Skip to content

Commit

Permalink
(PC-23699)[API] test: update serialization decorator test
Browse files Browse the repository at this point in the history
I specifically commit that separately because I am not 100% confident this actually tests the same thing
  • Loading branch information
lixxday committed Aug 11, 2023
1 parent a4ade6c commit e525416
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions api/tests/serialization/serialization_decorator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from unittest.mock import patch

from flask.blueprints import Blueprint
import pytest

from pcapi.models import api_errors
from pcapi.routes.serialization import BaseModel
from pcapi.serialization.decorator import spectree_serialize

Expand Down Expand Up @@ -42,6 +40,12 @@ def spectree_post_test_endpoint():
endpoint_method()


@test_blueprint.route("/validation", methods=["POST"])
@spectree_serialize(on_success_status=206)
def spectree_empty_form_validation(form: TestQueryModel):
return


@test_bookings_blueprint.route("/bookings", methods=["GET"])
@spectree_serialize(on_success_status=204)
def spectree_get_booking_test_endpoint():
Expand Down Expand Up @@ -143,12 +147,12 @@ def test_post_with_content_type_with_invalid_body_throw_error(self, client, capl
)
assert response.status_code == 400

def test_http_form_validation(self):
@spectree_serialize(response_model=TestResponseModel, on_success_status=206)
def mock_func(form: TestQueryModel):
return

with pytest.raises(api_errors.ApiErrors) as exc_info:
mock_func(form=None)
def test_http_form_validation(self, client):
response = client.post(
"/test-blueprint/validation", form=None, headers={"Content-Type": "application/x-www-form-urlencoded"}
)

assert exc_info.value.errors == {"compulsory_int_query": "field required"}
assert response.status_code == 400
assert response.json == {
"compulsory_int_query": ["Ce champ est obligatoire"],
}

0 comments on commit e525416

Please sign in to comment.