From 67f2f57e95e11ffc126229dabe46895a7893d25d Mon Sep 17 00:00:00 2001 From: TShapinsky Date: Tue, 7 Jan 2025 14:28:52 -0700 Subject: [PATCH] fix api tests, import changes, point id changes --- .github/workflows/ci.yml | 6 +++--- alfalfa_web/server/api-v2.js | 2 +- alfalfa_web/server/api.js | 6 ++++-- alfalfa_worker/jobs/openstudio/__init__.py | 4 ++-- alfalfa_worker/jobs/openstudio/step_run.py | 2 +- tests/api/conftest.py | 7 +++++++ tests/api/test_point.py | 10 +++++++--- tests/api/test_run.py | 2 +- tests/worker/conftest.py | 2 -- tests/worker/test_dispatcher.py | 8 ++++---- 10 files changed, 30 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e6f7c9b..805778eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: - name: Install Python uses: actions/setup-python@v5 with: - python-version: "3.8" + python-version: "3.11" - name: Run pre-commit uses: pre-commit/action@v3.0.1 @@ -39,7 +39,7 @@ jobs: - name: Install Python uses: actions/setup-python@v5 with: - python-version: "3.8" + python-version: "3.11" - name: Install poetry uses: abatilo/actions-poetry@v3 @@ -117,7 +117,7 @@ jobs: - name: Install Python uses: actions/setup-python@v5 with: - python-version: "3.8" + python-version: "3.11" - name: Install poetry uses: abatilo/actions-poetry@v3 diff --git a/alfalfa_web/server/api-v2.js b/alfalfa_web/server/api-v2.js index 3b48e98e..8d542166 100644 --- a/alfalfa_web/server/api-v2.js +++ b/alfalfa_web/server/api-v2.js @@ -106,7 +106,7 @@ router.param("pointId", (req, res, next, id) => { const error = validate( { id }, { - id: "required|uuid" + id: "required|string" } ); if (error) return res.status(400).json({ message: error }); diff --git a/alfalfa_web/server/api.js b/alfalfa_web/server/api.js index 63aa6537..7986bf81 100644 --- a/alfalfa_web/server/api.js +++ b/alfalfa_web/server/api.js @@ -203,7 +203,7 @@ class AlfalfaAPI { const { startDatetime, endDatetime, timescale, realtime, externalClock } = data; - const job = `alfalfa_worker.jobs.${sim_type === "MODELICA" ? "modelica" : "openstudio"}.StepRun`; + const job = `alfalfa_worker.jobs.${sim_type === "MODELICA" ? "modelica" : "openstudio"}.step_run.StepRun`; const params = { run_id: run.ref_id, start_datetime: startDatetime, @@ -303,7 +303,9 @@ class AlfalfaAPI { createRunFromModel = async (model) => { const runId = uuidv1(); - const job = `alfalfa_worker.jobs.${model.model_name.endsWith(".fmu") ? "modelica" : "openstudio"}.CreateRun`; + const job = `alfalfa_worker.jobs.${ + model.model_name.endsWith(".fmu") ? "modelica" : "openstudio" + }.create_run.CreateRun`; const params = { model_id: model.ref_id, run_id: runId diff --git a/alfalfa_worker/jobs/openstudio/__init__.py b/alfalfa_worker/jobs/openstudio/__init__.py index 40b629c8..b61fc6df 100644 --- a/alfalfa_worker/jobs/openstudio/__init__.py +++ b/alfalfa_worker/jobs/openstudio/__init__.py @@ -2,5 +2,5 @@ from pathlib import Path lib_dir = Path(os.path.dirname(__file__), 'lib') -from .create_run import CreateRun -from .step_run import StepRun +# from .create_run import CreateRun +# from .step_run import StepRun diff --git a/alfalfa_worker/jobs/openstudio/step_run.py b/alfalfa_worker/jobs/openstudio/step_run.py index bedeaffb..3fe73000 100644 --- a/alfalfa_worker/jobs/openstudio/step_run.py +++ b/alfalfa_worker/jobs/openstudio/step_run.py @@ -9,7 +9,7 @@ from alfalfa_worker.jobs.openstudio.lib.variables import Variables from alfalfa_worker.jobs.step_run_process import StepRunProcess from alfalfa_worker.lib.enums import PointType -from alfalfa_worker.lib.job import ( +from alfalfa_worker.lib.job_exception import ( JobException, JobExceptionExternalProcess, JobExceptionSimulation diff --git a/tests/api/conftest.py b/tests/api/conftest.py index 80a11a02..4c673351 100644 --- a/tests/api/conftest.py +++ b/tests/api/conftest.py @@ -1,4 +1,5 @@ import os +from datetime import datetime from pathlib import Path import pytest @@ -35,3 +36,9 @@ def run_id(alfalfa_client: AlfalfaClient, model_path): alfalfa_client.stop(run_id) except AlfalfaAPIException: pass + + +@pytest.fixture +def started_run_id(alfalfa_client: AlfalfaClient, run_id): + alfalfa_client.start(run_id, datetime(2020, 1, 1, 0, 0), datetime(2020, 1, 2, 0, 0), external_clock=True) + yield run_id diff --git a/tests/api/test_point.py b/tests/api/test_point.py index c4f57b1e..69f9c397 100644 --- a/tests/api/test_point.py +++ b/tests/api/test_point.py @@ -40,6 +40,7 @@ def test_point_retrieval(base_url, run_id, alfalfa_client): } response = requests.post(f"{base_url}/runs/{run_id}/points", json=request_body) + response.raise_for_status() assert response.status_code == 200 response_body = response.json() assert "payload" in response_body @@ -72,6 +73,7 @@ def test_point_retrieval(base_url, run_id, alfalfa_client): for point in outputs + bidirectionals: response = requests.get(f"{base_url}/runs/{run_id}/points/{point['id']}") + response.raise_for_status() assert response.status_code == 200 response_body = response.json() assert "payload" in response_body @@ -138,7 +140,8 @@ def test_point_retrieval(base_url, run_id, alfalfa_client): @pytest.mark.api -def test_point_writes(base_url, run_id): +def test_point_writes(base_url, started_run_id): + run_id = started_run_id # get all points response = requests.get(f"{base_url}/runs/{run_id}/points") @@ -179,7 +182,7 @@ def test_point_writes(base_url, run_id): request_body = { 'value': "hello" } - response = requests.put(f"{base_url}/runs/{run_id}/points/{inputs[0]['id']}", json=request_body) + response = requests.put(f"{base_url}/runs/{run_id}/points/{bidirectionals[0]['id']}", json=request_body) assert response.status_code == 400 response_body = response.json() @@ -208,7 +211,8 @@ def test_point_writes(base_url, run_id): @pytest.mark.api -def test_point_not_found(base_url, run_id): +def test_point_not_found(base_url, started_run_id): + run_id = started_run_id # request point which does not exist response = requests.get(f"{base_url}/runs/{run_id}/points/{uuid4()}") diff --git a/tests/api/test_run.py b/tests/api/test_run.py index ecddfc67..7aa0862f 100644 --- a/tests/api/test_run.py +++ b/tests/api/test_run.py @@ -189,7 +189,7 @@ def test_run_start_stop(base_url, run_id): assert "status" in payload status = payload["status"] - if status == "STOPPING": + if status.lower() == "stopping" or status.lower() == "complete": break if time.time() > timeout: pytest.fail("Timed out waiting for run to stop") diff --git a/tests/worker/conftest.py b/tests/worker/conftest.py index 041cb88b..ff58a46c 100644 --- a/tests/worker/conftest.py +++ b/tests/worker/conftest.py @@ -4,8 +4,6 @@ @pytest.fixture(autouse=True) def env_setup(monkeypatch): - monkeypatch.setenv('WEB_REGISTRY_URI', '313781303390.dkr.ecr.us-east-1.amazonaws.com/queue/web') - monkeypatch.setenv('WORKER_REGISTRY_URI', '313781303390.dkr.ecr.us-east-1.amazonaws.com/queue/worker') monkeypatch.setenv('AWS_ACCESS_KEY_ID', 'user') monkeypatch.setenv('AWS_SECRET_ACCESS_KEY', 'password') monkeypatch.setenv('NODE_ENV', 'production') diff --git a/tests/worker/test_dispatcher.py b/tests/worker/test_dispatcher.py index fb2bf792..4bd70df4 100644 --- a/tests/worker/test_dispatcher.py +++ b/tests/worker/test_dispatcher.py @@ -1,6 +1,6 @@ from alfalfa_worker.dispatcher import Dispatcher from alfalfa_worker.jobs.openstudio.create_run import CreateRun -from alfalfa_worker.jobs.openstudio.step_run import StepRun +# from alfalfa_worker.jobs.openstudio.step_run import StepRun from alfalfa_worker.lib.job import JobStatus from tests.worker.jobs.basic_mock_job import BasicMockJob from tests.worker.utilities import wait_for_job_status @@ -11,13 +11,13 @@ def test_valid_init(dispatcher): def test_get_builtin_job(dispatcher): - create_run_job = dispatcher.find_class('alfalfa_worker.jobs.openstudio.CreateRun') + create_run_job = dispatcher.find_class('alfalfa_worker.jobs.openstudio.create_run.CreateRun') assert create_run_job == CreateRun def test_get_from_job_get_path(dispatcher): - step_run_job = dispatcher.find_class(StepRun.job_path()) - assert step_run_job == StepRun + create_run_job = dispatcher.find_class(CreateRun.job_path()) + assert create_run_job == CreateRun def test_test_job_create_with_params(dispatcher):