def test_with_missing_mandatory_param(
        self, mock_get_collection_link, mock_get_cosmos_client
    ):

        invalid_feedback_body = get_string("fixtures/missing_is_useful.json")
        invalid_feedback_body = bytearray(invalid_feedback_body, "utf8")
        # Construct a mock HTTP request.
        req = func.HttpRequest(method="POST", body=invalid_feedback_body, url=f"/api/")

        # Call the main Azure Function entry point with the request.
        resp = main(req)

        # Check status code
        self.assertEqual(resp.status_code, 400)

        # Check content type
        headers = dict(resp.headers)
        self.assertEqual(headers["content-type"], "application/json")

        # Do some checking of the returned error message.
        error_msg = json.loads(resp.get_body().decode("utf-8"))
        self.assertEqual(error_msg["errors"][0]["error"], "Bad Request")
        self.assertEqual(
            error_msg["errors"][0]["error_values"][0]["JSON Validation Error"],
            "'is_useful' is a required property",
        )
 def test_with_4000_char_feedback(self):
     feedback_too_long = json.loads(
         get_string("fixtures/feedback_4000_chars.json"))
     try:
         validate_feedback(feedback_too_long)
     except ValidationError:
         self.fail("validate_feedback raised unexpected ValidationError")
    def test_with_valid_feedback(self):
        success = True
        valid_feedback = json.loads(get_string("fixtures/valid_feedback.json"))
        try:
            validate_feedback(valid_feedback)
        except ValidationError:
            success = False

        # Check we
        self.assertTrue(success, "Failed valid feedback")
    def test_with_valid_request(self, mock_get_collection_link, mock_get_cosmos_client):

        invalid_feedback_body = get_string("fixtures/valid_feedback.json")
        invalid_feedback_body = bytearray(invalid_feedback_body, "utf8")

        # Construct a mock HTTP request.
        req = func.HttpRequest(method="POST", body=invalid_feedback_body, url=f"/api/")

        # Call the main Azure Function entry point with the request.
        resp = main(req)

        # Check status code
        self.assertEqual(resp.status_code, 201)
 def test_with_too_long_feedback(self):
     feedback_too_long = json.loads(
         get_string("fixtures/feedback_4001_chars.json"))
     with self.assertRaises(ValidationError):
         validate_feedback(feedback_too_long)