forked from snowplow/snowplow-python-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tracker.py
More file actions
55 lines (41 loc) · 1.99 KB
/
Copy pathtest_tracker.py
File metadata and controls
55 lines (41 loc) · 1.99 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
"""
test_tracker.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 freezegun import freeze_time
from snowplow_tracker.tracker import Tracker
from snowplow_tracker.emitters import Emitter
class TestTracker(unittest.TestCase):
def setUp(self):
pass
def test_initialisation(self):
t = Tracker(Emitter("d3rkrsqld9gmqf.cloudfront.net"), namespace="cloudfront", encode_base64= False, app_id="AF003")
self.assertEquals(t.standard_nv_pairs["tna"], "cloudfront")
self.assertEquals(t.standard_nv_pairs["aid"], "AF003")
self.assertEquals(t.encode_base64, False)
def test_get_transaction_id(self):
tid = Tracker.get_transaction_id()
self.assertTrue(tid >= 100000 and tid <= 999999)
@freeze_time("1970-01-01 00:00:01")
def test_get_timestamp(self):
dtm = Tracker.get_timestamp()
self.assertEquals(dtm, 1000) # 1970-01-01 00:00:01 in ms
def test_set_timestamp_1(self):
dtm = Tracker.get_timestamp(1399021242030)
self.assertEquals(dtm, 1399021242030)
def test_set_timestamp_2(self):
dtm = Tracker.get_timestamp(1399021242240.0303)
self.assertEquals(dtm, 1399021242240)