Improved unit test readability and fixed bugs related to refactoring of mongodb parameters in environment config

This commit is contained in:
VakarisZ 2021-05-26 16:32:26 +03:00
parent 2e600fd5b2
commit f2c8de9eb6
4 changed files with 13 additions and 10 deletions

View File

@ -1,11 +1,3 @@
import monkey_island.cc.environment.environment_singleton as env_singleton
from monkey_island.cc.environment.testing import TestingEnvironment
# Mock environment singleton because it contains mongodb parameters
# needed for model tests. See monkey/monkey_island/cc/models/__init__.py
env_config = {}
env_singleton.env = TestingEnvironment(env_config)
# Without these imports pytests can't use fixtures,
# because they are not found
from tests.unit_tests.monkey_island.cc.mongomock_fixtures import * # noqa: F401,F403,E402

View File

@ -19,6 +19,18 @@ def config(monkeypatch):
return config
class MockClass:
pass
@pytest.fixture(scope="function", autouse=True)
def mock_port_in_env_singleton(monkeypatch):
mock_singleton = MockClass()
mock_singleton.env = MockClass()
mock_singleton.env.get_island_port = lambda: PORT
monkeypatch.setattr("monkey_island.cc.services.config.env_singleton", mock_singleton)
def test_set_server_ips_in_config_command_servers(config):
ConfigService.set_server_ips_in_config(config)
expected_config_command_servers = [f"{ip}:{PORT}" for ip in IPS]

View File

@ -166,8 +166,7 @@ IBM # unused variable (monkey/common/cloud/environment_names.py:11)
DigitalOcean # unused variable (monkey/common/cloud/environment_names.py:12)
_.aws_info # unused attribute (monkey/monkey_island/cc/environment/aws.py:13)
build_from_config_file_contents # unused method 'build_from_config_file_contents' (\monkey_island\setup\island_config_options.py:18)
fake_db_dir # unused function 'fake_db_dir' (monkey/tests/unit_tests/monkey_island/cc/setup/test_process_runner.py:10)
mock_port_in_env_singleton # monkey\tests\unit_tests\monkey_island\cc\services\test_config.py:26:
# these are not needed for it to work, but may be useful extra information to understand what's going on
WINDOWS_PBA_TYPE # unused variable (monkey/monkey_island/cc/resources/pba_file_upload.py:23)