test: added some tests for Memory

This commit is contained in:
souliane 2014-01-04 17:16:40 +01:00
commit 6007937962

View file

@ -24,7 +24,9 @@ from sat.core.xmpp import SatRosterProtocol
from sat.memory.memory import Params
from twisted.trial.unittest import FailTest
from twisted.trial import unittest
from twisted.internet import defer
from xml.etree import cElementTree as etree
from sat.core import exceptions
import re
@ -96,14 +98,28 @@ class FakeParams(Params):
def __init__(self, host, storage):
Params.__init__(self, host, storage)
self.values = {} # naive simulation of values storage
self.params = {} # 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
profile = self.getProfileName(profile_key)
self.params.setdefault(profile, {})
self.params[profile_key][(category, name)] = value
def getParamA(self, name, category, attr="value", profile_key='@NONE@'):
return self.values[category][name]
profile = self.getProfileName(profile_key)
return self.params[profile][(category, name)]
def getProfileName(self, profile_key, return_profile_keys=False):
if profile_key == '@DEFAULT@':
return Const.TEST_PROFILE
elif profile_key == '@NONE@':
raise exceptions.ProfileNotSetError
else:
return profile_key
def loadIndParams(self, profile, cache=None):
self.params[profile] = {}
return defer.succeed(None)
class FakeMemory(object):
@ -118,11 +134,11 @@ class FakeMemory(object):
"""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.params.params.clear()
self.entities_data = {} # naive simulation of entities
def getProfileName(self, profile_key):
return profile_key
def getProfileName(self, profile_key, return_profile_keys=False):
return self.params.getProfileName(profile_key, return_profile_keys)
def addToHistory(self, from_jid, to_jid, message, _type='chat', extra=None, timestamp=None, profile="@NONE@"):
pass
@ -139,9 +155,16 @@ class FakeMemory(object):
def delWaitingSub(self, contact_jid, profile_key):
pass
def getParams(self, security_limit=Const.NO_SECURITY_LIMIT, app='', profile_key='@NONE@'):
"""profile_key is set to @DEFAULT@ to avoid specifying it always"""
return self.params.getParams(security_limit, app, profile_key='@DEFAULT@')
def updateParams(self, xml, security_limit=Const.SECURITY_LIMIT, app=''):
self.params.updateParams(xml, security_limit, app)
def paramsRegisterApp(self, xml, security_limit=Const.NO_SECURITY_LIMIT, app=''):
return self.params.paramsRegisterApp(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)