File: test_mongodb_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 (30 lines) | stat: -rw-r--r-- 842 bytes parent folder | download
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
import pytest
from clear import ClearTests
from common import CommonTests
from has import HasTests

from cachelib.mongodb import MongoDbCache


@pytest.fixture(autouse=True, params=[MongoDbCache])
def cache_factory(request):
    def _factory(self, *args, **kwargs):
        kwargs["db"] = "test-db"
        kwargs["collection"] = "test-collection"
        kwargs["key_prefix"] = "prefix"

        rc = request.param(*args, **kwargs)
        index_info = rc.client.index_information()
        all_keys = {
            subkey[0] for value in index_info.values() for subkey in value["key"]
        }
        assert "id" in all_keys, "Failed to create index on 'id' field"
        rc.clear()
        return rc

    if request.cls:
        request.cls.cache_factory = _factory


class TestMongoDbCache(CommonTests, ClearTests, HasTests):
    pass