1
+ import datetime as dt
1
2
import os
2
3
import unittest
4
+
3
5
from urllib .error import URLError , HTTPError
4
6
5
7
from uid2_client import IdentityMapClient , IdentityMapInput , normalize_and_hash_email , normalize_and_hash_phone
@@ -130,24 +132,29 @@ def test_identity_map_hashed_phones(self):
130
132
131
133
self .assert_unmapped (response , "optout" , hashed_opted_out_phone )
132
134
133
- def test_identity_map_bad_url (self ):
135
+ def test_identity_map_client_bad_url (self ):
134
136
identity_map_input = IdentityMapInput .from_emails (
135
137
136
138
client = IdentityMapClient ("https://operator-bad-url.uidapi.com" , os .getenv ("UID2_API_KEY" ), os .getenv ("UID2_SECRET_KEY" ))
137
139
self .assertRaises (URLError , client .generate_identity_map , identity_map_input )
140
+ self .assertRaises (URLError , client .get_identity_buckets , dt .datetime .now ())
138
141
139
- def test_identity_map_bad_api_key (self ):
142
+ def test_identity_map_client_bad_api_key (self ):
140
143
identity_map_input = IdentityMapInput .from_emails (
141
144
142
145
client = IdentityMapClient (os .getenv ("UID2_BASE_URL" ), "bad-api-key" , os .getenv ("UID2_SECRET_KEY" ))
143
146
self .assertRaises (HTTPError , client .generate_identity_map ,identity_map_input )
147
+ self .assertRaises (HTTPError , client .get_identity_buckets , dt .datetime .now ())
144
148
145
- def test_identity_map_bad_secret (self ):
149
+ def test_identity_map_client_bad_secret (self ):
146
150
identity_map_input = IdentityMapInput .from_emails (
147
151
152
+
148
153
client = IdentityMapClient (os .getenv ("UID2_BASE_URL" ), os .getenv ("UID2_API_KEY" ), "wJ0hP19QU4hmpB64Y3fV2dAed8t/mupw3sjN5jNRFzg=" )
149
154
self .assertRaises (HTTPError , client .generate_identity_map ,
150
155
identity_map_input )
156
+ self .assertRaises (HTTPError , client .get_identity_buckets ,
157
+ dt .datetime .now ())
151
158
152
159
def assert_mapped (self , response , dii ):
153
160
mapped_identity = response .mapped_identities .get (dii )
@@ -165,6 +172,15 @@ def assert_unmapped(self, response, reason, dii):
165
172
mapped_identity = response .mapped_identities .get (dii )
166
173
self .assertIsNone (mapped_identity )
167
174
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 )
168
184
169
185
if __name__ == '__main__' :
170
186
unittest .main ()
0 commit comments