2009-12-10 20:06:46 +01:00
|
|
|
'''
|
|
|
|
Tests for caps network coding
|
|
|
|
'''
|
2018-07-22 19:12:52 +02:00
|
|
|
|
2009-12-10 20:06:46 +01:00
|
|
|
import unittest
|
2018-07-22 19:12:52 +02:00
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
|
|
import nbxmpp
|
2009-12-10 20:06:46 +01:00
|
|
|
|
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
|
2018-07-22 19:12:52 +02:00
|
|
|
from gajim.common.modules.caps import Caps
|
2009-12-10 20:06:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestConnectionCaps(unittest.TestCase):
|
|
|
|
|
2013-04-07 23:41:15 +02:00
|
|
|
def setUp(self):
|
2018-07-22 19:12:52 +02:00
|
|
|
app.contacts.add_account('account')
|
|
|
|
contact = app.contacts.create_contact(
|
|
|
|
'user@server.com', 'account', resource='a')
|
|
|
|
app.contacts.add_contact('account', contact)
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.nec = nec.NetworkEventsController()
|
2018-07-22 19:12:52 +02:00
|
|
|
app.ged.register_event_handler(
|
|
|
|
'caps-presence-received', ged.GUI2,
|
2013-04-07 23:41:15 +02:00
|
|
|
self._nec_caps_presence_received)
|
|
|
|
|
2018-07-22 19:12:52 +02:00
|
|
|
self.module = Caps(MagicMock())
|
|
|
|
self.module._account = 'account'
|
|
|
|
self.module._capscache = MagicMock()
|
|
|
|
|
2018-11-17 11:19:16 +01:00
|
|
|
def tearDown(self):
|
|
|
|
app.contacts.remove_account('account')
|
|
|
|
|
2013-04-07 23:41:15 +02:00
|
|
|
def _nec_caps_presence_received(self, obj):
|
2018-07-22 19:12:52 +02:00
|
|
|
self.assertTrue(
|
|
|
|
isinstance(obj.client_caps, caps_cache.ClientCaps),
|
|
|
|
msg="On receive of valid caps, ClientCaps should be returned")
|
2013-04-07 23:41:15 +02:00
|
|
|
|
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"
|
|
|
|
|
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))
|
2018-07-22 19:12:52 +02:00
|
|
|
self.module._presence_received(None, msg)
|
|
|
|
|
2009-12-10 20:06:46 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|