Skip to content

Commit

Permalink
Merge pull request #707 from Delaunay/fix_mongo
Browse files Browse the repository at this point in the history
replace count by count_documents #706
  • Loading branch information
bouthilx committed Dec 1, 2021
2 parents ed9a57a + 13ea9a0 commit a77128d
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions tests/unittests/core/database/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = orion_db.count("experiments")
# call interface
assert orion_db.write("experiments", item) == 2
database = get_db(orion_db)
assert database["experiments"].count() == 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]
Expand All @@ -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 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"
Expand All @@ -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 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"
Expand Down Expand Up @@ -500,27 +500,26 @@ 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 = database["test_collection"].count()
count_filt = database["test_collection"].count(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() == count_before - count_filt
assert database["test_collection"].count() == 1
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]

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 = database["test_collection"].count()
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() == 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:]

Expand All @@ -533,12 +532,10 @@ 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 = 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() == 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)
Expand Down

0 comments on commit a77128d

Please sign in to comment.