Skip to content

Commit

Permalink
[ADD] Tests for #1
Browse files Browse the repository at this point in the history
  • Loading branch information
acwazz committed Aug 5, 2022
1 parent c324099 commit fc1a04b
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/test_response_model_compatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import string
from fastapi import FastAPI, APIRouter
from fastapi.testclient import TestClient
from fastapi_responseschema import SchemaAPIRoute, wrap_app_responses
from pydantic import BaseModel
from .common import SimpleResponseSchema


class RModel(BaseModel):
id: str
name: str


class Route(SchemaAPIRoute):
response_schema = SimpleResponseSchema


app = FastAPI()


wrap_app_responses(app, Route)


@app.get("/model-exclude", response_model=RModel, response_model_exclude={"name"})
def wrapped_call_first():
return {"id": 1, "name": "hiddenfield"}


@app.get("/model-filters", response_model=RModel)
def wrapped_call_first():
return {"id": 1, "name": "hiddenfield", "hidden": True}


client = TestClient(app)


def test_response_model_exclude_preserved():
r = client.get("/model-exclude")
resp = r.json()
assert not resp.get("error")
assert resp.get("data").get("id") == 1
assert not resp.get("data").get("name")


def test_response_model_filters():
r = client.get("/model-filters")
resp = r.json()
assert not resp.get("error")
assert resp.get("data").get("id") == 1
assert resp.get("data").get("name")
assert not resp.get("data").get("hidden")

0 comments on commit fc1a04b

Please sign in to comment.