1+ import datetime as dt
12import os
23import unittest
4+
35from urllib .error import URLError , HTTPError
46
57from uid2_client import IdentityMapClient , IdentityMapInput , normalize_and_hash_email , normalize_and_hash_phone
@@ -130,24 +132,29 @@ def test_identity_map_hashed_phones(self):
130132
131133 self .assert_unmapped (response , "optout" , hashed_opted_out_phone )
132134
133- def test_identity_map_bad_url (self ):
135+ def test_identity_map_client_bad_url (self ):
134136 identity_map_input = IdentityMapInput .from_emails (
135137 ["hopefully-not-opted-out@example.com" , "somethingelse@example.com" , "optout@example.com" ])
136138 client = IdentityMapClient ("https://operator-bad-url.uidapi.com" , os .getenv ("UID2_API_KEY" ), os .getenv ("UID2_SECRET_KEY" ))
137139 self .assertRaises (URLError , client .generate_identity_map , identity_map_input )
140+ self .assertRaises (URLError , client .get_identity_buckets , dt .datetime .now ())
138141
139- def test_identity_map_bad_api_key (self ):
142+ def test_identity_map_client_bad_api_key (self ):
140143 identity_map_input = IdentityMapInput .from_emails (
141144 ["hopefully-not-opted-out@example.com" , "somethingelse@example.com" , "optout@example.com" ])
142145 client = IdentityMapClient (os .getenv ("UID2_BASE_URL" ), "bad-api-key" , os .getenv ("UID2_SECRET_KEY" ))
143146 self .assertRaises (HTTPError , client .generate_identity_map ,identity_map_input )
147+ self .assertRaises (HTTPError , client .get_identity_buckets , dt .datetime .now ())
144148
145- def test_identity_map_bad_secret (self ):
149+ def test_identity_map_client_bad_secret (self ):
146150 identity_map_input = IdentityMapInput .from_emails (
147151 ["hopefully-not-opted-out@example.com" , "somethingelse@example.com" , "optout@example.com" ])
152+
148153 client = IdentityMapClient (os .getenv ("UID2_BASE_URL" ), os .getenv ("UID2_API_KEY" ), "wJ0hP19QU4hmpB64Y3fV2dAed8t/mupw3sjN5jNRFzg=" )
149154 self .assertRaises (HTTPError , client .generate_identity_map ,
150155 identity_map_input )
156+ self .assertRaises (HTTPError , client .get_identity_buckets ,
157+ dt .datetime .now ())
151158
152159 def assert_mapped (self , response , dii ):
153160 mapped_identity = response .mapped_identities .get (dii )
@@ -165,6 +172,15 @@ def assert_unmapped(self, response, reason, dii):
165172 mapped_identity = response .mapped_identities .get (dii )
166173 self .assertIsNone (mapped_identity )
167174
175+ def test_identity_buckets (self ):
176+ response = self .identity_map_client .get_identity_buckets (dt .datetime .now () - dt .timedelta (days = 90 ))
177+ self .assertTrue (len (response .buckets ) > 0 )
178+ self .assertTrue (response .is_success )
179+
180+ def test_identity_buckets_empty_response (self ):
181+ response = self .identity_map_client .get_identity_buckets (dt .datetime .now () + dt .timedelta (days = 1 ))
182+ self .assertTrue (len (response .buckets ) == 0 )
183+ self .assertTrue (response .is_success )
168184
169185if __name__ == '__main__' :
170186 unittest .main ()
0 commit comments