@@ -403,21 +403,21 @@ async def test_sharing_async_connections(self):
403403 async def test_async_connect_uri (self ):
404404 """Ensure that the async_connect() method works properly with URIs."""
405405 c = await async_connect (db = MONGO_TEST_DB , alias = "admin" )
406- await c . admin . system . users . delete_many ({})
407- await c . mongoenginetest . system . users . delete_many ({})
406+ admin_username = f"admin_ { uuid . uuid4 (). hex [: 8 ] } "
407+ user_username = f"user_ { uuid . uuid4 (). hex [: 8 ] } "
408408
409- await c .admin .command ("createUser" , "admin" , pwd = "password" , roles = ["root" ])
409+ await c .admin .command ("createUser" , admin_username , pwd = "password" , roles = ["root" ])
410410
411411 adminadmin_settings = connection ._connection_settings [
412412 "adminadmin"
413413 ] = connection ._connection_settings ["admin" ].copy ()
414- adminadmin_settings ["username" ] = "admin"
414+ adminadmin_settings ["username" ] = admin_username
415415 adminadmin_settings ["password" ] = "password"
416416 ca = await async_connect (db = MONGO_TEST_DB , alias = "adminadmin" )
417- await ca .admin .command ("createUser" , "username" , pwd = "password" , roles = ["dbOwner" ])
417+ await ca .admin .command ("createUser" , user_username , pwd = "password" , roles = ["dbOwner" ])
418418
419419 await async_connect (
420- "testdb_uri " , host = f"mongodb://username:password@localhost/{ MONGO_TEST_DB } "
420+ f" { MONGO_TEST_DB } _testdb_uri " , host = f"mongodb://username:password@localhost/{ MONGO_TEST_DB } "
421421 )
422422
423423 conn = await async_get_connection ()
@@ -427,8 +427,8 @@ async def test_async_connect_uri(self):
427427 assert isinstance (db , AsyncDatabase )
428428 assert db .name == MONGO_TEST_DB
429429
430- await c .admin .system . users . delete_many ({} )
431- await c .mongoenginetest . system . users . delete_many ({} )
430+ await c .admin .command ( "dropUser" , user_username )
431+ await c .admin . command ( "dropUser" , admin_username )
432432
433433 @pytest .mark .asyncio
434434 async def test_async_connect_uri_without_db (self ):
@@ -487,14 +487,14 @@ async def test_async_connect_uri_with_authsource(self):
487487 # Create users
488488 c = await async_connect (MONGO_TEST_DB )
489489
490- await c . admin . system . users . delete_many ({})
491- await c .admin .command ("createUser" , "username2" , pwd = "password" , roles = ["dbOwner" ])
490+ username = f"user_ { uuid . uuid4 (). hex [: 8 ] } "
491+ await c .admin .command ("createUser" , username , pwd = "password" , roles = ["dbOwner" ])
492492
493493 # Authentication fails without "authSource"
494494 test_conn = await async_connect (
495495 MONGO_TEST_DB ,
496496 alias = "test1" ,
497- host = f"mongodb://username2 :password@localhost/{ MONGO_TEST_DB } " ,
497+ host = f"mongodb://{ username } :password@localhost/{ MONGO_TEST_DB } " ,
498498 )
499499 with pytest .raises (OperationFailure ):
500500 await test_conn .server_info ()
@@ -504,15 +504,15 @@ async def test_async_connect_uri_with_authsource(self):
504504 MONGO_TEST_DB ,
505505 alias = "test2" ,
506506 host = (
507- f"mongodb://username2 :password@localhost/{ MONGO_TEST_DB } ?authSource=admin"
507+ f"mongodb://{ username } :password@localhost/{ MONGO_TEST_DB } ?authSource=admin"
508508 ),
509509 )
510510 db = await async_get_db ("test2" )
511511 assert isinstance (db , AsyncDatabase )
512512 assert db .name == MONGO_TEST_DB
513513
514514 # Clear all users
515- await authd_conn .admin .system . users . delete_many ({} )
515+ await authd_conn .admin .command ( "dropUser" , username )
516516
517517 @pytest .mark .asyncio
518518 async def test_register_async_connection (self ):
0 commit comments