Skip to content

Commit 01b844b

Browse files
committed
Move the unit tests to a new file
1 parent c5f235d commit 01b844b

File tree

4 files changed

+48
-31
lines changed

4 files changed

+48
-31
lines changed

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ requires-python = ">=3.6"
2222
dependencies = [
2323
"setuptools",
2424
"pycryptodome",
25-
"bitarray",
26-
"pytz"
25+
"bitarray"
2726
]
2827
keywords = ["uid2"]
2928
[project.license]

tests/test_identity_map_client.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
from urllib.error import URLError, HTTPError
66

7-
from uid2_client import IdentityMapClient, IdentityMapInput, normalize_and_hash_email, normalize_and_hash_phone, \
8-
get_datetime_utc_iso_format
7+
from uid2_client import IdentityMapClient, IdentityMapInput, normalize_and_hash_email, normalize_and_hash_phone
98

109

1110
class IdentityMapIntegrationTests(unittest.TestCase):
@@ -183,29 +182,5 @@ def test_identity_buckets_empty_response(self):
183182
self.assertTrue(len(response.buckets) == 0)
184183
self.assertTrue(response.is_success)
185184

186-
def test_identity_buckets_invalid_timestamp(self):
187-
test_cases = ["1234567890",
188-
1234567890,
189-
2024.7,
190-
"2024-7-1",
191-
"2024-07-01T12:00:00",
192-
[2024, 7, 1, 12, 0, 0],
193-
None]
194-
for timestamp in test_cases:
195-
self.assertRaises(AttributeError, self.identity_map_client.get_identity_buckets,
196-
timestamp)
197-
198-
def test_get_datetime_utc_iso_format_timestamp(self):
199-
expected_timestamp = "2024-07-02T14:30:15.123456"
200-
test_cases = ["2024-07-02T14:30:15.123456+00:00", "2024-07-02 09:30:15.123456-05:00",
201-
"2024-07-02T08:30:15.123456-06:00", "2024-07-02T10:30:15.123456-04:00",
202-
"2024-07-02T06:30:15.123456-08:00", "2024-07-02T23:30:15.123456+09:00",
203-
"2024-07-03T00:30:15.123456+10:00", "2024-07-02T20:00:15.123456+05:30"]
204-
for timestamp_str in test_cases:
205-
timestamp = dt.datetime.fromisoformat(timestamp_str)
206-
iso_format_timestamp = get_datetime_utc_iso_format(timestamp)
207-
self.assertEqual(expected_timestamp, iso_format_timestamp)
208-
209-
210185
if __name__ == '__main__':
211186
unittest.main()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import unittest
2+
import datetime as dt
3+
4+
from uid2_client import IdentityMapClient, get_datetime_utc_iso_format
5+
6+
7+
class IdentityMapUnitTests(unittest.TestCase):
8+
UID2_BASE_URL = None
9+
UID2_API_KEY = None
10+
UID2_SECRET_KEY = None
11+
12+
identity_map_client = None
13+
14+
@classmethod
15+
def setUpClass(cls):
16+
cls.UID2_BASE_URL = "UID2_BASE_URL"
17+
cls.UID2_API_KEY = "UID2_API_KEY"
18+
cls.UID2_SECRET_KEY = "wJ0hP19QU4hmpB64Y3fV2dAed8t/mupw3sjN5jNRFzg="
19+
20+
cls.identity_map_client = IdentityMapClient(cls.UID2_BASE_URL, cls.UID2_API_KEY, cls.UID2_SECRET_KEY)
21+
22+
def test_identity_buckets_invalid_timestamp(self):
23+
test_cases = ["1234567890",
24+
1234567890,
25+
2024.7,
26+
"2024-7-1",
27+
"2024-07-01T12:00:00",
28+
[2024, 7, 1, 12, 0, 0],
29+
None]
30+
for timestamp in test_cases:
31+
self.assertRaises(AttributeError, self.identity_map_client.get_identity_buckets,
32+
timestamp)
33+
34+
def test_get_datetime_utc_iso_format_timestamp(self):
35+
expected_timestamp = "2024-07-02T14:30:15.123456"
36+
test_cases = ["2024-07-02T14:30:15.123456+00:00", "2024-07-02 09:30:15.123456-05:00",
37+
"2024-07-02T08:30:15.123456-06:00", "2024-07-02T10:30:15.123456-04:00",
38+
"2024-07-02T06:30:15.123456-08:00", "2024-07-02T23:30:15.123456+09:00",
39+
"2024-07-03T00:30:15.123456+10:00", "2024-07-02T20:00:15.123456+05:30"]
40+
for timestamp_str in test_cases:
41+
timestamp = dt.datetime.fromisoformat(timestamp_str)
42+
iso_format_timestamp = get_datetime_utc_iso_format(timestamp)
43+
self.assertEqual(expected_timestamp, iso_format_timestamp)
44+

uid2_client/input_util.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import hashlib
22
import base64
3-
4-
import pytz
3+
from datetime import timezone
54

65

76
def is_phone_number_normalized(phone_number):
@@ -124,6 +123,6 @@ def normalize_and_hash_phone(phone):
124123

125124

126125
def get_datetime_utc_iso_format(timestamp):
127-
dt_utc = timestamp.astimezone(pytz.utc)
126+
dt_utc = timestamp.astimezone(timezone.utc)
128127
dt_utc_without_tz = dt_utc.replace(tzinfo=None)
129128
return dt_utc_without_tz.isoformat()

0 commit comments

Comments
 (0)