4949 async_get_as_pymongo ,
5050 requires_mongodb_gte_44 , reset_async_connections ,
5151)
52+ from tests .utils import MONGO_TEST_DB
5253
5354TEST_IMAGE_PATH = os .path .join (os .path .dirname (__file__ ), "../fields/mongoengine.png" )
5455
@@ -491,7 +492,7 @@ class Animal(Document):
491492 CMD_QUERY_KEY = "command"
492493 async with async_query_counter () as q :
493494 await doc .areload ()
494- query_op = (await ((await q .db ).system .profile .find ({"ns" : "mongoenginetest .animal" })).to_list ())[0 ]
495+ query_op = (await ((await q .db ).system .profile .find ({"ns" : f" { MONGO_TEST_DB } .animal" })).to_list ())[0 ]
495496 assert set (query_op [CMD_QUERY_KEY ]["filter" ].keys ()) == {
496497 "_id" ,
497498 "superphylum" ,
@@ -508,7 +509,7 @@ class Person(Document):
508509 CMD_QUERY_KEY = "command"
509510 async with async_query_counter () as q :
510511 await doc .areload ()
511- query_op = (await ((await q .db ).system .profile .find ({"ns" : "mongoenginetest .person" })).to_list ())[0 ]
512+ query_op = (await ((await q .db ).system .profile .find ({"ns" : f" { MONGO_TEST_DB } .person" })).to_list ())[0 ]
512513 assert set (query_op [CMD_QUERY_KEY ]["filter" ].keys ()) == {"_id" , "country" }
513514
514515 async def test_reload_sharded_nested (self ):
@@ -542,7 +543,7 @@ class Animal(Document):
542543 async with async_query_counter () as q :
543544 doc .name = "Cat"
544545 await doc .asave ()
545- query_op = (await ((await q .db ).system .profile .find ({"ns" : "mongoenginetest .animal" })).to_list ())[0 ]
546+ query_op = (await ((await q .db ).system .profile .find ({"ns" : f" { MONGO_TEST_DB } .animal" })).to_list ())[0 ]
546547 assert query_op ["op" ] == "update"
547548 assert set (query_op ["command" ]["q" ].keys ()) == {"_id" , "is_mammal" }
548549
@@ -564,7 +565,7 @@ class Animal(Document):
564565
565566 async with async_query_counter () as q :
566567 await doc .asave ()
567- query_op = (await ((await q .db ).system .profile .find ({"ns" : "mongoenginetest .animal" })).to_list ())[0 ]
568+ query_op = (await ((await q .db ).system .profile .find ({"ns" : f" { MONGO_TEST_DB } .animal" })).to_list ())[0 ]
568569 assert query_op ["op" ] == "command"
569570 assert query_op ["command" ]["findAndModify" ] == "animal"
570571 assert set (query_op ["command" ]["query" ].keys ()) == {"_id" , "is_mammal" }
@@ -1894,23 +1895,23 @@ class AggPerson(Document):
18941895
18951896 async with async_db_ops_tracker () as q :
18961897 _ = await AggPerson .aobjects .comment (comment ).update_one (name = "something" )
1897- query_op = (await ((await q .db ).system .profile .find ({"ns" : "mongoenginetest .agg_person" })).to_list ())[0 ]
1898+ query_op = (await ((await q .db ).system .profile .find ({"ns" : f" { MONGO_TEST_DB } .agg_person" })).to_list ())[0 ]
18981899 CMD_QUERY_KEY = "command"
18991900 assert "hint" not in query_op [CMD_QUERY_KEY ]
19001901 assert query_op [CMD_QUERY_KEY ]["comment" ] == comment
19011902 assert "collation" not in query_op [CMD_QUERY_KEY ]
19021903
19031904 async with async_db_ops_tracker () as q :
19041905 _ = await AggPerson .aobjects .hint (index_name ).update_one (name = "something" )
1905- query_op = (await ((await q .db ).system .profile .find ({"ns" : "mongoenginetest .agg_person" })).to_list ())[0 ]
1906+ query_op = (await ((await q .db ).system .profile .find ({"ns" : f" { MONGO_TEST_DB } .agg_person" })).to_list ())[0 ]
19061907 CMD_QUERY_KEY = "command"
19071908 assert query_op [CMD_QUERY_KEY ]["hint" ] == {"$hint" : index_name }
19081909 assert "comment" not in query_op [CMD_QUERY_KEY ]
19091910 assert "collation" not in query_op [CMD_QUERY_KEY ]
19101911
19111912 async with async_db_ops_tracker () as q :
19121913 _ = await AggPerson .aobjects .collation (base ).update_one (name = "something" )
1913- query_op = (await ((await q .db ).system .profile .find ({"ns" : "mongoenginetest .agg_person" })).to_list ())[0 ]
1914+ query_op = (await ((await q .db ).system .profile .find ({"ns" : f" { MONGO_TEST_DB } .agg_person" })).to_list ())[0 ]
19141915 CMD_QUERY_KEY = "command"
19151916 assert "hint" not in query_op [CMD_QUERY_KEY ]
19161917 assert "comment" not in query_op [CMD_QUERY_KEY ]
@@ -1943,23 +1944,23 @@ class AggPerson(Document):
19431944
19441945 async with async_db_ops_tracker () as q :
19451946 _ = await AggPerson .aobjects ().comment (comment ).delete ()
1946- query_op = (await ((await q .db ).system .profile .find ({"ns" : "mongoenginetest .agg_person" })).to_list ())[0 ]
1947+ query_op = (await ((await q .db ).system .profile .find ({"ns" : f" { MONGO_TEST_DB } .agg_person" })).to_list ())[0 ]
19471948 CMD_QUERY_KEY = "command"
19481949 assert "hint" not in query_op [CMD_QUERY_KEY ]
19491950 assert query_op [CMD_QUERY_KEY ]["comment" ] == comment
19501951 assert "collation" not in query_op [CMD_QUERY_KEY ]
19511952
19521953 async with async_db_ops_tracker () as q :
19531954 _ = await AggPerson .aobjects .hint (index_name ).delete ()
1954- query_op = (await ((await q .db ).system .profile .find ({"ns" : "mongoenginetest .agg_person" })).to_list ())[0 ]
1955+ query_op = (await ((await q .db ).system .profile .find ({"ns" : f" { MONGO_TEST_DB } .agg_person" })).to_list ())[0 ]
19551956 CMD_QUERY_KEY = "command"
19561957 assert query_op [CMD_QUERY_KEY ]["hint" ] == {"$hint" : index_name }
19571958 assert "comment" not in query_op [CMD_QUERY_KEY ]
19581959 assert "collation" not in query_op [CMD_QUERY_KEY ]
19591960
19601961 async with async_db_ops_tracker () as q :
19611962 _ = await AggPerson .aobjects .collation (base ).delete ()
1962- query_op = (await ((await q .db ).system .profile .find ({"ns" : "mongoenginetest .agg_person" })).to_list ())[0 ]
1963+ query_op = (await ((await q .db ).system .profile .find ({"ns" : f" { MONGO_TEST_DB } .agg_person" })).to_list ())[0 ]
19631964 CMD_QUERY_KEY = "command"
19641965 assert "hint" not in query_op [CMD_QUERY_KEY ]
19651966 assert "comment" not in query_op [CMD_QUERY_KEY ]
@@ -2867,9 +2868,9 @@ async def test_db_alias_tests(self):
28672868 """DB Alias tests."""
28682869 # mongoenginetest - Is default connection alias from setUp()
28692870 # Register Aliases
2870- await async_register_connection ("testdb-1" , "mongoenginetest2 " )
2871- await async_register_connection ("testdb-2" , "mongoenginetest3 " )
2872- await async_register_connection ("testdb-3" , "mongoenginetest4 " )
2871+ await async_register_connection ("testdb-1" , f" { MONGO_TEST_DB } _2 " )
2872+ await async_register_connection ("testdb-2" , f" { MONGO_TEST_DB } _3 " )
2873+ await async_register_connection ("testdb-3" , f" { MONGO_TEST_DB } _4 " )
28732874
28742875 class User (Document ):
28752876 name = StringField ()
@@ -2931,7 +2932,7 @@ class AuthorBooks(Document):
29312932 async def test_db_alias_overrides (self ):
29322933 """Test db_alias can be overriden."""
29332934 # Register a connection with db_alias testdb-2
2934- await async_register_connection ("testdb-2" , "mongoenginetest2 " )
2935+ await async_register_connection ("testdb-2" , f" { MONGO_TEST_DB } _2 " )
29352936
29362937 class A (Document ):
29372938 """Uses default db_alias"""
@@ -2947,13 +2948,13 @@ class B(A):
29472948 A .aobjects .all ()
29482949
29492950 assert "testdb-2" == B ._meta .get ("db_alias" )
2950- assert "mongoenginetest" == (await A ._aget_collection ()).database .name
2951- assert "mongoenginetest2 " == (await B ._aget_collection ()).database .name
2951+ assert MONGO_TEST_DB == (await A ._aget_collection ()).database .name
2952+ assert f" { MONGO_TEST_DB } _2 " == (await B ._aget_collection ()).database .name
29522953 await async_disconnect ("testdb-2" )
29532954
29542955 async def test_db_alias_propagates (self ):
29552956 """db_alias propagates?"""
2956- await async_register_connection ("testdb-1" , "mongoenginetest2 " )
2957+ await async_register_connection ("testdb-1" , f" { MONGO_TEST_DB } _2 " )
29572958
29582959 class A (Document ):
29592960 name = StringField ()
@@ -3049,7 +3050,7 @@ def __str__(self):
30493050 assert [str (b ) async for b in custom_qs ] == ["1" , "2" ]
30503051
30513052 async def test_switch_db_instance (self ):
3052- await async_register_connection ("testdb-1" , "mongoenginetest2 " )
3053+ await async_register_connection ("testdb-1" , f" { MONGO_TEST_DB } _2 " )
30533054
30543055 class Group (Document ):
30553056 name = StringField ()
@@ -3098,8 +3099,8 @@ class Group(Document):
30983099 assert "hello - default" == group .name
30993100
31003101 async def test_switch_db_multiple_documents_same_context (self ):
3101- await async_register_connection ("testdb-1" , "mongoenginetest2 " )
3102- await async_register_connection ("testdb-2" , "mongoenginetest3 " )
3102+ await async_register_connection ("testdb-1" , f" { MONGO_TEST_DB } _2 " )
3103+ await async_register_connection ("testdb-2" , f" { MONGO_TEST_DB } _3 " )
31033104
31043105 class Group (Document ):
31053106 name = StringField ()
@@ -3155,7 +3156,7 @@ class Post(Document):
31553156 assert p2 .title == "post-testdb-2"
31563157
31573158 async def test_switch_db_and_switch_collection_instance (self ):
3158- await async_register_connection ("testdb-1" , "mongoenginetest2 " )
3159+ await async_register_connection ("testdb-1" , f" { MONGO_TEST_DB } _2 " )
31593160
31603161 class Group (Document ):
31613162 name = StringField ()
@@ -3218,8 +3219,8 @@ class Group(Document):
32183219 assert "hello - default" == g0 .name
32193220
32203221 async def test_switch_multiple_db_and_multiple_collection_same_time (self ):
3221- await async_register_connection ("tenantA" , "mongoenginetest2 " )
3222- await async_register_connection ("tenantB" , "mongoenginetest2 " )
3222+ await async_register_connection ("tenantA" , f" { MONGO_TEST_DB } _2 " )
3223+ await async_register_connection ("tenantB" , f" { MONGO_TEST_DB } _2 " )
32233224
32243225 class User (Document ):
32253226 name = StringField ()
0 commit comments