File: test_dict_store.py

package info (click to toggle)
cachy 0.3.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 320 kB
  • sloc: python: 1,308; sh: 6; makefile: 4
file content (55 lines) | stat: -rw-r--r-- 1,443 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-

from unittest import TestCase
from flexmock import flexmock

from cachy.stores import DictStore


class DictStoreTestCase(TestCase):

    def test_items_can_be_set_and_retrieved(self):
        store = DictStore()
        store.put('foo', 'bar', 10)

        self.assertEqual('bar', store.get('foo'))

    def test_store_item_forever_properly_stores_in_dict(self):
        mock = flexmock(DictStore())
        mock.should_receive('put').once().with_args('foo', 'bar', 0)
        mock.forever('foo', 'bar')

    def test_values_can_be_incremented(self):
        store = DictStore()
        store.put('foo', 1, 10)
        store.increment('foo')

        self.assertEqual(2, store.get('foo'))

    def test_values_can_be_decremented(self):
        store = DictStore()
        store.put('foo', 1, 10)
        store.decrement('foo')

        self.assertEqual(0, store.get('foo'))

    def test_values_can_be_removed(self):
        store = DictStore()
        store.put('foo', 'bar', 10)
        store.forget('foo')

        self.assertIsNone(store.get('foo'))

    def test_items_can_be_flushed(self):
        store = DictStore()
        store.put('foo', 'bar', 10)
        store.put('baz', 'boom', 10)
        store.flush()

        self.assertIsNone(store.get('foo'))
        self.assertIsNone(store.get('baz'))

    def test_cache_key(self):
        store = DictStore()

        self.assertEqual('', store.get_prefix())