Skip to content

Commit

Permalink
fix api tests, import changes, point id changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TShapinsky committed Jan 7, 2025
1 parent 9b56504 commit 67f2f57
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion alfalfa_web/server/api-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
6 changes: 4 additions & 2 deletions alfalfa_web/server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions alfalfa_worker/jobs/openstudio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion alfalfa_worker/jobs/openstudio/step_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/api/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from datetime import datetime
from pathlib import Path

import pytest
Expand Down Expand Up @@ -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
10 changes: 7 additions & 3 deletions tests/api/test_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()}")

Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 0 additions & 2 deletions tests/worker/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 4 additions & 4 deletions tests/worker/test_dispatcher.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down

0 comments on commit 67f2f57

Please sign in to comment.