forked from sonic-net/sonic-host-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock_connector.py
45 lines (33 loc) · 1.13 KB
/
mock_connector.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
class MockConnector(object):
STATE_DB = None
data = {}
def __init__(self, host):
pass
def connect(self, db_id):
pass
def get(self, db_id, key, field):
return MockConnector.data[key][field]
def set(self, db_id, key, field, value):
if key not in MockConnector.data:
MockConnector.data[key] = {}
MockConnector.data[key][field] = value
def hmset(self, db_id, key, fvs):
if key not in MockConnector.data:
MockConnector.data[key] = {}
for field, value in fvs.items():
MockConnector.data[key][field] = value
def keys(self, db_id, pattern):
match = pattern.split('*')[0]
ret = []
for key in MockConnector.data.keys():
if match in key:
ret.append(key)
return ret
def get_all(self, db_id, key):
return MockConnector.data[key]
def delete(self, db_id, key):
return MockConnector.data.delete(key)
def delete_all_by_pattern(self, db_id, pattern):
keys = self.keys(db_id, pattern)
for key in keys:
self.delete(db_id, key)