sqlmodel-fix/tests/test_deprecations.py
Sebastián Ramírez fa2f178b8a
Add support for Pydantic v2 (while keeping support for v1 if v2 is not available), including initial work by AntonDeMeester (#722)
Co-authored-by: Mohamed Farahat <farahats9@yahoo.com>
Co-authored-by: Stefan Borer <stefan.borer@gmail.com>
Co-authored-by: Peter Landry <peter.landry@gmail.com>
Co-authored-by: Anton De Meester <antondemeester+github@gmail.com>
2023-12-04 15:42:39 +01:00

31 lines
690 B
Python

import pytest
from sqlmodel import SQLModel
class Item(SQLModel):
name: str
class SubItem(Item):
password: str
def test_deprecated_from_orm_inheritance():
new_item = SubItem(name="Hello", password="secret")
with pytest.warns(DeprecationWarning):
item = Item.from_orm(new_item)
assert item.name == "Hello"
assert not hasattr(item, "password")
def test_deprecated_parse_obj():
with pytest.warns(DeprecationWarning):
item = Item.parse_obj({"name": "Hello"})
assert item.name == "Hello"
def test_deprecated_dict():
with pytest.warns(DeprecationWarning):
data = Item(name="Hello").dict()
assert data == {"name": "Hello"}