fix for obsolete pydantic parameters
This commit is contained in:
29
tests/test_fastapi/test_schema_not_allowed_params.py
Normal file
29
tests/test_fastapi/test_schema_not_allowed_params.py
Normal file
@ -0,0 +1,29 @@
|
||||
import databases
|
||||
import sqlalchemy
|
||||
|
||||
import ormar
|
||||
|
||||
DATABASE_URL = "sqlite:///db.sqlite"
|
||||
database = databases.Database(DATABASE_URL)
|
||||
metadata = sqlalchemy.MetaData()
|
||||
|
||||
|
||||
class BaseMeta(ormar.ModelMeta):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
|
||||
class Author(ormar.Model):
|
||||
class Meta(BaseMeta):
|
||||
tablename = "authors"
|
||||
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
name: str = ormar.String(max_length=100)
|
||||
contents: str = ormar.Text()
|
||||
|
||||
|
||||
def test_schema_not_allowed():
|
||||
schema = Author.schema()
|
||||
for field_schema in schema.get("properties").values():
|
||||
for key in field_schema.keys():
|
||||
assert "_" not in key, f"Found illegal field in openapi schema: {key}"
|
||||
@ -595,3 +595,9 @@ async def test_get_and_first():
|
||||
|
||||
user = await User2.objects.first()
|
||||
assert user.name == "Jane"
|
||||
|
||||
|
||||
def test_constraints():
|
||||
with pytest.raises(pydantic.ValidationError) as e:
|
||||
Product(name="T-Shirt", rating=50, in_stock=True)
|
||||
assert "ensure this value is less than or equal to 5" in str(e.value)
|
||||
|
||||
Reference in New Issue
Block a user