-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
123 lines (108 loc) · 4.63 KB
/
tests.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import unittest
from jmatch import match
MOCK_JSON_LIST = '''
[
{
"track": {
"title": "Shame Shame Shame",
"duration": "3:10"
}
},
{
"track": {
"title": "Road Runner",
"duration": "2:50"
}
}
]
'''
MOCK_JSON_DICT = '''
{
"entry-1" : {
"name":"first entry",
"other" : "some other data"
},
"entry-2" : {
"name":"second entry",
"other": " "
},
"entry-3" : {
"name":"third entry",
"other": "something else"
}
}
'''
MOCK_JSON_DICT_OF_LIST = '''
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para":
"A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": [{"value": [{"GML":"ok"}], "type": "XML"}]
},
"GlossSee": "markup"
}
}
}
}
}
'''
MOCK_JSON_ONE_OBJECT = '''
{
"name":"Bond",
"city":"London",
"profession": "secret agent"
}
'''
class TestJsonMatch(unittest.TestCase):
def test001_one_object_response(self):
result = match(expected='{"name": "Bond"}',
actual=MOCK_JSON_ONE_OBJECT)
self.assertTrue(result)
def test002_one_object_response(self):
result = match(expected='{"name": "James", "profession": '
'"secret agent"}',
actual=MOCK_JSON_ONE_OBJECT)
self.assertFalse(result)
def test003_list_of_objects_response(self):
result = match(expected='{"track": {"title": "Shame Shame Shame",'
' "duration":"3:10"}}',
actual=MOCK_JSON_LIST)
self.assertTrue(result)
def test004_list_of_objects_response(self):
result = match(expected='{"track":{"title":"Eyesight To The Blind",'
' "duration":"2:50"}}',
actual=MOCK_JSON_LIST)
self.assertFalse(result)
def test005_dict_of_objects_response(self):
result = match(expected='{"entry-1" : {"name":"first entry"}}',
actual=MOCK_JSON_DICT)
self.assertTrue(result)
def test006_dict_of_objects_response(self):
result = match(expected='{"entry-4" : {"name":"fourth entry"}}',
actual=MOCK_JSON_DICT)
self.assertFalse(result)
def test007_dict_of_list_of_objects_response(self):
result = match(expected='{"glossary": {"GlossDiv": '
'{"GlossList": {"GlossEntry": {"GlossDef": '
'{"GlossSeeAlso": [{"value": [{"GML":"ok"}], "type": "XML"}]}}}}}}',
actual=MOCK_JSON_DICT_OF_LIST)
self.assertTrue(result)
def test008_dict_of_list_of_objects_response(self):
result = match(expected='{"glossary": {"GlossDiv": '
'{"GlossList": {"GlossEntry": {"GlossDef": '
'{"GlossSeeAlso": [{"value": [{"GML":"test"}], "type": ""}]}}}}}}',
actual=MOCK_JSON_DICT_OF_LIST)
self.assertFalse(result)
if __name__ == "__main__":
unittest.main()