From f3865d022bb25365ebb9749beb3e1a8e86ba6040 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Wed, 22 Sep 2021 13:41:40 +0300 Subject: [PATCH] Change mongomock_fixtures.py to drop the whole database instead of specified collections. This makes it easier to add new database related tests, because we no longer need to modify the mongomock_fixtures.py to also drop a particular collection we are testing. --- .../monkey_island/cc/mongomock_fixtures.py | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/mongomock_fixtures.py b/monkey/tests/unit_tests/monkey_island/cc/mongomock_fixtures.py index 26a41685a..aa00aa69a 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/mongomock_fixtures.py +++ b/monkey/tests/unit_tests/monkey_island/cc/mongomock_fixtures.py @@ -1,32 +1,20 @@ import mongoengine import pytest -from monkey_island.cc.models import Monkey -from monkey_island.cc.models.edge import Edge -from monkey_island.cc.models.zero_trust.finding import Finding +MOCK_DB_NAME = "mongoenginetest" @pytest.fixture(scope="module", autouse=True) def change_to_mongo_mock(): # Make sure tests are working with mongomock mongoengine.disconnect() - mongoengine.connect("mongoenginetest", host="mongomock://localhost") + mongoengine.connect(MOCK_DB_NAME, host="mongomock://localhost") @pytest.fixture(scope="function") def uses_database(): - _clean_edge_db() - _clean_monkey_db() - _clean_finding_db() + _drop_database() -def _clean_monkey_db(): - Monkey.objects().delete() - - -def _clean_edge_db(): - Edge.objects().delete() - - -def _clean_finding_db(): - Finding.objects().delete() +def _drop_database(): + mongoengine.connection.get_connection().drop_database(MOCK_DB_NAME)