1- import datetime
1+ import datetime as dt
22import os
33import unittest
4- from datetime import datetime
54
6- import requests
5+ from urllib . error import URLError , HTTPError
76
87from uid2_client import IdentityMapClient , IdentityMapInput , normalize_and_hash_email , normalize_and_hash_phone , \
98 get_datetime_utc_iso_format
@@ -137,27 +136,26 @@ def test_identity_map_hashed_phones(self):
137136 def test_identity_map_client_bad_url (self ):
138137 identity_map_input = IdentityMapInput .from_emails (
139138 ["hopefully-not-opted-out@example.com" , "somethingelse@example.com" , "optout@example.com" ])
140- client = IdentityMapClient ("https://operator-bad-url.uidapi.com" , os .getenv ("UID2_API_KEY" ),
141- os .getenv ("UID2_SECRET_KEY" ))
142- self .assertRaises (requests .exceptions .ConnectionError , client .generate_identity_map , identity_map_input )
143- self .assertRaises (requests .exceptions .ConnectionError , client .get_identity_buckets , datetime .datetime .now ())
139+ client = IdentityMapClient ("https://operator-bad-url.uidapi.com" , os .getenv ("UID2_API_KEY" ), os .getenv ("UID2_SECRET_KEY" ))
140+ self .assertRaises (URLError , client .generate_identity_map , identity_map_input )
141+ self .assertRaises (URLError , client .get_identity_buckets , dt .datetime .now ())
144142
145143 def test_identity_map_client_bad_api_key (self ):
146144 identity_map_input = IdentityMapInput .from_emails (
147145 ["hopefully-not-opted-out@example.com" , "somethingelse@example.com" , "optout@example.com" ])
148146 client = IdentityMapClient (os .getenv ("UID2_BASE_URL" ), "bad-api-key" , os .getenv ("UID2_SECRET_KEY" ))
149- self .assertRaises (requests . exceptions . HTTPError , client .generate_identity_map , identity_map_input )
150- self .assertRaises (requests . exceptions . HTTPError , client .get_identity_buckets , datetime .datetime .now ())
147+ self .assertRaises (HTTPError , client .generate_identity_map ,identity_map_input )
148+ self .assertRaises (HTTPError , client .get_identity_buckets , dt .datetime .now ())
151149
152150 def test_identity_map_client_bad_secret (self ):
153151 identity_map_input = IdentityMapInput .from_emails (
154152 ["hopefully-not-opted-out@example.com" , "somethingelse@example.com" , "optout@example.com" ])
155- client = IdentityMapClient ( os . getenv ( "UID2_BASE_URL" ), os . getenv ( "UID2_API_KEY" ),
156- "wJ0hP19QU4hmpB64Y3fV2dAed8t/mupw3sjN5jNRFzg=" )
157- self .assertRaises (requests . exceptions . HTTPError , client .generate_identity_map ,
153+
154+ client = IdentityMapClient ( os . getenv ( "UID2_BASE_URL" ), os . getenv ( "UID2_API_KEY" ), "wJ0hP19QU4hmpB64Y3fV2dAed8t/mupw3sjN5jNRFzg=" )
155+ self .assertRaises (HTTPError , client .generate_identity_map ,
158156 identity_map_input )
159- self .assertRaises (requests . exceptions . HTTPError , client .get_identity_buckets ,
160- datetime .datetime .now ())
157+ self .assertRaises (HTTPError , client .get_identity_buckets ,
158+ dt .datetime .now ())
161159
162160 def assert_mapped (self , response , dii ):
163161 mapped_identity = response .mapped_identities .get (dii )
@@ -176,12 +174,12 @@ def assert_unmapped(self, response, reason, dii):
176174 self .assertIsNone (mapped_identity )
177175
178176 def test_identity_buckets (self ):
179- response = self .identity_map_client .get_identity_buckets (datetime .datetime .now () - datetime .timedelta (days = 90 ))
177+ response = self .identity_map_client .get_identity_buckets (dt .datetime .now () - dt .timedelta (days = 90 ))
180178 self .assertTrue (len (response .buckets ) > 0 )
181179 self .assertTrue (response .is_success )
182180
183181 def test_identity_buckets_empty_response (self ):
184- response = self .identity_map_client .get_identity_buckets (datetime .datetime .now () + datetime .timedelta (days = 1 ))
182+ response = self .identity_map_client .get_identity_buckets (dt .datetime .now () + dt .timedelta (days = 1 ))
185183 self .assertTrue (len (response .buckets ) == 0 )
186184 self .assertTrue (response .is_success )
187185
@@ -204,7 +202,7 @@ def test_get_datetime_utc_iso_format_timestamp(self):
204202 "2024-07-02T06:30:15.123456-08:00" , "2024-07-02T23:30:15.123456+09:00" ,
205203 "2024-07-03T00:30:15.123456+10:00" , "2024-07-02T20:00:15.123456+05:30" ]
206204 for timestamp_str in test_cases :
207- timestamp = datetime .fromisoformat (timestamp_str )
205+ timestamp = dt . datetime .fromisoformat (timestamp_str )
208206 iso_format_timestamp = get_datetime_utc_iso_format (timestamp )
209207 self .assertEqual (expected_timestamp , iso_format_timestamp )
210208
0 commit comments