@@ -162,11 +162,14 @@ def test_bulk_operations_workflow(self):
162162 """Test complete bulk operations workflow: create users, unlock bulk, and fetch all users."""
163163 # Step 1: Create 10 users using bulk creation
164164 users_data = []
165+ created_emails = []
165166 for i in range (10 ):
167+ email = f"bulktest{ random .randint (1000 , 999999 )} @example.com"
168+ created_emails .append (email )
166169 users_data .append (
167170 {
168171 "profile" : {
169- "email" : f"bulktest { random . randint ( 1000 , 999999 ) } @example.com" ,
172+ "email" : email ,
170173 "name" : f"Bulk Test User { i + 1 } " ,
171174 "phone" : str (random .randint (1000000 , 9999999 )),
172175 }
@@ -183,8 +186,12 @@ def test_bulk_operations_workflow(self):
183186 self .assertIn ("created" , create_result )
184187 self .assertEqual (len (create_result ["created" ]), 10 )
185188
186- # Store created user tokens for verification
189+ # Store created user tokens and emails for verification
187190 created_tokens = [user ["token" ] for user in create_result ["created" ]]
191+ created_user_identities = [
192+ {"mode" : "email" , "identity" : user ["profile" ]["email" ]}
193+ for user in create_result ["created" ]
194+ ]
188195
189196 # Step 2: Initiate bulk list unlock operation
190197 unlock_result = self .api .bulk_list_unlock ()
@@ -196,9 +203,28 @@ def test_bulk_operations_workflow(self):
196203
197204 unlock_uuid = unlock_result ["unlockuuid" ]
198205
199- # Step 3: Fetch all users using bulk list operation
200- # First, get the total count by fetching with a large limit
201- bulk_users_result = self .api .bulk_list_users (unlock_uuid , offset = 0 , limit = 100 )
206+ # Step 3: Test bulk_list_users() with subset of created users
207+ # Select first 5 users for subset testing
208+ subset_users = created_user_identities [:5 ]
209+ subset_result = self .api .bulk_list_users (unlock_uuid , subset_users )
210+
211+ # Verify subset fetch was successful
212+ self .assertIsInstance (subset_result , dict )
213+ self .assertEqual (subset_result .get ("status" ), "ok" )
214+ self .assertIn ("rows" , subset_result )
215+
216+ # Verify we got the expected number of users in subset
217+ subset_users_returned = subset_result ["rows" ]
218+ self .assertLessEqual (len (subset_users_returned ), 5 , "Subset should not exceed requested users" )
219+
220+ # Verify subset users are from our created set
221+ subset_emails = [user .get ("profile" , {}).get ("email" ) for user in subset_users_returned ]
222+ for email in subset_emails :
223+ if email : # Only check if email exists
224+ self .assertIn (email , created_emails , f"Email { email } should be from our created users" )
225+
226+ # Step 4: Fetch all users using bulk list operation
227+ bulk_users_result = self .api .bulk_list_all_users (unlock_uuid , offset = 0 , limit = 100 )
202228
203229 # Verify bulk fetch was successful
204230 self .assertIsInstance (bulk_users_result , dict )
@@ -225,13 +251,13 @@ def test_bulk_operations_workflow(self):
225251 f"Expected to find 10 created users in bulk results, but found { found_created_users } " ,
226252 )
227253
228- # Step 4 : Test pagination by fetching users in smaller batches
254+ # Step 5 : Test pagination by fetching users in smaller batches
229255 paginated_users = []
230256 offset = 0
231257 limit = 5
232258
233259 while True :
234- page_result = self .api .bulk_list_users (
260+ page_result = self .api .bulk_list_all_users (
235261 unlock_uuid , offset = offset , limit = limit
236262 )
237263 self .assertEqual (page_result .get ("status" ), "ok" )
@@ -264,6 +290,91 @@ def test_bulk_operations_workflow(self):
264290
265291 return created_tokens
266292
293+ def test_bulk_list_users_subset (self ):
294+ """Test bulk_list_users() method to fetch a specific subset of user records."""
295+ # Step 1: Create 5 users for testing
296+ users_data = []
297+ test_emails = []
298+ for i in range (5 ):
299+ email = f"subsettest{ random .randint (1000 , 999999 )} @example.com"
300+ test_emails .append (email )
301+ users_data .append (
302+ {
303+ "profile" : {
304+ "email" : email ,
305+ "name" : f"Subset Test User { i + 1 } " ,
306+ "phone" : str (random .randint (1000000 , 9999999 )),
307+ }
308+ }
309+ )
310+
311+ # Create users in bulk
312+ create_result = self .api .create_users_bulk (users_data )
313+ self .assertEqual (create_result .get ("status" ), "ok" )
314+ self .assertEqual (len (create_result ["created" ]), 5 )
315+
316+ # Store created user data
317+ created_tokens = [user ["token" ] for user in create_result ["created" ]]
318+ created_user_identities = [
319+ {"mode" : "email" , "identity" : user ["profile" ]["email" ]}
320+ for user in create_result ["created" ]
321+ ]
322+
323+ # Step 2: Initiate bulk list unlock operation
324+ unlock_result = self .api .bulk_list_unlock ()
325+ self .assertEqual (unlock_result .get ("status" ), "ok" )
326+ unlock_uuid = unlock_result ["unlockuuid" ]
327+
328+ # Step 3: Test bulk_list_users with all created users
329+ all_users_result = self .api .bulk_list_users (unlock_uuid , created_user_identities )
330+
331+ # Verify the result
332+ self .assertEqual (all_users_result .get ("status" ), "ok" )
333+ self .assertIn ("rows" , all_users_result )
334+
335+ returned_users = all_users_result ["rows" ]
336+ self .assertLessEqual (len (returned_users ), 5 , "Should not return more users than requested" )
337+
338+ # Verify all returned users are from our created set
339+ returned_emails = [user .get ("profile" , {}).get ("email" ) for user in returned_users ]
340+ for email in returned_emails :
341+ if email :
342+ self .assertIn (email , test_emails , f"Email { email } should be from our test users" )
343+
344+ # Step 4: Test bulk_list_users with subset (first 3 users)
345+ subset_identities = created_user_identities [:3 ]
346+ subset_result = self .api .bulk_list_users (unlock_uuid , subset_identities )
347+
348+ # Verify subset result
349+ self .assertEqual (subset_result .get ("status" ), "ok" )
350+ self .assertIn ("rows" , subset_result )
351+
352+ subset_users = subset_result ["rows" ]
353+ self .assertLessEqual (len (subset_users ), 3 , "Subset should not exceed 3 users" )
354+
355+ # Verify subset users are from our created set
356+ subset_emails = [user .get ("profile" , {}).get ("email" ) for user in subset_users ]
357+ for email in subset_emails :
358+ if email :
359+ self .assertIn (email , test_emails , f"Email { email } should be from our test users" )
360+
361+ # Step 5: Test with empty users list
362+ empty_result = self .api .bulk_list_users (unlock_uuid , [])
363+ self .assertEqual (empty_result .get ("status" ), "ok" )
364+ self .assertIn ("rows" , empty_result )
365+ self .assertEqual (len (empty_result ["rows" ]), 0 , "Empty users list should return empty result" )
366+
367+ # Clean up: Delete the created users
368+ for token in created_tokens :
369+ try :
370+ delete_result = self .api .delete_user ("token" , token )
371+ if delete_result .get ("status" ) != "ok" :
372+ print (f"Warning: Failed to delete user with token { token } " )
373+ except Exception as e :
374+ print (f"Warning: Exception during cleanup for token { token } : { str (e )} " )
375+
376+ return created_tokens
377+
267378
268379if __name__ == "__main__" :
269380 unittest .main ()
0 commit comments