Skip to content

Commit

Permalink
aaq urgency check endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Hlamallama committed Aug 6, 2024
1 parent f30a407 commit 1464ec4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
13 changes: 13 additions & 0 deletions aaq/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
21 changes: 19 additions & 2 deletions aaq/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions aaq/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 1464ec4

Please sign in to comment.