Organize tests into unit and integration tests.
Integration tests can depend on UI, network or both. Unittests use neither.
This commit is contained in:
parent
3157cf0b1b
commit
2e5bf4d0d2
15 changed files with 126 additions and 80 deletions
6
test/integration/__init__.py
Normal file
6
test/integration/__init__.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
'''
|
||||||
|
|
||||||
|
This package contains integration tests. Integration tests are tests
|
||||||
|
which require or include UI, network or both.
|
||||||
|
|
||||||
|
'''
|
|
@ -1,5 +1,6 @@
|
||||||
'''
|
'''
|
||||||
Unit test for tranports classes.
|
Integration test for tranports classes. See unit for the ordinary
|
||||||
|
unit tests of this module.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -12,62 +13,6 @@ from xmpp_mocks import IdleQueueThread, IdleMock
|
||||||
from common.xmpp import transports_nb
|
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, path):
|
|
||||||
_proto, _host, _path = transports_nb.urisplit(uri)
|
|
||||||
self.assertEqual(proto, _proto)
|
|
||||||
self.assertEqual(host, _host)
|
|
||||||
self.assertEqual(path, _path)
|
|
||||||
check_uri('http://httpcm.jabber.org/webclient',
|
|
||||||
proto='http', host='httpcm.jabber.org', 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)
|
|
||||||
|
|
||||||
bosh_dict = {'bosh_content': u'text/xml; charset=utf-8',
|
|
||||||
'bosh_hold': 2,
|
|
||||||
'bosh_http_pipelining': False,
|
|
||||||
'bosh_uri': u'http://gajim.org:5280/http-bind',
|
|
||||||
'bosh_useproxy': False,
|
|
||||||
'bosh_wait': 30,
|
|
||||||
'bosh_wait_for_restart_response': False,
|
|
||||||
'host': u'172.16.99.11',
|
|
||||||
'pass': u'pass',
|
|
||||||
'port': 3128,
|
|
||||||
'type': u'bosh',
|
|
||||||
'useauth': True,
|
|
||||||
'user': u'user'}
|
|
||||||
check_dict(bosh_dict, host=u'gajim.org', port=5280, user=u'user',
|
|
||||||
passwd=u'pass')
|
|
||||||
|
|
||||||
proxy_dict = {'bosh_content': u'text/xml; charset=utf-8',
|
|
||||||
'bosh_hold': 2,
|
|
||||||
'bosh_http_pipelining': False,
|
|
||||||
'bosh_port': 5280,
|
|
||||||
'bosh_uri': u'',
|
|
||||||
'bosh_useproxy': True,
|
|
||||||
'bosh_wait': 30,
|
|
||||||
'bosh_wait_for_restart_response': False,
|
|
||||||
'host': u'172.16.99.11',
|
|
||||||
'pass': u'pass',
|
|
||||||
'port': 3128,
|
|
||||||
'type': 'socks5',
|
|
||||||
'useauth': True,
|
|
||||||
'user': u'user'}
|
|
||||||
check_dict(proxy_dict, host=u'172.16.99.11', port=3128, user=u'user',
|
|
||||||
passwd=u'pass')
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractTransportTest(unittest.TestCase):
|
class AbstractTransportTest(unittest.TestCase):
|
||||||
''' Encapsulates Idlequeue instantiation for transports and more...'''
|
''' Encapsulates Idlequeue instantiation for transports and more...'''
|
||||||
|
|
|
@ -91,6 +91,7 @@ class MockChatControl(Mock):
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return self is other
|
return self is other
|
||||||
|
|
||||||
|
|
||||||
class MockInterface(Mock):
|
class MockInterface(Mock):
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
Mock.__init__(self, *args)
|
Mock.__init__(self, *args)
|
||||||
|
@ -113,14 +114,17 @@ class MockInterface(Mock):
|
||||||
self.jabber_state_images = {'16': Mock(), '32': Mock(),
|
self.jabber_state_images = {'16': Mock(), '32': Mock(),
|
||||||
'opened': Mock(), 'closed': Mock()}
|
'opened': Mock(), 'closed': Mock()}
|
||||||
|
|
||||||
|
|
||||||
class MockLogger(Mock):
|
class MockLogger(Mock):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Mock.__init__(self, {'write': None, 'get_transports_type': {}})
|
Mock.__init__(self, {'write': None, 'get_transports_type': {}})
|
||||||
|
|
||||||
|
|
||||||
class MockContact(Mock):
|
class MockContact(Mock):
|
||||||
def __nonzero__(self):
|
def __nonzero__(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
class MockSession(Mock):
|
class MockSession(Mock):
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
'''
|
'''
|
||||||
Runs Gajim's Test Suite
|
Runs Gajim's Test Suite
|
||||||
|
|
||||||
Non GUI related tests will be run on each commit.
|
Unit tests tests will be run on each commit.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
@ -35,20 +35,21 @@ for o, a in opts:
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
# new test modules need to be added manually
|
# new test modules need to be added manually
|
||||||
modules = ( 'test_xmpp_dispatcher_nb',
|
modules = ( 'unit.test_xmpp_dispatcher_nb',
|
||||||
'test_xmpp_client_nb',
|
'unit.test_xmpp_transports_nb',
|
||||||
'test_xmpp_transports_nb',
|
'unit.test_caps',
|
||||||
'test_resolver',
|
'unit.test_contacts',
|
||||||
'test_caps',
|
'unit.test_gui_interface',
|
||||||
'test_contacts',
|
'unit.test_sessions',
|
||||||
'test_gui_interface',
|
|
||||||
)
|
)
|
||||||
#modules = ()
|
#modules = ()
|
||||||
|
|
||||||
if use_x:
|
if use_x:
|
||||||
modules += ('test_gui_event_integration',
|
modules += ('integration.test_gui_event_integration',
|
||||||
'test_roster',
|
'integration.test_roster',
|
||||||
'test_sessions',
|
'integration.test_resolver',
|
||||||
|
'integration.test_xmpp_client_nb',
|
||||||
|
'integration.test_xmpp_transports_nb'
|
||||||
)
|
)
|
||||||
|
|
||||||
nb_errors = 0
|
nb_errors = 0
|
||||||
|
|
5
test/unit/__init__.py
Normal file
5
test/unit/__init__.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
'''
|
||||||
|
|
||||||
|
This package just contains plain unit tests
|
||||||
|
|
||||||
|
'''
|
|
@ -3,13 +3,15 @@ import unittest
|
||||||
import lib
|
import lib
|
||||||
lib.setup_env()
|
lib.setup_env()
|
||||||
|
|
||||||
from gajim_mocks import *
|
|
||||||
gajim.logger = MockLogger()
|
|
||||||
|
|
||||||
from common import logging_helpers
|
from common import logging_helpers
|
||||||
logging_helpers.set_quiet()
|
logging_helpers.set_quiet()
|
||||||
|
|
||||||
from interface import Interface
|
from common import gajim
|
||||||
|
|
||||||
|
from gajim_mocks import MockLogger
|
||||||
|
gajim.logger = MockLogger()
|
||||||
|
|
||||||
|
from gui_interface import Interface
|
||||||
|
|
||||||
class Test(unittest.TestCase):
|
class Test(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -77,7 +79,6 @@ class Test(unittest.TestCase):
|
||||||
self.assertTrue(self.called_a and self.called_b,
|
self.assertTrue(self.called_a and self.called_b,
|
||||||
msg="Both handlers should have been called")
|
msg="Both handlers should have been called")
|
||||||
|
|
||||||
|
|
||||||
def test_links_regexp_entire(self):
|
def test_links_regexp_entire(self):
|
||||||
sut = Interface()
|
sut = Interface()
|
||||||
def assert_matches_all(str_):
|
def assert_matches_all(str_):
|
|
@ -5,19 +5,27 @@ import time
|
||||||
import lib
|
import lib
|
||||||
lib.setup_env()
|
lib.setup_env()
|
||||||
|
|
||||||
|
|
||||||
|
import notify
|
||||||
|
|
||||||
from common import gajim
|
from common import gajim
|
||||||
from common import xmpp
|
from common import xmpp
|
||||||
|
|
||||||
|
from common.stanza_session import StanzaSession
|
||||||
|
from session import ChatControlSession
|
||||||
|
|
||||||
from mock import Mock, expectParams
|
from mock import Mock, expectParams
|
||||||
from gajim_mocks import *
|
from gajim_mocks import *
|
||||||
|
|
||||||
from common.stanza_session import StanzaSession
|
gajim.interface = MockInterface()
|
||||||
|
|
||||||
|
|
||||||
# name to use for the test account
|
# name to use for the test account
|
||||||
account_name = 'test'
|
account_name = 'test'
|
||||||
|
|
||||||
class TestStanzaSession(unittest.TestCase):
|
class TestStanzaSession(unittest.TestCase):
|
||||||
''' Testclass for common/stanzasession.py '''
|
''' Testclass for common/stanzasession.py '''
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.jid = 'test@example.org/Gajim'
|
self.jid = 'test@example.org/Gajim'
|
||||||
self.conn = MockConnection(account_name, {'send_stanza': None})
|
self.conn = MockConnection(account_name, {'send_stanza': None})
|
||||||
|
@ -68,14 +76,10 @@ class TestStanzaSession(unittest.TestCase):
|
||||||
calls = self.conn.mockGetNamedCalls('send_stanza')
|
calls = self.conn.mockGetNamedCalls('send_stanza')
|
||||||
self.assertEqual(0, len(calls))
|
self.assertEqual(0, len(calls))
|
||||||
|
|
||||||
from session import ChatControlSession
|
|
||||||
|
|
||||||
gajim.interface = MockInterface()
|
|
||||||
|
|
||||||
import notify
|
|
||||||
|
|
||||||
class TestChatControlSession(unittest.TestCase):
|
class TestChatControlSession(unittest.TestCase):
|
||||||
''' Testclass for session.py '''
|
''' Testclass for session.py '''
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.jid = 'test@example.org/Gajim'
|
self.jid = 'test@example.org/Gajim'
|
||||||
self.conn = MockConnection(account_name, {'send_stanza': None})
|
self.conn = MockConnection(account_name, {'send_stanza': None})
|
80
test/unit/test_xmpp_transports_nb.py
Normal file
80
test/unit/test_xmpp_transports_nb.py
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
'''
|
||||||
|
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)
|
||||||
|
|
||||||
|
bosh_dict = {'bosh_content': u'text/xml; charset=utf-8',
|
||||||
|
'bosh_hold': 2,
|
||||||
|
'bosh_http_pipelining': False,
|
||||||
|
'bosh_uri': u'http://gajim.org:5280/http-bind',
|
||||||
|
'bosh_useproxy': False,
|
||||||
|
'bosh_wait': 30,
|
||||||
|
'bosh_wait_for_restart_response': False,
|
||||||
|
'host': u'172.16.99.11',
|
||||||
|
'pass': u'pass',
|
||||||
|
'port': 3128,
|
||||||
|
'type': u'bosh',
|
||||||
|
'useauth': True,
|
||||||
|
'user': u'user'}
|
||||||
|
check_dict(bosh_dict, host=u'gajim.org', port=5280, user=u'user',
|
||||||
|
passwd=u'pass')
|
||||||
|
|
||||||
|
proxy_dict = {'bosh_content': u'text/xml; charset=utf-8',
|
||||||
|
'bosh_hold': 2,
|
||||||
|
'bosh_http_pipelining': False,
|
||||||
|
'bosh_port': 5280,
|
||||||
|
'bosh_uri': u'',
|
||||||
|
'bosh_useproxy': True,
|
||||||
|
'bosh_wait': 30,
|
||||||
|
'bosh_wait_for_restart_response': False,
|
||||||
|
'host': u'172.16.99.11',
|
||||||
|
'pass': u'pass',
|
||||||
|
'port': 3128,
|
||||||
|
'type': 'socks5',
|
||||||
|
'useauth': True,
|
||||||
|
'user': u'user'}
|
||||||
|
check_dict(proxy_dict, host=u'172.16.99.11', port=3128, user=u'user',
|
||||||
|
passwd=u'pass')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
|
# vim: se ts=3:
|
Loading…
Add table
Reference in a new issue