gajim-plural/test/unit/test_protocol_caps.py

56 lines
1.6 KiB
Python
Raw Normal View History

'''
Tests for caps network coding
'''
2018-07-22 19:12:52 +02:00
import unittest
2018-07-22 19:12:52 +02:00
from unittest.mock import MagicMock
import nbxmpp
import lib
lib.setup_env()
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
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)
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()
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
def test_capsPresenceCB(self):
2013-04-07 23:41:15 +02:00
fjid = "user@server.com/a"
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)
if __name__ == '__main__':
unittest.main()