-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathtest_subject.py
More file actions
89 lines (74 loc) · 2.87 KB
/
test_subject.py
File metadata and controls
89 lines (74 loc) · 2.87 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""
test_subject.py
Copyright (c) 2013-2021 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, Paul Boocock
Copyright: Copyright (c) 2013-2021 Snowplow Analytics Ltd
License: Apache License Version 2.0
"""
import unittest
import pytest
from snowplow_tracker import subject as _subject
class TestSubject(unittest.TestCase):
def setUp(self) -> None:
pass
def test_subject_0(self) -> None:
s = _subject.Subject()
self.assertDictEqual(s.standard_nv_pairs, {"p": _subject.DEFAULT_PLATFORM})
s.set_platform("srv")
s.set_user_id("1234")
s.set_screen_resolution(1920, 1080)
s.set_viewport(1080, 1080)
s.set_color_depth(1080)
s.set_timezone("PST")
s.set_lang("EN")
s.set_domain_user_id("domain-user-id")
s.set_ip_address("127.0.0.1")
s.set_useragent("useragent-string")
s.set_network_user_id("network-user-id")
exp = {
"p": "srv",
"uid": "1234",
"res": "1920x1080",
"vp": "1080x1080",
"cd": 1080,
"tz": "PST",
"lang": "EN",
"ip": "127.0.0.1",
"ua": "useragent-string",
"duid": "domain-user-id",
"tnuid": "network-user-id"
}
self.assertDictEqual(s.standard_nv_pairs, exp)
def test_subject_1(self) -> None:
s = _subject.Subject().set_platform("srv").set_user_id("1234").set_lang("EN")
exp = {
"p": "srv",
"uid": "1234",
"lang": "EN"
}
self.assertDictEqual(s.standard_nv_pairs, exp)
with pytest.raises(KeyError):
s.standard_nv_pairs["res"]
with pytest.raises(KeyError):
s.standard_nv_pairs["vp"]
with pytest.raises(KeyError):
s.standard_nv_pairs["cd"]
with pytest.raises(KeyError):
s.standard_nv_pairs["tz"]
with pytest.raises(KeyError):
s.standard_nv_pairs["ip"]
with pytest.raises(KeyError):
s.standard_nv_pairs["ua"]
with pytest.raises(KeyError):
s.standard_nv_pairs["duid"]
with pytest.raises(KeyError):
s.standard_nv_pairs["tnuid"]