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:
parent
b370f284dd
commit
1eee4a779c
2 changed files with 43 additions and 6 deletions
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class SatMessageProtocolTest(unittest.TestCase):
|
|||
def setUp(self):
|
||||
self.host = helpers.FakeSAT()
|
||||
self.message = xmpp.SatMessageProtocol(self.host)
|
||||
self.message.parent = helpers.FakeParent()
|
||||
self.message.parent = helpers.FakeClient(self.host)
|
||||
|
||||
def test_onMessage(self):
|
||||
xml = """
|
||||
|
|
@ -64,7 +64,7 @@ class SatRosterProtocolTest(unittest.TestCase):
|
|||
def setUp(self):
|
||||
self.host = helpers.FakeSAT()
|
||||
self.roster = xmpp.SatRosterProtocol(self.host)
|
||||
self.roster.parent = helpers.FakeParent()
|
||||
self.roster.parent = helpers.FakeClient(self.host)
|
||||
|
||||
def test_onRosterSet(self):
|
||||
roster_item = RosterItem(helpers.TEST_JID)
|
||||
|
|
@ -82,7 +82,7 @@ class SatPresenceProtocolTest(unittest.TestCase):
|
|||
def setUp(self):
|
||||
self.host = helpers.FakeSAT()
|
||||
self.presence = xmpp.SatPresenceProtocol(self.host)
|
||||
self.presence.parent = helpers.FakeParent()
|
||||
self.presence.parent = helpers.FakeClient(self.host)
|
||||
|
||||
def test_availableReceived(self):
|
||||
self.host.bridge.expectCall("presenceUpdate", helpers.TEST_JID_STR, "xa", 15, {'default': "test status", 'fr': 'statut de test'}, helpers.TEST_PROFILE)
|
||||
|
|
|
|||
Loading…
Reference in a new issue