2009-11-05 09:06:46 +01:00
|
|
|
'''
|
|
|
|
Unit test for tranports classes.
|
|
|
|
'''
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
import lib
|
|
|
|
lib.setup_env()
|
|
|
|
|
|
|
|
from common.xmpp import transports_nb
|
|
|
|
|
|
|
|
|
|
|
|
class TestModuleLevelFunctions(unittest.TestCase):
|
2010-02-08 15:08:40 +01:00
|
|
|
'''
|
|
|
|
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)
|
2009-11-05 09:06:46 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
check_uri('http://httpcm.jabber.org:5280/webclient', proto='http',
|
|
|
|
host='httpcm.jabber.org', port=5280, path='/webclient')
|
2009-11-05 09:06:46 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
check_uri('http://httpcm.jabber.org/webclient', proto='http',
|
|
|
|
host='httpcm.jabber.org', port=80, path='/webclient')
|
2009-11-05 09:06:46 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
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',
|
2010-02-08 15:08:40 +01:00
|
|
|
'bosh_hold': 2,
|
|
|
|
'bosh_http_pipelining': False,
|
2013-01-01 19:44:25 +01:00
|
|
|
'bosh_uri': 'http://gajim.org:5280/http-bind',
|
2010-02-08 15:08:40 +01:00
|
|
|
'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',
|
2010-02-08 15:08:40 +01:00
|
|
|
'port': 3128,
|
2013-01-01 19:44:25 +01:00
|
|
|
'type': 'bosh',
|
2010-02-08 15:08:40 +01:00
|
|
|
'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')
|
2009-11-05 09:06:46 +01:00
|
|
|
|
2013-01-01 19:44:25 +01:00
|
|
|
proxy_dict = {'bosh_content': 'text/xml; charset=utf-8',
|
2010-02-08 15:08:40 +01:00
|
|
|
'bosh_hold': 2,
|
|
|
|
'bosh_http_pipelining': False,
|
|
|
|
'bosh_port': 5280,
|
2013-01-01 19:44:25 +01:00
|
|
|
'bosh_uri': '',
|
2010-02-08 15:08:40 +01:00
|
|
|
'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',
|
2010-02-08 15:08:40 +01:00
|
|
|
'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')
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|