-
Notifications
You must be signed in to change notification settings - Fork 4
aaq urgency check endpoint V2 #616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
a28044a
f30a407
1464ec4
02fbae6
3048457
ee5474e
a68a93d
48bc4d8
40aa6c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
from rest_framework import status | ||
from rest_framework.test import APITestCase | ||
|
||
from .helpers import FakeAaqApi, FakeAaqCoreApi, FakeAaqUdApi, FakeTask | ||
from .helpers import FakeAaqApi, FakeAaqCoreApi, FakeAaqUdApi, FakeAaqUdV2Api, FakeTask | ||
|
||
|
||
class GetFirstPageViewTests(APITestCase): | ||
|
@@ -527,3 +527,88 @@ def test_response_feedback_invalid_feedback_text_view(self): | |
assert response.json() == { | ||
"feedback_sentiment": ['"test" is not a valid choice.'] | ||
} | ||
|
||
|
||
class CheckUrgencyV2ViewTests(APITestCase): | ||
url = reverse("aaq-check-urgency-v2") | ||
|
||
@responses.activate | ||
def test_urgency_check_urgent(self): | ||
""" | ||
Test that we can get an urgency score of 1.0 | ||
""" | ||
user = get_user_model().objects.create_user("test") | ||
self.client.force_authenticate(user) | ||
fakeAaqUdV2Api = FakeAaqUdV2Api() | ||
responses.add_callback( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you validate the request payload that is sent to the AAQ endpoint please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i have this test test_urgency_check_invalid to check if the payload is valid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is the payload to our endpoint, I'm talking about the payload e send to the aaq endpoint |
||
responses.POST, | ||
"http://aaq_v2/urgency-check-v2", | ||
callback=fakeAaqUdV2Api.post_urgency_detect_return_true, | ||
content_type="application/json", | ||
) | ||
|
||
payload = json.dumps({"message_text": "I am pregnant and out of breath"}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you remove the .dumps here, you can remove the 2 .loads() calls on line 571 |
||
|
||
response = self.client.post( | ||
self.url, data=payload, content_type="application/json" | ||
) | ||
|
||
assert response.status_code == 200 | ||
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): | ||
""" | ||
Test that we can get an urgency score of 0.0 | ||
""" | ||
user = get_user_model().objects.create_user("test") | ||
self.client.force_authenticate(user) | ||
fakeAaqUdV2Api = FakeAaqUdV2Api() | ||
responses.add_callback( | ||
responses.POST, | ||
"http://aaq_v2/urgency-check-v2", | ||
callback=fakeAaqUdV2Api.post_urgency_detect_return_false, | ||
content_type="application/json", | ||
) | ||
|
||
payload = json.dumps({"message_text": "I am fine"}) | ||
|
||
response = self.client.post( | ||
self.url, data=payload, content_type="application/json" | ||
) | ||
|
||
assert response.status_code == 200 | ||
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): | ||
""" | ||
Test that we can get a field required message | ||
""" | ||
user = get_user_model().objects.create_user("test") | ||
self.client.force_authenticate(user) | ||
payload = json.dumps({}) | ||
|
||
response = self.client.post( | ||
self.url, data=payload, content_type="application/json" | ||
) | ||
|
||
assert response.status_code == 400 | ||
assert response.json() == {"message_text": ["This field is required."]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update these docstrings to match the true/false