Skip to content

Commit

Permalink
Merge pull request #54 from n0nSmoker/test/add.new.test.of.serialize_…
Browse files Browse the repository at this point in the history
…model.method

New test for the serialize_model method
  • Loading branch information
n0nSmoker authored Jul 18, 2024
2 parents d807833 + 858d5ef commit 826dce2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FlatModel(Base, SerializerMixin):
time = sa.Column(sa.Time, default=TIME)
bool = sa.Column(sa.Boolean, default=True)
null = sa.Column(sa.String)
uuid = sa.Column(UUID(as_uuid=True), default=lambda: uuid4())
uuid = sa.Column(UUID(as_uuid=True), default=uuid4)
list = [1, "test_string", 0.9, {"key": 123, "key2": 23423}, {"key": 234}]
set = {1, 2, "test_string"}
dict = dict(key=123, key2={"key": 12})
Expand Down
30 changes: 30 additions & 0 deletions tests/test_serializer_serialize_model__function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest

from tests.models import FlatModel, NestedModel


@pytest.fixture
def test_model(get_instance):
model = get_instance(NestedModel)
model.model = get_instance(FlatModel)
return model


# TODO: Add more checks of model fields
@pytest.mark.parametrize(
"only, expected",
[
# FIXME: last `key` ignored and all the rist is returned is it expected?
# (("model.list.key",), {"model": {"list": [{"key": 123}]}}),
(("dict.key",), {"dict": {"key": 123}}),
(("bool",), {"bool": False}),
(("null",), {"null": None}), # FIXME: Invalid JSON
],
)
def test_serializer_serialize_model__fork_success(
get_serializer, test_model, only, expected
):
serializer = get_serializer()
serializer.schema.update(only=only)
result = serializer.serialize_model(test_model)
assert result == expected

0 comments on commit 826dce2

Please sign in to comment.