-
Notifications
You must be signed in to change notification settings - Fork 4
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
aaq urgency check endpoint V2 #616
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a28044a
aaq urgency check endpoint
Hlamallama f30a407
aaq urgency check endpoint
Hlamallama 1464ec4
aaq urgency check endpoint
Hlamallama 02fbae6
aaq urgency check endpoint
Hlamallama 3048457
aaq urgency check endpoint
Hlamallama ee5474e
aaq urgency check endpoint
Hlamallama a68a93d
aaq urgency check endpoint
Hlamallama 48bc4d8
aaq search endpoint
Hlamallama 40aa6c8
aaq search endpoint
Hlamallama File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | ||
|
@@ -376,12 +376,14 @@ def test_search(self): | |
response = self.client.post( | ||
self.url, data=payload, content_type="application/json" | ||
) | ||
[request] = responses.calls | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertIn("message", response.data) | ||
self.assertIn("body", response.data) | ||
self.assertIn("query_id", response.data) | ||
self.assertIn("feedback_secret_key", response.data) | ||
self.assertEqual(json.loads(request.request.body), json.loads(payload)) | ||
|
||
assert response.json() == { | ||
"message": "*0* - Example content title\n*1* -" | ||
|
@@ -527,3 +529,90 @@ 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 is_urgent True | ||
""" | ||
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_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" | ||
) | ||
[request] = responses.calls | ||
|
||
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", | ||
], | ||
} | ||
self.assertEqual(json.loads(request.request.body), json.loads(payload)) | ||
|
||
@responses.activate | ||
def test_urgency_check_not_urgent(self): | ||
""" | ||
Test that we can get is_urgent False | ||
""" | ||
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."]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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 comment
The 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