tests.test_expiration()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 7
rs 9.4285
cc 3
1
import hug
2
from hug_store_redis import RedisStore
3
import pytest
4
import time
5
import uuid
6
7
8
def test_store(connection):
9
    store = RedisStore(connection, namespace='test')
10
    key = str(uuid.uuid4())
11
    data = {'important': True}
12
13
    # Key doesn't exist
14
    assert not store.exists(key)
15
16
    # Create
17
    store.set(key, data)
18
    assert store.exists(key)
19
20
    # Read
21
    assert store.get(key) == data
22
23
    # Update
24
    data['important'] = False
25
    store.set(key, data)
26
    assert store.get(key) == data
27
28
    # Delete
29
    store.delete(key)
30
    assert not store.exists(key)
31
32
33
def test_get_unknown_key(connection):
34
    store = RedisStore(connection, namespace='test')
35
36
    with pytest.raises(hug.exceptions.StoreKeyNotFound):
37
        store.get('this-does-not-exist')
38
39
40
def test_expiration(connection):
41
    store = RedisStore(connection, namespace='test', expiration=1)
42
    key = str(uuid.uuid4())
43
    store.set(key, True)
44
    assert store.exists(key)
45
    time.sleep(1)
46
    assert not store.exists(key)
47