forked from cgardens/target-csv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
target_csv_test.py
37 lines (28 loc) · 947 Bytes
/
target_csv_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
import target_csv
import unittest
class TestTargetCsv(unittest.TestCase):
def setUp(self):
pass
def test_get_headers(self):
schema = {"properties": {
'a': {'type': 'string'},
'b': {'type': 'array', 'items': {'type': 'string'}},
'c': {'type': 'object', 'properties': {'d': {'type': 'string'}}}
}}
assert target_csv.get_headers(schema) == ['a', 'b', 'c__d']
def test_get_headers_matches_flatten(self):
schema = {'properties': {
'a': {'type': 'string'},
'b': {'type': 'array', 'items': {'type': 'string'}},
'c': {'type': 'object', 'properties': {'d': {'type': 'string'}}}
}}
record = {
'a': 'alpha',
'b': ['beta'],
'c': {'d': 'delta'}
}
keys_from_schema = target_csv.get_headers(schema)
keys_from_records = list(target_csv.flatten(record).keys())
assert keys_from_schema == keys_from_records
if __name__ == '__main__':
unittest.main()