1
0
bthlabs-jsonrpc/packages/bthlabs-jsonrpc-django/tests/serializer/test_DjangoJSONRPCSerializer.py
Tomek Wójcik c75ea4ea9d Initial public releases
* `bthlabs-jsonrpc-aiohttp` v1.0.0
* `bthlabs-jsonrpc-core` v1.0.0
* `bthlabs-jsonrpc-django` v1.0.0
2022-06-04 10:41:53 +02:00

33 lines
907 B
Python

# -*- coding: utf-8 -*-
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