forked from snowplow/snowplow-python-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_payload.py
More file actions
68 lines (53 loc) · 2.37 KB
/
test_payload.py
File metadata and controls
68 lines (53 loc) · 2.37 KB
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
"""
test_payload.py
Copyright (c) 2013-2014 Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Apache License Version 2.0,
and you may not use this file except in compliance with the Apache License
Version 2.0. You may obtain a copy of the Apache License Version 2.0 at
http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing,
software distributed under the Apache License Version 2.0 is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the Apache License Version 2.0 for the specific
language governing permissions and limitations there under.
Authors: Anuj More, Alex Dean, Fred Blundun
Copyright: Copyright (c) 2013-2014 Snowplow Analytics Ltd
License: Apache License Version 2.0
"""
import unittest
from snowplow_tracker import payload
def is_subset(dict1, dict2):
"""
* is_subset(smaller_dict, larger_dict)
Checks if dict1 has name, value pairs that also exist in dict2.
Typically this function is used in the case where dict1 (expected
output) contains certain name, value pairs, and those have to be
compared with name, value pairs in another dict (the actual output)
"""
if len(dict1) > len(dict2):
return False
if set(dict1.items()).issubset(dict2.items()):
return True
else:
return False
class TestPayload(unittest.TestCase):
def setUp(self):
pass
def test_object_generation(self):
p = payload.Payload()
self.assertTrue(is_subset({}, p.nv_pairs))
def test_object_generation_2(self):
p = payload.Payload({"test1": "result1", "test2": "result2", })
output = {"test1": "result1", "test2": "result2"}
self.assertTrue(is_subset(output, p.nv_pairs))
def test_add(self):
p = payload.Payload()
p.add("name1", "value1")
p.add("name2", "value2")
output = {"name1": "value1", "name2": "value2", }
self.assertTrue(is_subset(output, p.nv_pairs))
def test_add_dict(self):
p = payload.Payload({"n1": "v1", "n2": "v2", })
p.add_dict({"name4": 4, "name3": 3}) # Order doesn't matter
output = {"n1": "v1", "n2": "v2", "name3": 3, "name4": 4}
self.assertTrue(is_subset(output, p.nv_pairs))