2009-12-10 20:06:46 +01:00
|
|
|
'''
|
|
|
|
Tests for caps network coding
|
|
|
|
'''
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
import lib
|
|
|
|
lib.setup_env()
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2017-08-12 02:39:55 +02:00
|
|
|
from gajim.common import nec
|
|
|
|
from gajim.common import ged
|
|
|
|
from gajim.common import caps_cache
|
|
|
|
from gajim.common.connection_handlers import ConnectionHandlers
|
|
|
|
from gajim.common.protocol import caps
|
|
|
|
from gajim.common.contacts import Contact
|
|
|
|
from gajim.common.connection_handlers_events import CapsPresenceReceivedEvent
|
2009-12-10 20:06:46 +01:00
|
|
|
|
|
|
|
from mock import Mock
|
|
|
|
|
2013-04-07 23:41:15 +02:00
|
|
|
import nbxmpp
|
2009-12-10 20:06:46 +01:00
|
|
|
|
2013-04-07 23:41:15 +02:00
|
|
|
class TestableConnectionCaps(ConnectionHandlers, caps.ConnectionCaps):
|
2009-12-10 20:06:46 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self, *args, **kwargs):
|
2013-04-07 23:41:15 +02:00
|
|
|
self.name = 'account'
|
2010-02-08 15:08:40 +01:00
|
|
|
self._mocked_contacts = {}
|
|
|
|
caps.ConnectionCaps.__init__(self, *args, **kwargs)
|
2009-12-10 20:06:46 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def _get_contact_or_gc_contact_for_jid(self, jid):
|
|
|
|
"""
|
|
|
|
Overwrite to decouple form contact handling
|
|
|
|
"""
|
|
|
|
if jid not in self._mocked_contacts:
|
|
|
|
self._mocked_contacts[jid] = Mock(realClass=Contact)
|
|
|
|
self._mocked_contacts[jid].jid = jid
|
|
|
|
return self._mocked_contacts[jid]
|
2009-12-10 20:06:46 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def discoverInfo(self, *args, **kwargs):
|
|
|
|
pass
|
2009-12-10 20:06:46 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def get_mocked_contact_for_jid(self, jid):
|
|
|
|
return self._mocked_contacts[jid]
|
2009-12-10 20:06:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestConnectionCaps(unittest.TestCase):
|
|
|
|
|
2013-04-07 23:41:15 +02:00
|
|
|
def setUp(self):
|
2017-08-13 13:18:56 +02:00
|
|
|
app.nec = nec.NetworkEventsController()
|
|
|
|
app.ged.register_event_handler('caps-presence-received', ged.GUI2,
|
2013-04-07 23:41:15 +02:00
|
|
|
self._nec_caps_presence_received)
|
|
|
|
|
|
|
|
def _nec_caps_presence_received(self, obj):
|
|
|
|
self.assertFalse(isinstance(obj.client_caps, caps_cache.NullClientCaps),
|
|
|
|
msg="On receive of proper caps, we must not use the fallback")
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def test_capsPresenceCB(self):
|
2013-04-07 23:41:15 +02:00
|
|
|
fjid = "user@server.com/a"
|
|
|
|
|
|
|
|
connection_caps = TestableConnectionCaps("account", Mock(),
|
|
|
|
caps_cache.create_suitable_client_caps)
|
|
|
|
|
|
|
|
contact = connection_caps._get_contact_or_gc_contact_for_jid(fjid)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
xml = """<presence from='user@server.com/a' to='%s' id='123'>
|
2013-04-07 23:41:15 +02:00
|
|
|
<c node='http://gajim.org' ver='pRCD6cgQ4SDqNMCjdhRV6TECx5o='
|
|
|
|
hash='sha-1' xmlns='http://jabber.org/protocol/caps'/>
|
|
|
|
</presence>
|
|
|
|
""" % (fjid)
|
|
|
|
msg = nbxmpp.protocol.Presence(node=nbxmpp.simplexml.XML2Node(xml))
|
|
|
|
connection_caps._presenceCB(None, msg)
|
2009-12-10 20:06:46 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|