This repository has been archived by the owner on Dec 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
49 lines (43 loc) · 1.87 KB
/
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
import unittest
from process_contacts import (
get_first_value, combine_dictionary_values, combine_set_values)
from upload_changes import get_keys
class TestFunctions(unittest.TestCase):
def test_get_first_value(self):
self.assertEqual(get_first_value([], 'foo'), None)
self.assertEqual(
get_first_value([{'foo': 'bar'}, {'bar': 'foo'}], 'foo'), 'bar')
self.assertEqual(
get_first_value([{'bar': 'foo'}, {'foo': 'bar'}], 'foo'), 'bar')
self.assertEqual(
get_first_value([{'bar': 'foo'}, {'notfoo': 'bar'}], 'foo'), None)
def test_combine_dictionary_values(self):
self.assertEqual(combine_dictionary_values([], 'foo'), {})
self.assertEqual(
combine_dictionary_values(
[{'foo': {'bar': 'baz'}}, {'bar': 'foo'}], 'foo'),
{'bar': 'baz'})
self.assertEqual(
combine_dictionary_values(
[{'foo': {'bar': 'baz'}}, {'foo': {'baz': 'bar'}}], 'foo'),
{'bar': 'baz', 'baz': 'bar'})
self.assertEqual(
combine_dictionary_values(
[{'foo': {'bar': 'baz'}}, {'foo': {'bar': 'qux'}}], 'foo'),
{'bar': 'qux'})
def test_combine_set_values(self):
self.assertEqual(combine_set_values([], 'foo'), [])
self.assertEqual(
combine_set_values([{'foo': ['bar']}, {'bar': ['foo']}], 'foo'),
['bar'])
self.assertEqual(
combine_set_values([{'foo': ['bar', 'baz']}, {'foo': ['baz']}],
'foo'),
['bar', 'baz'])
def test_get_keys(self):
self.assertEqual(get_keys([]), [])
self.assertEqual(get_keys([{'key': '1'}, {'key': '2'}]), ['1', '2'])
self.assertEqual(
get_keys([{'key': '1'}, {'key': '2', 'foo': '3'}]), ['1', '2'])
if __name__ == '__main__':
unittest.main()