forked from csirtgadgets/csirtg-indicator-py-v1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_timestamps.py
59 lines (37 loc) · 1.38 KB
/
test_timestamps.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
50
51
52
53
54
55
56
57
58
59
from csirtg_indicator import Indicator
import arrow
import json
def test_indicator_timestamps():
f = arrow.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ")
l = arrow.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ")
r = arrow.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ")
i = Indicator('192.168.1.1', firsttime=f, lasttime=l, reporttime=r)
assert i.firsttime == arrow.get(f).datetime
assert i.lasttime == arrow.get(l).datetime
assert i.reporttime == arrow.get(r).datetime
s = str(i)
i = json.loads(s)
assert i['firsttime'] == f
assert i['lasttime'] == l
assert i['reporttime'] == r
def test_indicator_timezones():
t = '2017-03-06T11:41:48-06:00'
a = arrow.get('2017-03-06T17:41:48Z').datetime
i = Indicator('example.com', firsttime=t, lasttime=t, reporttime=t)
assert i.firsttime == a
assert i.lasttime == a
assert i.reporttime == a
def test_lasttime_only():
l = arrow.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ")
i = Indicator('192.168.1.1', lasttime=l)
assert i.lasttime == arrow.get(l).datetime
s = str(i)
i = json.loads(s)
assert i.get('firsttime') is None
def test_firsttime_only():
l = arrow.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ")
i = Indicator('192.168.1.1', firsttime=l)
assert i.firsttime == arrow.get(l).datetime
s = str(i)
i = json.loads(s)
assert i.get('lasttime') is None