1+ import datetime
12import os
23import unittest
34
@@ -131,24 +132,28 @@ def test_identity_map_hashed_phones(self):
131132
132133 self .assert_unmapped (response , "optout" , hashed_opted_out_phone )
133134
134- def test_identity_map_bad_url (self ):
135+ def test_identity_map_client_bad_url (self ):
135136 identity_map_input = IdentityMapInput .from_emails (
136137 ["hopefully-not-opted-out@example.com" , "somethingelse@example.com" , "optout@example.com" ])
137138 client = IdentityMapClient ("https://operator-bad-url.uidapi.com" , os .getenv ("UID2_API_KEY" ), os .getenv ("UID2_SECRET_KEY" ))
138139 self .assertRaises (requests .exceptions .ConnectionError , client .generate_identity_map , identity_map_input )
140+ self .assertRaises (requests .exceptions .ConnectionError , client .get_identity_buckets , datetime .datetime .now ())
139141
140- def test_identity_map_bad_api_key (self ):
142+ def test_identity_map_client_bad_api_key (self ):
141143 identity_map_input = IdentityMapInput .from_emails (
142144 ["hopefully-not-opted-out@example.com" , "somethingelse@example.com" , "optout@example.com" ])
143145 client = IdentityMapClient (os .getenv ("UID2_BASE_URL" ), "bad-api-key" , os .getenv ("UID2_SECRET_KEY" ))
144146 self .assertRaises (requests .exceptions .HTTPError , client .generate_identity_map ,identity_map_input )
147+ self .assertRaises (requests .exceptions .HTTPError , client .get_identity_buckets , datetime .datetime .now ())
145148
146- def test_identity_map_bad_secret (self ):
149+ def test_identity_map_client_bad_secret (self ):
147150 identity_map_input = IdentityMapInput .from_emails (
148151 ["hopefully-not-opted-out@example.com" , "somethingelse@example.com" , "optout@example.com" ])
149152 client = IdentityMapClient (os .getenv ("UID2_BASE_URL" ), os .getenv ("UID2_API_KEY" ), "wJ0hP19QU4hmpB64Y3fV2dAed8t/mupw3sjN5jNRFzg=" )
150153 self .assertRaises (requests .exceptions .HTTPError , client .generate_identity_map ,
151154 identity_map_input )
155+ self .assertRaises (requests .exceptions .HTTPError , client .get_identity_buckets ,
156+ datetime .datetime .now ())
152157
153158 def assert_mapped (self , response , dii ):
154159 mapped_identity = response .mapped_identities .get (dii )
@@ -166,6 +171,20 @@ def assert_unmapped(self, response, reason, dii):
166171 mapped_identity = response .mapped_identities .get (dii )
167172 self .assertIsNone (mapped_identity )
168173
174+ def test_identity_buckets (self ):
175+ response = self .identity_map_client .get_identity_buckets (datetime .datetime .now () - datetime .timedelta (days = 2 ))
176+ self .assertTrue (len (response .buckets ) > 0 )
177+ self .assertTrue (response .is_success )
178+
179+ def test_identity_buckets_empty_response (self ):
180+ response = self .identity_map_client .get_identity_buckets (datetime .datetime .now () + datetime .timedelta (days = 1 ))
181+ self .assertTrue (len (response .buckets ) == 0 )
182+ self .assertTrue (response .is_success )
183+
184+ def test_identity_buckets_invalid_timestamp (self ):
185+ self .assertRaises (TypeError , self .identity_map_client .get_identity_buckets ,
186+ "1234567890" )
187+
169188
170189if __name__ == '__main__' :
171190 unittest .main ()
0 commit comments