forked from p34709852/monkey
tests: Move monkeypatch statements to fixtures in test_version_update.py
This commit is contained in:
parent
90c6392e16
commit
686f65e4f4
|
@ -6,46 +6,50 @@ from monkey_island.cc.services.version_update import VersionUpdateService
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def deployment_info_file_path(data_for_tests_dir):
|
def deployment_info_file_path(monkeypatch, data_for_tests_dir):
|
||||||
return os.path.join(data_for_tests_dir, "deployment.json")
|
path = os.path.join(data_for_tests_dir, "deployment.json")
|
||||||
|
monkeypatch.setattr(os.path, "join", lambda *args: path)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def ghost_file():
|
def ghost_file(monkeypatch):
|
||||||
return "ghost_file"
|
path = "ghost_file"
|
||||||
|
monkeypatch.setattr(os.path, "join", lambda *args: path)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def key_error_deployment_info_file_path(data_for_tests_dir):
|
def key_error_deployment_info_file_path(monkeypatch, data_for_tests_dir):
|
||||||
return os.path.join(data_for_tests_dir, "deployment_key_error.json")
|
path = os.path.join(data_for_tests_dir, "deployment_key_error.json")
|
||||||
|
monkeypatch.setattr(os.path, "join", lambda *args: path)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def flawed_deployment_info_file_path(data_for_tests_dir):
|
def flawed_deployment_info_file_path(monkeypatch, data_for_tests_dir):
|
||||||
return os.path.join(data_for_tests_dir, "deployment_flawed")
|
path = os.path.join(data_for_tests_dir, "deployment_flawed")
|
||||||
|
monkeypatch.setattr(os.path, "join", lambda *args: path)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
def test_get_deployment_field_from_file(deployment_info_file_path, monkeypatch):
|
def test_get_deployment_field_from_file(deployment_info_file_path):
|
||||||
monkeypatch.setattr(os.path, "join", lambda *args: deployment_info_file_path)
|
|
||||||
deployment = VersionUpdateService().get_deployment_from_file(deployment_info_file_path)
|
deployment = VersionUpdateService().get_deployment_from_file(deployment_info_file_path)
|
||||||
assert deployment == "develop"
|
assert deployment == "develop"
|
||||||
|
|
||||||
|
|
||||||
def test_get_deployment_field_from_nonexistent_file(ghost_file, monkeypatch):
|
def test_get_deployment_field_from_nonexistent_file(ghost_file):
|
||||||
monkeypatch.setattr(os.path, "join", lambda *args: ghost_file)
|
|
||||||
deployment = VersionUpdateService().get_deployment_from_file(ghost_file)
|
deployment = VersionUpdateService().get_deployment_from_file(ghost_file)
|
||||||
assert deployment == "unknown"
|
assert deployment == "unknown"
|
||||||
|
|
||||||
|
|
||||||
def test_get_deployment_field_key_error(key_error_deployment_info_file_path, monkeypatch):
|
def test_get_deployment_field_key_error(key_error_deployment_info_file_path):
|
||||||
monkeypatch.setattr(os.path, "join", lambda *args: key_error_deployment_info_file_path)
|
|
||||||
deployment = VersionUpdateService().get_deployment_from_file(
|
deployment = VersionUpdateService().get_deployment_from_file(
|
||||||
key_error_deployment_info_file_path
|
key_error_deployment_info_file_path
|
||||||
)
|
)
|
||||||
assert deployment == "unknown"
|
assert deployment == "unknown"
|
||||||
|
|
||||||
|
|
||||||
def test_get_deployment_field_from_flawed_json_file(flawed_deployment_info_file_path, monkeypatch):
|
def test_get_deployment_field_from_flawed_json_file(flawed_deployment_info_file_path):
|
||||||
monkeypatch.setattr(os.path, "join", lambda *args: flawed_deployment_info_file_path)
|
|
||||||
deployment = VersionUpdateService().get_deployment_from_file(flawed_deployment_info_file_path)
|
deployment = VersionUpdateService().get_deployment_from_file(flawed_deployment_info_file_path)
|
||||||
assert deployment == "unknown"
|
assert deployment == "unknown"
|
||||||
|
|
Loading…
Reference in New Issue