forked from youknowone/ring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_control.py
49 lines (33 loc) · 1.05 KB
/
test_control.py
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
import ring
import pytest
class Object(object):
def __init__(self, **kwargs):
self._data = kwargs
def __getattr__(self, key):
if key in self._data:
return self._data[key]
return getattr(super(Object, self), key)
def test_action_dict():
cache = {}
class User(Object):
def __ring_key__(self):
return 'User{self.user_id}'.format(self=self)
@ring.dict(cache)
def data(self):
return self._data.copy()
u1 = User(user_id=42, name='User 1')
data = u1.data()
assert data
u1.data.run(action='delete')
data_or_none = u1.data.get()
assert data_or_none is None
u1 = User(user_id=42, name='User 1')
updated_data = u1.data.run(action="update")
assert updated_data == data
key = u1.data.run('key')
direct_data = cache[key]
assert data == direct_data
with pytest.raises(TypeError):
key = u1.data.run('key', name='User 1') # too many args
with pytest.raises(AttributeError):
u1.data.run('fjeiso', name='')