forked from cityofaustin/knackpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.py
69 lines (50 loc) · 1.8 KB
/
test_utils.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
60
61
62
63
64
65
66
67
68
69
import json
import knackpy
import pytz
import pytest
@pytest.fixture
def timezone():
return pytz.timezone("US/Central")
@pytest.fixture
def metadata():
with open("tests/_metadata.json", "r") as fin:
meta = json.loads(fin.read())
return meta["application"]
def test_valid_name():
assert knackpy.utils.valid_name("id") == "_id"
def test_correct_knack_timestamp(timezone):
"""
**Timestamp outside of daylight savings time**
Given `1577893645000`:
UTC: Wednesday, January 1, 2020 3:47:25 PM
US/Central: Wednesday, January 1, 2020 9:47:25 AM GMT-06:00
We are targeting: `1593636445000`
GMT: Wednesday, January 1, 2020 9:47:25 PM
US/Central: Wednesday, January 1, 2020 3:47:25 PM GMT-06:00
"""
timestamp_input = 1577893645000
timestamp_output = knackpy.utils.correct_knack_timestamp(timestamp_input, timezone)
assert timestamp_output == 1577915245000
def test_correct_knack_timestamp_during_dst(timezone):
"""
**Timestamp during daylight savings time**
Given `1593618445000`:
UTC: Wednesday, July 1, 2020 3:47:25 PM
US/Central: 10:47:25 AM GMT-05:00 DST
We are targeting: `1593636445000`
UTC: Wednesday, July 1, 2020 8:47:25 PM
US/Central 3:47:25 PM GMT-05:00 DST
"""
timestamp_input = 1593618445000
timestamp_output = knackpy.utils.correct_knack_timestamp(timestamp_input, timezone)
assert timestamp_output == 1593636445000
def test_generate_containers(metadata):
containers = knackpy.utils.generate_containers(metadata)
assert len(containers) > 0
def test_humanize_bytes():
kb = knackpy.utils.humanize_bytes(1000000)
assert kb == "976.56kb"
mb = knackpy.utils.humanize_bytes(10000000)
assert mb == "9.54mb"
gb = knackpy.utils.humanize_bytes(10000000000)
assert gb == "9.31gb"