From 1abbff241dbc065869f186fdc8b3cf6e8a522b44 Mon Sep 17 00:00:00 2001 From: Setepenre Date: Wed, 1 Dec 2021 10:57:58 -0500 Subject: [PATCH 1/6] replace count by count_documents --- .../unittests/core/database/test_database.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/unittests/core/database/test_database.py b/tests/unittests/core/database/test_database.py index 8bb8fed23..cfbf7b5c4 100644 --- a/tests/unittests/core/database/test_database.py +++ b/tests/unittests/core/database/test_database.py @@ -399,11 +399,11 @@ def test_insert_many(self, orion_db): {"exp_name": "supernaekei2", "user": "tsirif"}, {"exp_name": "supernaekei3", "user": "tsirif"}, ] - count_before = get_db(orion_db)["experiments"].count() + count_before = get_db(orion_db)["experiments"].count_documents() # call interface assert orion_db.write("experiments", item) == 2 database = get_db(orion_db) - assert database["experiments"].count() == count_before + 2 + assert database["experiments"].count_documents() == count_before + 2 value = database["experiments"].find({"exp_name": "supernaekei2"})[0] assert value == item[0] value = database["experiments"].find({"exp_name": "supernaekei3"})[0] @@ -420,7 +420,7 @@ def test_update_many_default(self, orion_db): == count_query ) database = get_db(orion_db) - assert database["test_collection"].count() == count_before + assert database["test_collection"].count_documents() == count_before value = list(database["test_collection"].find({})) assert value[0]["same_field"] == "diff" assert value[1]["same_field"] == "same" @@ -433,7 +433,7 @@ def test_update_with_id(self, orion_db, test_collection): # call interface assert orion_db.write("test_collection", {"same_field": "diff"}, filt) == 1 database = get_db(orion_db) - assert database["test_collection"].count() == count_before + assert database["test_collection"].count_documents() == count_before value = list(database["test_collection"].find()) assert value[0]["same_field"] == "same" assert value[1]["same_field"] == "diff" @@ -501,13 +501,13 @@ def test_remove_many_default(self, orion_db, test_collection): """Should match existing entries, and delete them all.""" filt = {"field1": "same1"} database = get_db(orion_db) - count_before = database["test_collection"].count() - count_filt = database["test_collection"].count(filt) + count_before = database["test_collection"].count_documents() + count_filt = database["test_collection"].count_documents(filt) # call interface assert orion_db.remove("test_collection", filt) == count_filt database = get_db(orion_db) - assert database["test_collection"].count() == count_before - count_filt - assert database["test_collection"].count() == 1 + assert database["test_collection"].count_documents() == count_before - count_filt + assert database["test_collection"].count_documents() == 1 loaded_config = list(database["test_collection"].find()) assert loaded_config == test_collection[1:2] @@ -516,11 +516,11 @@ def test_remove_with_id(self, orion_db, test_collection): filt = {"_id": test_collection[0]["_id"]} database = get_db(orion_db) - count_before = database["test_collection"].count() + count_before = database["test_collection"].count_documents() # call interface assert orion_db.remove("test_collection", filt) == 1 database = get_db(orion_db) - assert database["test_collection"].count() == count_before - 1 + assert database["test_collection"].count_documents() == count_before - 1 loaded_configs = list(database["test_collection"].find()) assert loaded_configs == test_collection[1:] @@ -534,11 +534,11 @@ def test_remove_update_indexes(self, orion_db, test_collection): filt = {"_id": test_collection[0]["_id"]} database = get_db(orion_db) - count_before = database["test_collection"].count() + count_before = database["test_collection"].count_documents() # call interface assert orion_db.remove("test_collection", filt) == 1 database = get_db(orion_db) - assert database["test_collection"].count() == count_before - 1 + assert database["test_collection"].count_documents() == count_before - 1 # Should not fail now, otherwise it means the indexes were not updated properly during # remove() orion_db.write("test_collection", filt) From b78c7c15df351a9b8de3ee2deeaf4bbcd4bfb519 Mon Sep 17 00:00:00 2001 From: Setepenre Date: Wed, 1 Dec 2021 11:00:30 -0500 Subject: [PATCH 2/6] - --- tests/unittests/core/database/test_database.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unittests/core/database/test_database.py b/tests/unittests/core/database/test_database.py index cfbf7b5c4..807407973 100644 --- a/tests/unittests/core/database/test_database.py +++ b/tests/unittests/core/database/test_database.py @@ -506,7 +506,9 @@ def test_remove_many_default(self, orion_db, test_collection): # call interface assert orion_db.remove("test_collection", filt) == count_filt database = get_db(orion_db) - assert database["test_collection"].count_documents() == count_before - count_filt + assert ( + database["test_collection"].count_documents() == count_before - count_filt + ) assert database["test_collection"].count_documents() == 1 loaded_config = list(database["test_collection"].find()) assert loaded_config == test_collection[1:2] From 2fd34001a3f985af542191396a49be6650e9e843 Mon Sep 17 00:00:00 2001 From: Setepenre Date: Wed, 1 Dec 2021 11:08:21 -0500 Subject: [PATCH 3/6] - --- .../unittests/core/database/test_database.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/unittests/core/database/test_database.py b/tests/unittests/core/database/test_database.py index 807407973..898243381 100644 --- a/tests/unittests/core/database/test_database.py +++ b/tests/unittests/core/database/test_database.py @@ -399,11 +399,11 @@ def test_insert_many(self, orion_db): {"exp_name": "supernaekei2", "user": "tsirif"}, {"exp_name": "supernaekei3", "user": "tsirif"}, ] - count_before = get_db(orion_db)["experiments"].count_documents() + count_before = get_db(orion_db)["experiments"].count_documents({}) # call interface assert orion_db.write("experiments", item) == 2 database = get_db(orion_db) - assert database["experiments"].count_documents() == count_before + 2 + assert database["experiments"].count_documents({}) == count_before + 2 value = database["experiments"].find({"exp_name": "supernaekei2"})[0] assert value == item[0] value = database["experiments"].find({"exp_name": "supernaekei3"})[0] @@ -420,7 +420,7 @@ def test_update_many_default(self, orion_db): == count_query ) database = get_db(orion_db) - assert database["test_collection"].count_documents() == count_before + assert database["test_collection"].count_documents({}) == count_before value = list(database["test_collection"].find({})) assert value[0]["same_field"] == "diff" assert value[1]["same_field"] == "same" @@ -433,7 +433,7 @@ def test_update_with_id(self, orion_db, test_collection): # call interface assert orion_db.write("test_collection", {"same_field": "diff"}, filt) == 1 database = get_db(orion_db) - assert database["test_collection"].count_documents() == count_before + assert database["test_collection"].count_documents({}) == count_before value = list(database["test_collection"].find()) assert value[0]["same_field"] == "same" assert value[1]["same_field"] == "diff" @@ -501,15 +501,15 @@ def test_remove_many_default(self, orion_db, test_collection): """Should match existing entries, and delete them all.""" filt = {"field1": "same1"} database = get_db(orion_db) - count_before = database["test_collection"].count_documents() + count_before = database["test_collection"].count_documents({}) count_filt = database["test_collection"].count_documents(filt) # call interface assert orion_db.remove("test_collection", filt) == count_filt database = get_db(orion_db) assert ( - database["test_collection"].count_documents() == count_before - count_filt + database["test_collection"].count_documents({}) == count_before - count_filt ) - assert database["test_collection"].count_documents() == 1 + assert database["test_collection"].count_documents({}) == 1 loaded_config = list(database["test_collection"].find()) assert loaded_config == test_collection[1:2] @@ -518,11 +518,11 @@ def test_remove_with_id(self, orion_db, test_collection): filt = {"_id": test_collection[0]["_id"]} database = get_db(orion_db) - count_before = database["test_collection"].count_documents() + count_before = database["test_collection"].count_documents({}) # call interface assert orion_db.remove("test_collection", filt) == 1 database = get_db(orion_db) - assert database["test_collection"].count_documents() == count_before - 1 + assert database["test_collection"].count_documents({}) == count_before - 1 loaded_configs = list(database["test_collection"].find()) assert loaded_configs == test_collection[1:] @@ -536,11 +536,11 @@ def test_remove_update_indexes(self, orion_db, test_collection): filt = {"_id": test_collection[0]["_id"]} database = get_db(orion_db) - count_before = database["test_collection"].count_documents() + count_before = database["test_collection"].count_documents({}) # call interface assert orion_db.remove("test_collection", filt) == 1 database = get_db(orion_db) - assert database["test_collection"].count_documents() == count_before - 1 + assert database["test_collection"].count_documents({}) == count_before - 1 # Should not fail now, otherwise it means the indexes were not updated properly during # remove() orion_db.write("test_collection", filt) From 0b84049367da83b51779094c465023c045a42fe6 Mon Sep 17 00:00:00 2001 From: Setepenre Date: Wed, 1 Dec 2021 11:19:48 -0500 Subject: [PATCH 4/6] - --- .../unittests/core/database/test_database.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/unittests/core/database/test_database.py b/tests/unittests/core/database/test_database.py index 898243381..7d1a39dfc 100644 --- a/tests/unittests/core/database/test_database.py +++ b/tests/unittests/core/database/test_database.py @@ -399,11 +399,11 @@ def test_insert_many(self, orion_db): {"exp_name": "supernaekei2", "user": "tsirif"}, {"exp_name": "supernaekei3", "user": "tsirif"}, ] - count_before = get_db(orion_db)["experiments"].count_documents({}) + count_before = orion_db.count("experiments") # call interface assert orion_db.write("experiments", item) == 2 database = get_db(orion_db) - assert database["experiments"].count_documents({}) == count_before + 2 + assert orion_db.count("experiments") == count_before + 2 value = database["experiments"].find({"exp_name": "supernaekei2"})[0] assert value == item[0] value = database["experiments"].find({"exp_name": "supernaekei3"})[0] @@ -420,7 +420,7 @@ def test_update_many_default(self, orion_db): == count_query ) database = get_db(orion_db) - assert database["test_collection"].count_documents({}) == count_before + assert orion_db.count("test_collection") == count_before value = list(database["test_collection"].find({})) assert value[0]["same_field"] == "diff" assert value[1]["same_field"] == "same" @@ -433,7 +433,7 @@ def test_update_with_id(self, orion_db, test_collection): # call interface assert orion_db.write("test_collection", {"same_field": "diff"}, filt) == 1 database = get_db(orion_db) - assert database["test_collection"].count_documents({}) == count_before + assert orion_db.count("test_collection") == count_before value = list(database["test_collection"].find()) assert value[0]["same_field"] == "same" assert value[1]["same_field"] == "diff" @@ -501,15 +501,15 @@ def test_remove_many_default(self, orion_db, test_collection): """Should match existing entries, and delete them all.""" filt = {"field1": "same1"} database = get_db(orion_db) - count_before = database["test_collection"].count_documents({}) - count_filt = database["test_collection"].count_documents(filt) + count_before = orion_db.count("test_collection") + count_filt = orion_db.count("test_collection", filt) # call interface assert orion_db.remove("test_collection", filt) == count_filt database = get_db(orion_db) assert ( - database["test_collection"].count_documents({}) == count_before - count_filt + orion_db.count("test_collection") == count_before - count_filt ) - assert database["test_collection"].count_documents({}) == 1 + assert orion_db.count("test_collection") == 1 loaded_config = list(database["test_collection"].find()) assert loaded_config == test_collection[1:2] @@ -518,11 +518,11 @@ def test_remove_with_id(self, orion_db, test_collection): filt = {"_id": test_collection[0]["_id"]} database = get_db(orion_db) - count_before = database["test_collection"].count_documents({}) + count_before = orion_db.count("test_collection") # call interface assert orion_db.remove("test_collection", filt) == 1 database = get_db(orion_db) - assert database["test_collection"].count_documents({}) == count_before - 1 + assert orion_db.count("test_collection") == count_before - 1 loaded_configs = list(database["test_collection"].find()) assert loaded_configs == test_collection[1:] @@ -536,11 +536,11 @@ def test_remove_update_indexes(self, orion_db, test_collection): filt = {"_id": test_collection[0]["_id"]} database = get_db(orion_db) - count_before = database["test_collection"].count_documents({}) + count_before = orion_db.count("test_collection") # call interface assert orion_db.remove("test_collection", filt) == 1 database = get_db(orion_db) - assert database["test_collection"].count_documents({}) == count_before - 1 + assert orion_db.count("test_collection") == count_before - 1 # Should not fail now, otherwise it means the indexes were not updated properly during # remove() orion_db.write("test_collection", filt) From ea150fb58049aa9654bdb84243c240a13982eafd Mon Sep 17 00:00:00 2001 From: Setepenre Date: Wed, 1 Dec 2021 11:21:11 -0500 Subject: [PATCH 5/6] - --- tests/unittests/core/database/test_database.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/unittests/core/database/test_database.py b/tests/unittests/core/database/test_database.py index 7d1a39dfc..e2686de85 100644 --- a/tests/unittests/core/database/test_database.py +++ b/tests/unittests/core/database/test_database.py @@ -506,9 +506,7 @@ def test_remove_many_default(self, orion_db, test_collection): # call interface assert orion_db.remove("test_collection", filt) == count_filt database = get_db(orion_db) - assert ( - orion_db.count("test_collection") == count_before - count_filt - ) + assert orion_db.count("test_collection") == count_before - count_filt assert orion_db.count("test_collection") == 1 loaded_config = list(database["test_collection"].find()) assert loaded_config == test_collection[1:2] From 13ea9a041d804697668756c3a55db02704a13bcb Mon Sep 17 00:00:00 2001 From: Setepenre Date: Wed, 1 Dec 2021 11:41:26 -0500 Subject: [PATCH 6/6] remove unused db --- tests/unittests/core/database/test_database.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/unittests/core/database/test_database.py b/tests/unittests/core/database/test_database.py index e2686de85..e60f00edd 100644 --- a/tests/unittests/core/database/test_database.py +++ b/tests/unittests/core/database/test_database.py @@ -500,7 +500,6 @@ class TestRemove(object): def test_remove_many_default(self, orion_db, test_collection): """Should match existing entries, and delete them all.""" filt = {"field1": "same1"} - database = get_db(orion_db) count_before = orion_db.count("test_collection") count_filt = orion_db.count("test_collection", filt) # call interface @@ -515,8 +514,8 @@ def test_remove_with_id(self, orion_db, test_collection): """Query using ``_id`` key.""" filt = {"_id": test_collection[0]["_id"]} - database = get_db(orion_db) count_before = orion_db.count("test_collection") + # call interface assert orion_db.remove("test_collection", filt) == 1 database = get_db(orion_db) @@ -533,11 +532,9 @@ def test_remove_update_indexes(self, orion_db, test_collection): filt = {"_id": test_collection[0]["_id"]} - database = get_db(orion_db) count_before = orion_db.count("test_collection") # call interface assert orion_db.remove("test_collection", filt) == 1 - database = get_db(orion_db) assert orion_db.count("test_collection") == count_before - 1 # Should not fail now, otherwise it means the indexes were not updated properly during # remove()