Mercurial > libervia-backend
comparison src/test/helpers.py @ 781:80ab2b58e205
test: added support of basic memory stuff in helpers.py
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 04 Jan 2014 15:46:30 +0100 |
parents | 9810f22ba733 |
children | 0e5807193721 |
comparison
equal
deleted
inserted
replaced
780:9810f22ba733 | 781:80ab2b58e205 |
---|---|
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from constants import Const | 21 from constants import Const |
22 from wokkel.xmppim import RosterItem | 22 from wokkel.xmppim import RosterItem |
23 from sat.core.xmpp import SatRosterProtocol | 23 from sat.core.xmpp import SatRosterProtocol |
24 from sat.memory.memory import Params | |
24 from twisted.trial.unittest import FailTest | 25 from twisted.trial.unittest import FailTest |
25 from twisted.trial import unittest | 26 from twisted.trial import unittest |
26 from xml.etree import cElementTree as etree | 27 from xml.etree import cElementTree as etree |
27 import re | 28 import re |
28 | 29 |
47 class FakeSAT(object): | 48 class FakeSAT(object): |
48 """Class to simulate a SAT instance""" | 49 """Class to simulate a SAT instance""" |
49 | 50 |
50 def __init__(self): | 51 def __init__(self): |
51 self.bridge = FakeBridge() | 52 self.bridge = FakeBridge() |
52 self.memory = FakeMemory() | 53 self.memory = FakeMemory(self) |
53 self.trigger = FakeTriggerManager() | 54 self.trigger = FakeTriggerManager() |
54 | 55 |
55 def delContact(self, to, profile_key): | 56 def delContact(self, to, profile_key): |
56 #TODO | 57 #TODO |
58 pass | |
59 | |
60 def registerCallback(self, callback, *args, **kwargs): | |
61 pass | |
62 | |
63 def registerNewAccountCB(self, data, profile): | |
64 pass | |
65 | |
66 def sendMessage(self, to_s, msg, subject=None, mess_type='auto', extra={}, profile_key='@NONE@'): | |
57 pass | 67 pass |
58 | 68 |
59 | 69 |
60 class FakeBridge(object): | 70 class FakeBridge(object): |
61 """Class to simulate and test bridge calls""" | 71 """Class to simulate and test bridge calls""" |
73 setattr(self, name, checkCall) | 83 setattr(self, name, checkCall) |
74 | 84 |
75 def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False): | 85 def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False): |
76 pass | 86 pass |
77 | 87 |
88 def addSignal(self, name, int_suffix, signature): | |
89 pass | |
90 | |
91 | |
92 class FakeParams(Params): | |
93 """Class to simulate and test params object. The methods of Params that could | |
94 not be run (for example those using the storage attribute must be overwritten | |
95 by a naive simulation of what they should do.""" | |
96 | |
97 def __init__(self, host, storage): | |
98 Params.__init__(self, host, storage) | |
99 self.values = {} # naive simulation of values storage | |
100 | |
101 def setParam(self, name, value, category, security_limit=-1, profile_key='@NONE@'): | |
102 self.values.setdefault(category, {}) | |
103 self.values[category][name] = value | |
104 | |
105 def getParamA(self, name, category, attr="value", profile_key='@NONE@'): | |
106 return self.values[category][name] | |
107 | |
108 | |
78 class FakeMemory(object): | 109 class FakeMemory(object): |
79 """Class to simulate and test memory object""" | 110 """Class to simulate and test memory object""" |
80 | 111 |
112 def __init__(self, host): | |
113 self.host = host | |
114 self.params = FakeParams(host, None) | |
115 self.init() | |
116 | |
117 def init(self): | |
118 """Tests that manipulate params and/or entities should | |
119 re-initialise the memory first to not fake the result.""" | |
120 self.params.load_default_params() | |
121 self.params.values.clear() | |
122 self.entities_data = {} # naive simulation of entities | |
123 | |
81 def getProfileName(self, profile_key): | 124 def getProfileName(self, profile_key): |
82 return profile_key | 125 return profile_key |
83 | 126 |
84 def addToHistory(self, from_jid, to_jid, message, _type='chat', extra=None, timestamp=None, profile="@NONE@"): | 127 def addToHistory(self, from_jid, to_jid, message, _type='chat', extra=None, timestamp=None, profile="@NONE@"): |
85 pass | 128 pass |
94 pass | 137 pass |
95 | 138 |
96 def delWaitingSub(self, contact_jid, profile_key): | 139 def delWaitingSub(self, contact_jid, profile_key): |
97 pass | 140 pass |
98 | 141 |
99 def updateParams(self, xml): | 142 def updateParams(self, xml, security_limit=Const.SECURITY_LIMIT, app=''): |
100 pass | 143 self.params.updateParams(xml, security_limit, app) |
144 | |
145 def setParam(self, name, value, category, security_limit=-1, profile_key='@NONE@'): | |
146 self.params.setParam(name, value, category, security_limit, profile_key) | |
147 | |
148 def getParamA(self, name, category, attr="value", profile_key='@NONE@'): | |
149 return self.params.getParamA(name, category, attr, profile_key) | |
150 | |
151 def updateEntityData(self, entity_jid, key, value, profile_key): | |
152 self.entities_data.setdefault(entity_jid, {}) | |
153 self.entities_data[entity_jid][key] = value | |
154 | |
155 def getEntityData(self, entity_jid, keys, profile_key): | |
156 result = {} | |
157 for key in keys: | |
158 result[key] = self.entities_data[entity_jid][key] | |
159 return result | |
160 | |
101 | 161 |
102 class FakeTriggerManager(object): | 162 class FakeTriggerManager(object): |
103 | 163 |
104 def add(self, point_name, callback): | 164 def add(self, point_name, callback): |
105 pass | 165 pass |