island, tests: Modify function to get deployment type with file path as input and modify related tests

This commit is contained in:
Shreya Malviya 2021-09-14 14:02:24 +05:30
parent c1fc56d4ce
commit 9fd6ea9598
2 changed files with 12 additions and 10 deletions

View File

@ -1,7 +1,6 @@
import json
import logging
import os
from typing import Optional
import requests
@ -42,8 +41,10 @@ class VersionUpdateService:
Checks if newer monkey version is available
:return: False if not, version in string format ('1.6.2') otherwise
"""
deployment_info_file_path = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc", "deployment.json")
url = VersionUpdateService.VERSION_SERVER_CHECK_NEW_URL % (
VersionUpdateService.get_deployment_file(),
VersionUpdateService.get_deployment_from_file(deployment_info_file_path),
get_version(),
)
@ -63,17 +64,18 @@ class VersionUpdateService:
@staticmethod
def get_download_link():
deployment_info_file_path = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc", "deployment.json")
return VersionUpdateService.VERSION_SERVER_DOWNLOAD_URL % (
VersionUpdateService.get_deployment_file(),
VersionUpdateService.get_deployment_from_file(deployment_info_file_path),
get_version(),
)
@staticmethod
def get_deployment_file() -> Optional[str]:
def get_deployment_from_file(file_path: str) -> str:
deployment = "unknown"
deployment_info_file_path = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc", "deployment.json")
with open(deployment_info_file_path, "r") as deployment_info_file:
with open(file_path, "r") as deployment_info_file:
deployment_info = json.load(deployment_info_file)
deployment = deployment_info["deployment"]

View File

@ -6,11 +6,11 @@ from monkey_island.cc.services.version_update import VersionUpdateService
@pytest.fixture
def deployment_file(data_for_tests_dir):
def deployment_info_file_path(data_for_tests_dir):
return os.path.join(data_for_tests_dir, "deployment.json")
def test_get_deployment_field(deployment_file, monkeypatch):
monkeypatch.setattr(os.path, "join", lambda *args: deployment_file)
deployment = VersionUpdateService().get_deployment_file()
def test_get_deployment_field(deployment_info_file_path, monkeypatch):
monkeypatch.setattr(os.path, "join", lambda *args: deployment_info_file_path)
deployment = VersionUpdateService().get_deployment_from_file(deployment_info_file_path)
assert deployment == "develop"