diff 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
line wrap: on
line diff
--- a/src/test/helpers.py	Sat Jan 04 15:45:08 2014 +0100
+++ b/src/test/helpers.py	Sat Jan 04 15:46:30 2014 +0100
@@ -21,6 +21,7 @@
 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 @@
 
     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 @@
     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 @@
     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):