diff --git a/missioncontrol/tests/conftest.py b/missioncontrol/tests/conftest.py index 30425be..1115c9e 100644 --- a/missioncontrol/tests/conftest.py +++ b/missioncontrol/tests/conftest.py @@ -113,6 +113,16 @@ def simple_pass(simple_sat, simple_gs): "end_time": "2018-11-25T01:00:00.000000Z", } +@pytest.fixture +def simple_pass2(simple_sat, simple_gs): + return { + "uuid": "9f6236cc-6bce-4e78-b8fa-8de758c20d74", + "satellite": simple_sat["hwid"], + "groundstation": simple_gs["hwid"], + "start_time": "2019-11-25T00:00:00.000000Z", + "end_time": "2019-11-25T01:00:00.000000Z", + } + @pytest.fixture def simple_task_run(simple_pass, simple_task_stack): return { diff --git a/missioncontrol/tests/test_pass_task_run.py b/missioncontrol/tests/test_pass_task_run.py index 3209de3..406c4de 100644 --- a/missioncontrol/tests/test_pass_task_run.py +++ b/missioncontrol/tests/test_pass_task_run.py @@ -1,4 +1,6 @@ import json +from uuid import uuid4 + import pytest @@ -33,3 +35,39 @@ def create_asset(asset_type, asset): assert response.status_code == 201, f"status code {response.status_code} not 201. Data: {response.get_data()}" assert response.json == expected + +@pytest.mark.django_db +def test_pass_task_run_search(test_client, simple_task_stack, simple_pass, simple_pass2, + simple_sat, simple_gs, simple_task_run, some_uuid, another_uuid, yet_another_uuid): + def create_asset(asset_type, asset): + asset_hwid = asset["hwid"] + response = test_client.put( + f"/api/v0/{asset_type}s/{asset_hwid}/", json=asset) + + diff_uuid = uuid4() + + create_asset('satellite', simple_sat) + create_asset('groundstation', simple_gs) + response = test_client.put(f'/api/v0/passes/{some_uuid}/', json=simple_pass) + assert response.status_code == 201, f"status code {response.status_code} not 201. Data: {response.get_data()}" + + response = test_client.put(f'/api/v0/passes/{diff_uuid}/', json=simple_pass2) + assert response.status_code == 201, f"status code {response.status_code} not 201. Data: {response.get_data()}" + + + response = test_client.put(f'/api/v0/task-stacks/{yet_another_uuid}/', json=simple_task_stack) + assert response.status_code == 201, f"status code {response.status_code} not 201. Data: {response.get_data()}" + + simple_task_run['task_stack'] = yet_another_uuid + # Create a task_run + response = test_client.put(f"/api/v0/passes/{some_uuid}/task-runs/{another_uuid}/", json=simple_task_run) + assert response.status_code == 201, response.get_data() + + response = test_client.get(f'/api/v0/passes/{some_uuid}/task-runs/') + assert response.status_code == 200, response.get_data() + assert response.json != [] + + response = test_client.get(f'/api/v0/passes/{diff_uuid}/task-runs/') + assert response.status_code == 200, response.get_data() + assert response.json == [] + diff --git a/missioncontrol/v0/pass_task_run.py b/missioncontrol/v0/pass_task_run.py index fcbb9c7..3f0d82f 100644 --- a/missioncontrol/v0/pass_task_run.py +++ b/missioncontrol/v0/pass_task_run.py @@ -4,7 +4,7 @@ def search(pass_uuid=None): - return [x.to_dict() for x in TaskRun.objects.all()] + return [x.to_dict() for x in TaskRun.objects.filter(task_pass=pass_uuid)] def get(pass_uuid=None, uuid=None): result = TaskRun.objects.get(uuid=uuid, task_pass=pass_uuid)