diff --git a/monkey/tests/unit_tests/monkey_island/cc/repository/test_mongo_credentials_repository.py b/monkey/tests/unit_tests/monkey_island/cc/repository/test_mongo_credentials_repository.py index 8148780d3..6debde1bb 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/repository/test_mongo_credentials_repository.py +++ b/monkey/tests/unit_tests/monkey_island/cc/repository/test_mongo_credentials_repository.py @@ -1,4 +1,4 @@ -import mongoengine +import mongomock import pytest from common.credentials import Credentials @@ -53,80 +53,81 @@ CREDENTIALS_LIST = [ @pytest.fixture -def fake_mongo_repository(monkeypatch): - mongo = mongoengine.connection.get_connection() +def mongo_repository(): + mongo = mongomock.MongoClient() + return MongoCredentialsRepository(mongo) -def test_mongo_repository_get_configured(fake_mongo_repository): +def test_mongo_repository_get_configured(mongo_repository): - actual_configured_credentials = fake_mongo_repository.get_configured_credentials() + actual_configured_credentials = mongo_repository.get_configured_credentials() assert actual_configured_credentials == [] -def test_mongo_repository_get_stolen(fake_mongo_repository): +def test_mongo_repository_get_stolen(mongo_repository): - actual_stolen_credentials = fake_mongo_repository.get_stolen_credentials() + actual_stolen_credentials = mongo_repository.get_stolen_credentials() assert actual_stolen_credentials == [] -def test_mongo_repository_get_all(fake_mongo_repository): +def test_mongo_repository_get_all(mongo_repository): - actual_credentials = fake_mongo_repository.get_all_credentials() + actual_credentials = mongo_repository.get_all_credentials() assert actual_credentials == [] -def test_mongo_repository_configured(fake_mongo_repository): +def test_mongo_repository_configured(mongo_repository): - fake_mongo_repository.save_configured_credentials(CREDENTIALS_LIST) + mongo_repository.save_configured_credentials(CREDENTIALS_LIST) - actual_configured_credentials = fake_mongo_repository.get_configured_credentials() + actual_configured_credentials = mongo_repository.get_configured_credentials() assert actual_configured_credentials == CREDENTIALS_LIST - fake_mongo_repository.remove_configured_credentials() + mongo_repository.remove_configured_credentials() - actual_configured_credentials = fake_mongo_repository.get_configured_credentials() + actual_configured_credentials = mongo_repository.get_configured_credentials() assert actual_configured_credentials == [] -def test_mongo_repository_stolen(fake_mongo_repository): +def test_mongo_repository_stolen(mongo_repository): - fake_mongo_repository.save_configured_credentials(CONFIGURED_CREDENTIALS) - fake_mongo_repository.save_stolen_credentials(STOLEN_CREDENTIALS) + mongo_repository.save_configured_credentials(CONFIGURED_CREDENTIALS) + mongo_repository.save_stolen_credentials(STOLEN_CREDENTIALS) - actual_stolen_credentials = fake_mongo_repository.get_stolen_credentials() + actual_stolen_credentials = mongo_repository.get_stolen_credentials() assert actual_stolen_credentials == STOLEN_CREDENTIALS - fake_mongo_repository.remove_stolen_credentials() + mongo_repository.remove_stolen_credentials() - actual_stolen_credentials = fake_mongo_repository.get_stolen_credentials() + actual_stolen_credentials = mongo_repository.get_stolen_credentials() assert actual_stolen_credentials == [] # Must remove configured also for the next tests - fake_mongo_repository.remove_configured_credentials() + mongo_repository.remove_configured_credentials() -def test_mongo_repository_all(fake_mongo_repository): +def test_mongo_repository_all(mongo_repository): - fake_mongo_repository.save_configured_credentials(CONFIGURED_CREDENTIALS) - fake_mongo_repository.save_stolen_credentials(STOLEN_CREDENTIALS) + mongo_repository.save_configured_credentials(CONFIGURED_CREDENTIALS) + mongo_repository.save_stolen_credentials(STOLEN_CREDENTIALS) - actual_credentials = fake_mongo_repository.get_all_credentials() + actual_credentials = mongo_repository.get_all_credentials() assert actual_credentials == CREDENTIALS_LIST - fake_mongo_repository.remove_all_credentials() + mongo_repository.remove_all_credentials() - actual_credentials = fake_mongo_repository.get_all_credentials() - actual_stolen_credentials = fake_mongo_repository.get_stolen_credentials() - actual_configured_credentials = fake_mongo_repository.get_configured_credentials() + actual_credentials = mongo_repository.get_all_credentials() + actual_stolen_credentials = mongo_repository.get_stolen_credentials() + actual_configured_credentials = mongo_repository.get_configured_credentials() assert actual_credentials == [] assert actual_stolen_credentials == []