Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pytest
from dynamic_preferences.registries import global_preferences_registry
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):
default = ['hello']
section = 'test'
name = 'string_list'
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):
s = common_preferences.StringListSerializer.to_db(input) == output
@pytest.mark.parametrize('input,output', [
('a,b,c', ['a', 'b', 'c'], ),
(None, []),
('', []),
])
def test_string_list_serializer_to_python(input, output):
s = common_preferences.StringListSerializer.to_python(input) == output
def test_string_list_pref_default(string_list_pref, preferences):
assert preferences['test__string_list'] == ['hello']
def test_string_list_pref_set(string_list_pref, preferences):
preferences['test__string_list'] = ['world', 'hello']
assert preferences['test__string_list'] == ['hello', 'world']