forked from p15670423/monkey
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.
This commit is contained in:
parent
f1c7cf4047
commit
f3865d022b
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue