def test_model_to_primitive_with_python_primitives(model: MyModel) -> None: dict_ = model_to_primitive(model, keep_python_primitives=True) assert dict_ == { "id": model.id, "title": model.title, "created": model.created }
def test_model_to_primitive(model: MyModel) -> None: dict_ = model_to_primitive(model) assert dict_ == { "id": model.id, "title": model.title, "created": '2020-01-04T00:00:00' }
def serialize(self, entity: GenericIdModel) -> Dict: """Convert pydantic model to dict""" return model_to_primitive(entity, without_id=True)
def test_model_to_primitive_excludes_fields_from_list(model: MyModel) -> None: dict_ = model_to_primitive(model, exclude=["title", "created"]) assert "title" not in dict_ and "created" not in dict_
def test_model_to_primitive_excludes_id(model: MyModel) -> None: dict_ = model_to_primitive(model, without_id=True) assert "id" not in dict_