Esempio n. 1
0
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
    }
Esempio n. 2
0
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'
    }
Esempio n. 3
0
 def serialize(self, entity: GenericIdModel) -> Dict:
     """Convert pydantic model to dict"""
     return model_to_primitive(entity, without_id=True)
Esempio n. 4
0
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_
Esempio n. 5
0
def test_model_to_primitive_excludes_id(model: MyModel) -> None:
    dict_ = model_to_primitive(model, without_id=True)
    assert "id" not in dict_