gajim-plural/test/unit/test_xmpp_transports_nb.py

79 lines
3.3 KiB
Python
Raw Normal View History

'''
Unit test for tranports classes.
'''
import unittest
import lib
lib.setup_env()
from common.xmpp import transports_nb
class TestModuleLevelFunctions(unittest.TestCase):
'''
Test class for functions defined at module level
'''
def test_urisplit(self):
def check_uri(uri, proto, host, port, path):
_proto, _host, _port, _path = transports_nb.urisplit(uri)
self.assertEqual(proto, _proto)
self.assertEqual(host, _host)
self.assertEqual(path, _path)
self.assertEqual(port, _port)
check_uri('http://httpcm.jabber.org:5280/webclient', proto='http',
host='httpcm.jabber.org', port=5280, path='/webclient')
check_uri('http://httpcm.jabber.org/webclient', proto='http',
host='httpcm.jabber.org', port=80, path='/webclient')
check_uri('https://httpcm.jabber.org/webclient', proto='https',
host='httpcm.jabber.org', port=443, path='/webclient')
def test_get_proxy_data_from_dict(self):
def check_dict(proxy_dict, host, port, user, passwd):
_host, _port, _user, _passwd = transports_nb.get_proxy_data_from_dict(
proxy_dict)
self.assertEqual(_host, host)
self.assertEqual(_port, port)
self.assertEqual(_user, user)
self.assertEqual(_passwd, passwd)
2013-01-01 19:44:25 +01:00
bosh_dict = {'bosh_content': 'text/xml; charset=utf-8',
'bosh_hold': 2,
'bosh_http_pipelining': False,
2013-01-01 19:44:25 +01:00
'bosh_uri': 'http://gajim.org:5280/http-bind',
'bosh_useproxy': False,
'bosh_wait': 30,
'bosh_wait_for_restart_response': False,
2013-01-01 19:44:25 +01:00
'host': '172.16.99.11',
'pass': 'pass',
'port': 3128,
2013-01-01 19:44:25 +01:00
'type': 'bosh',
'useauth': True,
2013-01-01 19:44:25 +01:00
'user': 'user'}
check_dict(bosh_dict, host='gajim.org', port=5280, user='user',
passwd='pass')
2013-01-01 19:44:25 +01:00
proxy_dict = {'bosh_content': 'text/xml; charset=utf-8',
'bosh_hold': 2,
'bosh_http_pipelining': False,
'bosh_port': 5280,
2013-01-01 19:44:25 +01:00
'bosh_uri': '',
'bosh_useproxy': True,
'bosh_wait': 30,
'bosh_wait_for_restart_response': False,
2013-01-01 19:44:25 +01:00
'host': '172.16.99.11',
'pass': 'pass',
'port': 3128,
'type': 'socks5',
'useauth': True,
2013-01-01 19:44:25 +01:00
'user': 'user'}
check_dict(proxy_dict, host='172.16.99.11', port=3128, user='user',
passwd='pass')
if __name__ == '__main__':
unittest.main()