Skip to content

Commit

Permalink
Fix task-run search returning all task-runs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Psykar committed Mar 4, 2019
1 parent 46bcfdb commit d14c8e5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
10 changes: 10 additions & 0 deletions missioncontrol/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
38 changes: 38 additions & 0 deletions missioncontrol/tests/test_pass_task_run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
from uuid import uuid4

import pytest


Expand Down Expand Up @@ -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 == []

2 changes: 1 addition & 1 deletion missioncontrol/v0/pass_task_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d14c8e5

Please sign in to comment.