1
0
bthlabs-jsonrpc/packages/bthlabs-jsonrpc-django/tests/serializer/test_DjangoJSONRPCSerializer.py
2024-01-15 20:20:10 +00:00

34 lines
922 B
Python

# -*- coding: utf-8 -*-
# type: ignore
import pytest
from bthlabs_jsonrpc_django import serializer
from testing.factories import ThingFactory
from testing.models import Thing
@pytest.mark.django_db
def test_serialize_value_query_set():
# Given
things = [ThingFactory() for _ in range(0, 3)]
query_set = Thing.objects.\
filter(pk__in=[thing.pk for thing in things]).\
order_by('pk')
the_serializer = serializer.DjangoJSONRPCSerializer('spam')
# When
result = the_serializer.serialize_value(query_set)
# Then
assert isinstance(result, list)
assert len(result) == 3
expected_serialized_thing = things[0].to_rpc()
expected_serialized_thing.update({
'created_at': expected_serialized_thing['created_at'].isoformat(),
'modified_at': expected_serialized_thing['modified_at'].isoformat(),
})
assert result[0] == expected_serialized_thing