forked from p15670423/monkey
island, tests: Handle exceptions when getting deployment type from file and add related tests
This commit is contained in:
parent
9fd6ea9598
commit
90c6392e16
|
@ -75,8 +75,13 @@ class VersionUpdateService:
|
||||||
def get_deployment_from_file(file_path: str) -> str:
|
def get_deployment_from_file(file_path: str) -> str:
|
||||||
deployment = "unknown"
|
deployment = "unknown"
|
||||||
|
|
||||||
with open(file_path, "r") as deployment_info_file:
|
try:
|
||||||
deployment_info = json.load(deployment_info_file)
|
with open(file_path, "r") as deployment_info_file:
|
||||||
deployment = deployment_info["deployment"]
|
deployment_info = json.load(deployment_info_file)
|
||||||
|
deployment = deployment_info["deployment"]
|
||||||
|
except Exception as ex:
|
||||||
|
logger.debug(
|
||||||
|
f"Couldn't get deployment info from {str(file_path)}. Exception: {str(ex)}."
|
||||||
|
)
|
||||||
|
|
||||||
return deployment
|
return deployment
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
develop
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"tnemyolped": "develop"
|
||||||
|
}
|
|
@ -10,7 +10,42 @@ def deployment_info_file_path(data_for_tests_dir):
|
||||||
return os.path.join(data_for_tests_dir, "deployment.json")
|
return os.path.join(data_for_tests_dir, "deployment.json")
|
||||||
|
|
||||||
|
|
||||||
def test_get_deployment_field(deployment_info_file_path, monkeypatch):
|
@pytest.fixture
|
||||||
|
def ghost_file():
|
||||||
|
return "ghost_file"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def key_error_deployment_info_file_path(data_for_tests_dir):
|
||||||
|
return os.path.join(data_for_tests_dir, "deployment_key_error.json")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def flawed_deployment_info_file_path(data_for_tests_dir):
|
||||||
|
return os.path.join(data_for_tests_dir, "deployment_flawed")
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_deployment_field_from_file(deployment_info_file_path, monkeypatch):
|
||||||
monkeypatch.setattr(os.path, "join", lambda *args: 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):
|
||||||
|
monkeypatch.setattr(os.path, "join", lambda *args: ghost_file)
|
||||||
|
deployment = VersionUpdateService().get_deployment_from_file(ghost_file)
|
||||||
|
assert deployment == "unknown"
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_deployment_field_key_error(key_error_deployment_info_file_path, monkeypatch):
|
||||||
|
monkeypatch.setattr(os.path, "join", lambda *args: key_error_deployment_info_file_path)
|
||||||
|
deployment = VersionUpdateService().get_deployment_from_file(
|
||||||
|
key_error_deployment_info_file_path
|
||||||
|
)
|
||||||
|
assert deployment == "unknown"
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_deployment_field_from_flawed_json_file(flawed_deployment_info_file_path, monkeypatch):
|
||||||
|
monkeypatch.setattr(os.path, "join", lambda *args: flawed_deployment_info_file_path)
|
||||||
|
deployment = VersionUpdateService().get_deployment_from_file(flawed_deployment_info_file_path)
|
||||||
|
assert deployment == "unknown"
|
||||||
|
|
Loading…
Reference in New Issue