File: test_uwsgi_cache.py

package info (click to toggle)
cachelib 0.13.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 428 kB
  • sloc: python: 1,555; makefile: 32; sh: 15
file content (44 lines) | stat: -rw-r--r-- 1,063 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pytest
from clear import ClearTests
from common import CommonTests
from has import HasTests

from cachelib import UWSGICache


class SillySerializer:
    """A pointless serializer only for testing"""

    def dumps(self, value):
        return repr(value).encode()

    def loads(self, bvalue):
        return eval(bvalue.decode())


class CustomCache(UWSGICache):
    """Our custom cache client with non-default serializer"""

    # overwrite serializer
    serializer = SillySerializer()

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)


@pytest.fixture(autouse=True, params=[UWSGICache, CustomCache])
def cache_factory(request):
    def _factory(self, *args, **kwargs):
        uwc = request.param(*args, **kwargs)
        uwc.clear()
        return uwc

    request.cls.cache_factory = _factory


class TestUwsgiCache(CommonTests, ClearTests, HasTests):
    pytest.importorskip(
        "uwsgi",
        reason="could not import 'uwsgi'. Make sure to "
        "run pytest under uwsgi for testing UWSGICache",
    )