@@ -111,10 +111,18 @@ class TestUserRepository(unittest.IsolatedAsyncioTestCase):
111
111
"""
112
112
113
113
def __init__ (self , * args , ** kwargs ):
114
+ """
115
+ Initializes the TestUserRepository class.
116
+ :param args: arguments
117
+ :param kwargs: keyword arguments
118
+ """
114
119
_log .info ("Initializing TestUserRepository" )
115
120
super (TestUserRepository , self ).__init__ (* args , ** kwargs )
116
121
117
122
async def asyncSetUp (self ):
123
+ """
124
+ Sets up the resources required for the tests.
125
+ """
118
126
_log .info ("Setting up each resources." )
119
127
self .container = MongoDbContainer (image = "mongo:latest" )
120
128
self .container .start ()
@@ -124,6 +132,9 @@ async def asyncSetUp(self):
124
132
await init_beanie (document_models = entities , database = self .db )
125
133
126
134
async def asyncTearDown (self ):
135
+ """
136
+ Tears down the resources after the tests.
137
+ """
127
138
_log .info ("Tearing down each resources." )
128
139
await self .db .get_collection (_collection_name ).delete_many ({})
129
140
self .client .close ()
@@ -132,6 +143,9 @@ async def asyncTearDown(self):
132
143
# region create entity tests
133
144
@pytest .mark .asyncio
134
145
async def test_given_min_entity_when_insert_then_successfully_created (self ):
146
+ """
147
+ Test case to create a user entity with minimal data and verify the creation process.
148
+ """
135
149
_log .info ("test_given_min_entity_when_insert_then_successfully_created" )
136
150
# Given
137
151
entity = _get_min_entity ()
@@ -157,6 +171,9 @@ async def test_given_min_entity_when_insert_then_successfully_created(self):
157
171
158
172
@pytest .mark .asyncio
159
173
async def test_given_full_entity_when_insert_then_successfully_created (self ):
174
+ """
175
+ Test case to create a user entity with full data and verify the creation process.
176
+ """
160
177
_log .info ("test_given_full_entity_when_insert_then_successfully_created" )
161
178
162
179
# Given
@@ -183,6 +200,9 @@ async def test_given_full_entity_when_insert_then_successfully_created(self):
183
200
184
201
@pytest .mark .asyncio
185
202
async def test_given_invalid_entity_when_insert_then_fail (self ):
203
+ """
204
+ Test case to handle invalid user entity creation attempts.
205
+ """
186
206
_log .info ("test_given_invalid_entity_when_insert_then_fail" )
187
207
188
208
# Given
@@ -199,6 +219,9 @@ async def test_given_invalid_entity_when_insert_then_fail(self):
199
219
# region update entity tests
200
220
@pytest .mark .asyncio
201
221
async def test_given_entity_when_update_then_successfully_updated (self ):
222
+ """
223
+ Test case to update a user entity and verify the changes are correctly applied.
224
+ """
202
225
_log .info ("test_given_entity_when_update_then_successfully_updated" )
203
226
204
227
# Given
@@ -236,6 +259,9 @@ async def test_given_entity_when_update_then_successfully_updated(self):
236
259
237
260
@pytest .mark .asyncio
238
261
async def test_given_invalid_userid_when_update_then_fail (self ):
262
+ """
263
+ Test case to handle invalid user ID during update attempts.
264
+ """
239
265
_log .info ("test_given_invalid_entity_when_update_then_fail" )
240
266
241
267
# inti entity
@@ -251,6 +277,9 @@ async def test_given_invalid_userid_when_update_then_fail(self):
251
277
252
278
@pytest .mark .asyncio
253
279
async def test_given_invalid_username_when_update_then_fail (self ):
280
+ """
281
+ Test case to handle invalid username during update attempts.
282
+ """
254
283
_log .info ("test_given_invalid_entity_when_update_then_fail" )
255
284
256
285
# inti entity
@@ -266,6 +295,9 @@ async def test_given_invalid_username_when_update_then_fail(self):
266
295
267
296
@pytest .mark .asyncio
268
297
async def test_given_invalid_email_when_update_then_fail (self ):
298
+ """
299
+ Test case to handle invalid email during update attempts.
300
+ """
269
301
_log .info ("test_given_invalid_entity_when_update_then_fail" )
270
302
271
303
# inti entity
@@ -291,6 +323,9 @@ async def test_given_invalid_email_when_update_then_fail(self):
291
323
292
324
@pytest .mark .asyncio
293
325
async def test_given_deleted_entity_when_retrieve_then_should_fail (self ):
326
+ """
327
+ Test case to handle deleted user entity retrieval attempts.
328
+ """
294
329
_log .info ("test_given_entity_when_delete_then_successfully_deleted" )
295
330
296
331
# Given
@@ -309,6 +344,9 @@ async def test_given_deleted_entity_when_retrieve_then_should_fail(self):
309
344
310
345
@pytest .mark .asyncio
311
346
async def test_given_random_id_when_delete_then_should_fail (self ):
347
+ """
348
+ Test case to handle deletion attempts for non-existent user entities.
349
+ """
312
350
_log .info ("test_given_entity_when_delete_then_successfully_deleted" )
313
351
314
352
repository = _get_repo ()
@@ -327,6 +365,9 @@ async def test_given_random_id_when_delete_then_should_fail(self):
327
365
# success case with default values
328
366
@pytest .mark .asyncio
329
367
async def test_given_entity_when_find_then_success (self ):
368
+ """
369
+ Test case to find user entities and verify the results.
370
+ """
330
371
_log .info ("test_given_entity_when_find_then_success" )
331
372
332
373
# Given
@@ -346,6 +387,9 @@ async def test_given_entity_when_find_then_success(self):
346
387
# success case with mongodb query
347
388
@pytest .mark .asyncio
348
389
async def test_given_native_mogo_query_when_find_with_query_then_success (self ):
390
+ """
391
+ Test case to find user entities with a MongoDB query and verify the results.
392
+ """
349
393
_log .info ("test_given_entity_when_find_with_query_then_success" )
350
394
351
395
# Given
@@ -365,6 +409,9 @@ async def test_given_native_mogo_query_when_find_with_query_then_success(self):
365
409
# success case with query, page, size, sort
366
410
@pytest .mark .asyncio
367
411
async def test_given_native_mogo_query_when_find_with_query_page_size_sort_then_success (self ):
412
+ """
413
+ Test case to find user entities with a MongoDB query, pagination, and sorting, and verify the results.
414
+ """
368
415
_log .info ("test_given_entity_when_find_with_query_page_size_sort_then_success" )
369
416
370
417
# Given
@@ -384,6 +431,9 @@ async def test_given_native_mogo_query_when_find_with_query_page_size_sort_then_
384
431
# success case with dict convert to query, page, size, sort
385
432
@pytest .mark .asyncio
386
433
async def test_given_dict_when_find_with_query_then_success (self ):
434
+ """
435
+ Test case to find user entities with a dictionary query, pagination, and sorting, and verify the results.
436
+ """
387
437
_log .info ("test_given_entity_when_find_with_invalid_query_then_fail" )
388
438
389
439
# Given
@@ -405,6 +455,9 @@ async def test_given_dict_when_find_with_query_then_success(self):
405
455
# fail case with invalid query
406
456
@pytest .mark .asyncio
407
457
async def test_given_invalid_query_when_find_with_invalid_query_then_fail (self ):
458
+ """
459
+ Test case to handle invalid query attempts during user entity retrieval.
460
+ """
408
461
_log .info ("test_given_entity_when_find_with_invalid_query_then_fail" )
409
462
410
463
# Given
@@ -422,6 +475,9 @@ async def test_given_invalid_query_when_find_with_invalid_query_then_fail(self):
422
475
# success case with count
423
476
@pytest .mark .asyncio
424
477
async def test_given_entity_when_count_then_success (self ):
478
+ """
479
+ Test case to count user entities and verify the results.
480
+ """
425
481
_log .info ("test_given_entity_when_count_then_success" )
426
482
427
483
# Given
@@ -440,6 +496,9 @@ async def test_given_entity_when_count_then_success(self):
440
496
# fail case with count
441
497
@pytest .mark .asyncio
442
498
async def test_given_invalid_query_when_count_with_invalid_query_then_fail (self ):
499
+ """
500
+ Test case to handle invalid query attempts during user entity count.
501
+ """
443
502
_log .info ("test_given_entity_when_count_with_invalid_query_then_fail" )
444
503
445
504
# Given
@@ -457,6 +516,9 @@ async def test_given_invalid_query_when_count_with_invalid_query_then_fail(self)
457
516
# success case with valid user_id retrieve
458
517
@pytest .mark .asyncio
459
518
async def test_given_entity_when_retrieve_then_success (self ):
519
+ """
520
+ Test case to retrieve a user entity by user ID and verify the results.
521
+ """
460
522
_log .info ("test_given_entity_when_retrieve_then_success" )
461
523
462
524
# Given
@@ -479,6 +541,9 @@ async def test_given_entity_when_retrieve_then_success(self):
479
541
# fail case with invalid user_id retrieve
480
542
@pytest .mark .asyncio
481
543
async def test_given_invalid_user_id_when_retrieve_then_fail (self ):
544
+ """
545
+ Test case to handle invalid user ID during user entity retrieval.
546
+ """
482
547
_log .info ("test_given_invalid_user_id_when_retrieve_then_fail" )
483
548
484
549
# Given
@@ -494,6 +559,9 @@ async def test_given_invalid_user_id_when_retrieve_then_fail(self):
494
559
# success case with valid email retrieve_by_email
495
560
@pytest .mark .asyncio
496
561
async def test_given_entity_when_retrieve_by_email_then_success (self ):
562
+ """
563
+ Test case to retrieve a user entity by email and verify the results.
564
+ """
497
565
_log .info ("test_given_entity_when_retrieve_by_email_then_success" )
498
566
499
567
# Given
@@ -516,6 +584,9 @@ async def test_given_entity_when_retrieve_by_email_then_success(self):
516
584
# fail case with invalid email retrieve_by_email
517
585
@pytest .mark .asyncio
518
586
async def test_given_invalid_email_when_retrieve_by_email_then_fail (self ):
587
+ """
588
+ Test case to handle invalid email during user entity retrieval by email.
589
+ """
519
590
_log .info ("test_given_invalid_email_when_retrieve_by_email_then_fail" )
520
591
521
592
# Given
@@ -531,6 +602,9 @@ async def test_given_invalid_email_when_retrieve_by_email_then_fail(self):
531
602
# success case with valid username retrieve_by_username
532
603
@pytest .mark .asyncio
533
604
async def test_given_entity_when_retrieve_by_username_then_success (self ):
605
+ """
606
+ Test case to retrieve a user entity by username and verify the results.
607
+ """
534
608
_log .info ("test_given_entity_when_retrieve_by_username_then_success" )
535
609
536
610
# Given
@@ -553,6 +627,9 @@ async def test_given_entity_when_retrieve_by_username_then_success(self):
553
627
# fail case with invalid username retrieve_by_username
554
628
@pytest .mark .asyncio
555
629
async def test_given_invalid_username_when_retrieve_by_username_then_fail (self ):
630
+ """
631
+ Test case to handle invalid username during user entity retrieval by username.
632
+ """
556
633
_log .info ("test_given_invalid_username_when_retrieve_by_username_then_fail" )
557
634
558
635
# Given
0 commit comments