Beispiel #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
    }
Beispiel #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'
    }
Beispiel #3
0
 def serialize(self, entity: GenericIdModel) -> Dict:
     """Convert pydantic model to dict"""
     return model_to_primitive(entity, without_id=True)
Beispiel #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_
Beispiel #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_