funkwhale/api/tests/common/test_preferences.py

46 wiersze
1.3 KiB
Python
Czysty Zwykły widok Historia

import pytest
from dynamic_preferences.registries import global_preferences_registry
2018-06-10 08:55:16 +00:00
from funkwhale_api.common import preferences as common_preferences
@pytest.fixture
def string_list_pref(preferences):
@global_preferences_registry.register
class P(common_preferences.StringListPreference):
2018-06-09 13:36:16 +00:00
default = ["hello"]
section = "test"
name = "string_list"
2018-06-09 13:36:16 +00:00
yield
del global_preferences_registry["test"]["string_list"]
@pytest.mark.parametrize(
"input,output",
[
(["a", "b", "c"], "a,b,c"),
(["a", "c", "b"], "a,b,c"),
(("a", "c", "b"), "a,b,c"),
([], None),
],
)
def test_string_list_serializer_to_db(input, output):
2018-06-09 15:41:59 +00:00
common_preferences.StringListSerializer.to_db(input) == output
2018-06-09 13:36:16 +00:00
@pytest.mark.parametrize(
"input,output", [("a,b,c", ["a", "b", "c"]), (None, []), ("", [])]
)
def test_string_list_serializer_to_python(input, output):
2018-06-09 15:41:59 +00:00
common_preferences.StringListSerializer.to_python(input) == output
def test_string_list_pref_default(string_list_pref, preferences):
2018-06-09 13:36:16 +00:00
assert preferences["test__string_list"] == ["hello"]
def test_string_list_pref_set(string_list_pref, preferences):
2018-06-09 13:36:16 +00:00
preferences["test__string_list"] = ["world", "hello"]
assert preferences["test__string_list"] == ["hello", "world"]