-
Notifications
You must be signed in to change notification settings - Fork 0
/
serializer_test.py
49 lines (35 loc) · 1.19 KB
/
serializer_test.py
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
45
46
47
48
49
from serializer import serializers
class MockTag:
def __init__(self, name, attrs, string):
self.name = name
self.attrs = attrs
self.string = string
def __str__(self):
return f'<{self.name}>{self.string}</{self.name}>'
def test_serialize_dict():
test_list = [
MockTag('a', {'class': 'some classes'}, 'I am a link')
]
serializer = serializers.get('dict')
assert serializer(test_list) == [
{
'name': 'a',
'attributes': {
'class': 'some classes',
},
'content': 'I am a link',
'source': '<a>I am a link</a>',
}
]
def test_serialize_json():
test_list = [
MockTag('a', {'class': 'some classes'}, 'I am a link')
]
serializer = serializers.get('json')
assert serializer(test_list) == '[{"name": "a", "attributes": {"class": "some classes"}, "content": "I am a link", "source": "<a>I am a link</a>"}]'
def test_serialize_csv():
test_list = [
MockTag('a', {'class': 'some classes'}, 'I am a link')
]
serializer = serializers.get('csv')
assert '"name","attributes","content","source"' in serializer(test_list)