test: added support of basic memory stuff in helpers.py

This commit is contained in:
souliane 2014-01-04 15:46:30 +01:00
commit 8307896c4f

View file

@ -21,6 +21,7 @@ from sat.core.i18n import _
from constants import Const
from wokkel.xmppim import RosterItem
from sat.core.xmpp import SatRosterProtocol
from sat.memory.memory import Params
from twisted.trial.unittest import FailTest
from twisted.trial import unittest
from xml.etree import cElementTree as etree
@ -49,13 +50,22 @@ class FakeSAT(object):
def __init__(self):
self.bridge = FakeBridge()
self.memory = FakeMemory()
self.memory = FakeMemory(self)
self.trigger = FakeTriggerManager()
def delContact(self, to, profile_key):
#TODO
pass
def registerCallback(self, callback, *args, **kwargs):
pass
def registerNewAccountCB(self, data, profile):
pass
def sendMessage(self, to_s, msg, subject=None, mess_type='auto', extra={}, profile_key='@NONE@'):
pass
class FakeBridge(object):
"""Class to simulate and test bridge calls"""
@ -75,9 +85,42 @@ class FakeBridge(object):
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False):
pass
def addSignal(self, name, int_suffix, signature):
pass
class FakeParams(Params):
"""Class to simulate and test params object. The methods of Params that could
not be run (for example those using the storage attribute must be overwritten
by a naive simulation of what they should do."""
def __init__(self, host, storage):
Params.__init__(self, host, storage)
self.values = {} # naive simulation of values storage
def setParam(self, name, value, category, security_limit=-1, profile_key='@NONE@'):
self.values.setdefault(category, {})
self.values[category][name] = value
def getParamA(self, name, category, attr="value", profile_key='@NONE@'):
return self.values[category][name]
class FakeMemory(object):
"""Class to simulate and test memory object"""
def __init__(self, host):
self.host = host
self.params = FakeParams(host, None)
self.init()
def init(self):
"""Tests that manipulate params and/or entities should
re-initialise the memory first to not fake the result."""
self.params.load_default_params()
self.params.values.clear()
self.entities_data = {} # naive simulation of entities
def getProfileName(self, profile_key):
return profile_key
@ -96,8 +139,25 @@ class FakeMemory(object):
def delWaitingSub(self, contact_jid, profile_key):
pass
def updateParams(self, xml):
pass
def updateParams(self, xml, security_limit=Const.SECURITY_LIMIT, app=''):
self.params.updateParams(xml, security_limit, app)
def setParam(self, name, value, category, security_limit=-1, profile_key='@NONE@'):
self.params.setParam(name, value, category, security_limit, profile_key)
def getParamA(self, name, category, attr="value", profile_key='@NONE@'):
return self.params.getParamA(name, category, attr, profile_key)
def updateEntityData(self, entity_jid, key, value, profile_key):
self.entities_data.setdefault(entity_jid, {})
self.entities_data[entity_jid][key] = value
def getEntityData(self, entity_jid, keys, profile_key):
result = {}
for key in keys:
result[key] = self.entities_data[entity_jid][key]
return result
class FakeTriggerManager(object):