diff --git a/tests/acceptance/test_serializers.py b/tests/acceptance/test_serializers.py index 694f0a8b..a19ae7f4 100644 --- a/tests/acceptance/test_serializers.py +++ b/tests/acceptance/test_serializers.py @@ -2,6 +2,7 @@ import random from typing import Any +import msgpack import pytest from marshmallow import Schema, fields, post_load @@ -13,6 +14,7 @@ from aiocache.serializers import ( BaseSerializer, JsonSerializer, + MsgPackSerializer, NullSerializer, PickleSerializer, StringSerializer, @@ -141,6 +143,28 @@ async def test_multi_set_multi_get_types(self, cache, obj): assert await cache.multi_get([Keys.KEY]) == [pickle.loads(pickle.dumps(obj))] +class TestMsgPackSerializer: + TYPES = (1, 2.0, "hi", True, ["1", 1], {"key": "value"}) + + @pytest.mark.parametrize("obj", TYPES) + async def test_set_get_types(self, cache, obj): + cache.serializer = MsgPackSerializer() + assert await cache.set(Keys.KEY, obj) is True + assert await cache.get(Keys.KEY) == msgpack.loads(msgpack.dumps(obj)) + + @pytest.mark.parametrize("obj", TYPES) + async def test_add_get_types(self, cache, obj): + cache.serializer = MsgPackSerializer() + assert await cache.add(Keys.KEY, obj) is True + assert await cache.get(Keys.KEY) == msgpack.loads(msgpack.dumps(obj)) + + @pytest.mark.parametrize("obj", TYPES) + async def test_multi_set_multi_get_types(self, cache, obj): + cache.serializer = MsgPackSerializer() + assert await cache.multi_set([(Keys.KEY, obj)]) is True + assert await cache.multi_get([Keys.KEY]) == [msgpack.loads(msgpack.dumps(obj))] + + class TestAltSerializers: async def test_get_set_alt_serializer_functions(self, cache): cache.serializer = StringSerializer()