File: test_serializers.py

package info (click to toggle)
django-redis 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 476 kB
  • sloc: python: 2,904; makefile: 6; sh: 6
file content (26 lines) | stat: -rw-r--r-- 922 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import pickle

import pytest
from django.core.exceptions import ImproperlyConfigured

from django_redis.serializers.pickle import PickleSerializer


class TestPickleSerializer:
    def test_invalid_pickle_version_provided(self):
        with pytest.raises(
            ImproperlyConfigured, match="PICKLE_VERSION value must be an integer"
        ):
            PickleSerializer({"PICKLE_VERSION": "not-an-integer"})

    def test_setup_pickle_version_not_explicitly_specified(self):
        serializer = PickleSerializer({})
        assert serializer._pickle_version == pickle.DEFAULT_PROTOCOL

    def test_setup_pickle_version_too_high(self):
        with pytest.raises(
            ImproperlyConfigured,
            match=f"PICKLE_VERSION can't be higher than pickle.HIGHEST_PROTOCOL:"
            f" {pickle.HIGHEST_PROTOCOL}",
        ):
            PickleSerializer({"PICKLE_VERSION": pickle.HIGHEST_PROTOCOL + 1})