diff --git a/aaq/tests/test_views.py b/aaq/tests/test_views.py index 890c841d..4c82deac 100644 --- a/aaq/tests/test_views.py +++ b/aaq/tests/test_views.py @@ -105,9 +105,11 @@ def test_get_first_page_view_gibberish_input(self): } @responses.activate - def test_get_first_page_view_blank(self): + def test_get_first_page_view_non_text(self): """ Check that we get an error message if a blank question is submitted + This happens when a voicenote or document is sent, or if an image is + sent without a text caption """ user = get_user_model().objects.create_user("test") self.client.force_authenticate(user) @@ -120,13 +122,12 @@ def test_get_first_page_view_blank(self): ) payload = json.dumps({"question": ""}) - # test string value, bad question, empty str, emoji, int response = self.client.post( self.url, data=payload, content_type="application/json" ) - assert response.json() == {"question": ["This field may not be blank."]} + assert response.json() == {"message": "Non-text Input Detected"} class AddFeedbackViewTests(APITestCase): diff --git a/aaq/views.py b/aaq/views.py index aa43ea3e..931588fe 100644 --- a/aaq/views.py +++ b/aaq/views.py @@ -22,9 +22,15 @@ @api_view(("POST",)) @renderer_classes((JSONRenderer,)) def get_first_page(request, *args, **kwargs): + print(request.data) + if request.data == {"question": ""}: + json_msg = { + "message": "Non-text Input Detected", + } + return Response(json_msg, status=status.HTTP_202_ACCEPTED) + serializer = InboundCheckSerializer(data=request.data) serializer.is_valid(raise_exception=True) - question = serializer.validated_data["question"] url = urllib.parse.urljoin(settings.AAQ_CORE_API_URL, "/inbound/check") payload = {"text_to_match": f"{question}"}