tests: helpers improvments:

- FakeParent renamed FakeClient
    - added FakeRoster class, and an instance of it in FakeClient (FakeClient.roster)
    - b2s function to convert boolean value to strings used in bridge
    - some fake methods (FakeClient.send, FakeSat.delContact) to avoid exceptions
This commit is contained in:
Goffi 2013-09-29 16:29:36 +02:00
commit 1eee4a779c

View file

@ -19,12 +19,21 @@
import __builtin__
from twisted.words.protocols.jabber.jid import JID
from wokkel.xmppim import RosterItem
from sat.core.xmpp import SatRosterProtocol
from twisted.trial.unittest import FailTest
TEST_JID_STR = u"test@example.org/SàT"
TEST_JID = JID(u"test@example.org/SàT")
TEST_PROFILE = 'test_profile'
def b2s(value):
"""Convert a bool to a unicode string used in bridge
@param value: boolean value
@return: unicode conversion, according to bridge convention
"""
return u"True" if value else u"False"
class DifferentArgsException(FailTest):
pass
@ -38,6 +47,10 @@ class FakeSAT(object):
self.memory = FakeMemory()
self.trigger = FakeTriggerManager()
def delContact(self, to, profile_key):
#TODO
pass
class FakeBridge(object):
"""Class to simulate and test bridge calls"""
@ -86,11 +99,35 @@ class FakeTriggerManager(object):
"""We always return true to continue the action"""
return True
class FakeRosterProtocol(SatRosterProtocol):
class FakeParent(object):
def __init__(self):
def __init__(self, host, parent):
SatRosterProtocol.__init__(self, host)
self.parent = parent
self.addItem(TEST_JID)
def addItem(self, jid, *args, **kwargs):
if not args and not kwargs:
# defaults values setted for the tests only
kwargs["subscriptionTo"] = True
kwargs["subscriptionFrom"] = True
roster_item = RosterItem(jid, *args, **kwargs)
attrs = {'to': b2s(roster_item.subscriptionTo), 'from': b2s(roster_item.subscriptionFrom), 'ask': b2s(roster_item.pendingOut)}
if roster_item.name:
attrs['name'] = roster_item.name
self.host.bridge.expectCall("newContact", jid.full(), attrs, roster_item.groups, self.parent.profile)
self.onRosterSet(roster_item)
class FakeClient(object):
def __init__(self, host):
self.host = host
self.profile = 'test_profile'
self.jid = TEST_JID
self.roster = FakeRosterProtocol(host, self)
def send(self, obj):
pass
def _(text):