diff --git a/aaq/tests/helpers.py b/aaq/tests/helpers.py index 8d43abc8..4bdb9256 100644 --- a/aaq/tests/helpers.py +++ b/aaq/tests/helpers.py @@ -123,14 +123,27 @@ def post_search_return_empty(self, request): class FakeAaqUdV2Api: def post_urgency_detect_return_true(self, request): resp_body = { + "details": { + "0": {"distance": 0.1, "urgency_rule": "Blurry vision and dizziness"}, + "1": {"distance": 0.2, "urgency_rule": "Nausea that lasts for 3 days"}, + }, "is_urgent": True, + "matched_rules": [ + "Blurry vision and dizziness", + "Nausea that lasts for 3 days", + ], } return (200, {}, json.dumps(resp_body)) def post_urgency_detect_return_false(self, request): resp_body = { + "details": { + "0": {"distance": 0.1, "urgency_rule": "Baby okay"}, + "1": {"distance": 0.2, "urgency_rule": "Baby healthy"}, + }, "is_urgent": False, + "matched_rules": ["Baby okay", "Baby healthy"], } return (200, {}, json.dumps(resp_body)) diff --git a/aaq/tests/test_views.py b/aaq/tests/test_views.py index a3bc0256..1564e996 100644 --- a/aaq/tests/test_views.py +++ b/aaq/tests/test_views.py @@ -554,7 +554,17 @@ def test_urgency_check_urgent(self): ) assert response.status_code == 200 - assert response.json() == {"is_urgent": True} + assert response.json() == { + "details": { + "0": {"distance": 0.1, "urgency_rule": "Blurry vision and dizziness"}, + "1": {"distance": 0.2, "urgency_rule": "Nausea that lasts for 3 days"}, + }, + "is_urgent": True, + "matched_rules": [ + "Blurry vision and dizziness", + "Nausea that lasts for 3 days", + ], + } @responses.activate def test_urgency_check_not_urgent(self): @@ -578,7 +588,14 @@ def test_urgency_check_not_urgent(self): ) assert response.status_code == 200 - assert response.json() == {"is_urgent": False} + assert response.json() == { + "details": { + "0": {"distance": 0.1, "urgency_rule": "Baby okay"}, + "1": {"distance": 0.2, "urgency_rule": "Baby healthy"}, + }, + "is_urgent": False, + "matched_rules": ["Baby okay", "Baby healthy"], + } @responses.activate def test_urgency_check_invalid(self): diff --git a/aaq/views.py b/aaq/views.py index 3f430f56..0c19b125 100644 --- a/aaq/views.py +++ b/aaq/views.py @@ -238,6 +238,5 @@ def check_urgency_v2(request, *args, **kwargs): } response = requests.request("POST", url, json=message_text, headers=headers) - is_urgent = {"is_urgent": response.json()["is_urgent"]} - return Response(is_urgent, status=status.HTTP_200_OK) + return Response(response.json(), status=status.HTTP_200_OK)