From 9f2c179c5826dce1fa8b343bb8b39641ac7fe9f9 Mon Sep 17 00:00:00 2001 From: Tushar <30565750+tushar5526@users.noreply.github.com> Date: Mon, 15 Jan 2024 02:51:56 +0530 Subject: [PATCH] feat: add in suggestions from review --- .github/workflows/test.yml | 17 ++++++++++++++--- server/utils.py | 4 +--- tests/test_utils.py | 32 +++++++++++++++++++++----------- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 449b648..d64e884 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,11 +17,22 @@ jobs: with: python-version: 3.11 # Choose your Python version - - name: Install dependencies + - name: Cache Python dependencies + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + + - name: Install main dependencies run: | python -m pip install --upgrade pip - pip install -r requirements.txt - pip install -r requirements-dev.txt + pip install -r requirements.txt + + - name: Install development dependencies + run: pip install -r requirements-dev.txt - name: Run pytest run: python -m pytest -vvv diff --git a/server/utils.py b/server/utils.py index d976b90..b6ad45e 100644 --- a/server/utils.py +++ b/server/utils.py @@ -45,9 +45,7 @@ class ComposeHelper: def __init__(self, compose_file_location: str, load_compose_file=True): self._compose_file_location = compose_file_location - self._compose = None - if load_compose_file: - self._compose = load_yaml_file(self._compose_file_location) + self._compose = load_yaml_file(self._compose_file_location) if load_compose_file else None def start_services( self, nginx_port: str, conf_file_path: str, deployment_namespace: str diff --git a/tests/test_utils.py b/tests/test_utils.py index 154d214..9809092 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -38,17 +38,27 @@ def test_start_services(compose_helper, mocker): # - No ports # - No container_name # - Restart should be present in each service - for service in compose_helper._compose["services"]: - if ( - "ports" in compose_helper._compose["services"][service] - and service != f"nginx_{deployment_namespace}" - ): - assert False, "Ports mapping present in processed compose file" - if "container_name" in compose_helper._compose["services"][service]: - assert False, "Container Name present in processed compose file" - if "restart" not in compose_helper._compose["services"][service]: - assert False, "Restart clause missing in processed compose file" - assert compose_helper._compose["services"][service]["restart"] == "always" + services = compose_helper._compose["services"] + + # Deployment Proxy should be added in compose file + is_deployment_proxy_service = False + + for service_name, service_config in services.items(): + is_deployment_proxy_service = is_deployment_proxy_service or service_name == f"nginx_{deployment_namespace}" + + assert "ports" not in service_config or is_deployment_proxy_service, \ + f"Ports mapping should not be present in {service_name}" + + assert "container_name" not in service_config, \ + f"Container Name should not be present in {service_name}" + + assert "restart" in service_config, \ + f"Restart clause missing in {service_name}" + + assert service_config["restart"] == "always", \ + f"Incorrect restart policy in {service_name}" + + assert is_deployment_proxy_service, "Deployment (Nginx) Proxy is missing in processed services" mocked_run.assert_called_once_with( ["docker-compose", "up", "-d", "--build"], check=True, cwd=pathlib.Path(".")