Organize tests into unit and integration tests.

Integration tests can depend on UI, network or both. Unittests use neither.
This commit is contained in:
Stephan Erb 2009-11-05 09:06:46 +01:00
parent 3157cf0b1b
commit 2e5bf4d0d2
15 changed files with 126 additions and 80 deletions

View File

@ -0,0 +1,6 @@
'''
This package contains integration tests. Integration tests are tests
which require or include UI, network or both.
'''

View File

@ -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
@ -12,62 +13,6 @@ from xmpp_mocks import IdleQueueThread, IdleMock
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):
''' Encapsulates Idlequeue instantiation for transports and more...'''

View File

@ -91,6 +91,7 @@ class MockChatControl(Mock):
def __eq__(self, other):
return self is other
class MockInterface(Mock):
def __init__(self, *args):
Mock.__init__(self, *args)
@ -113,14 +114,17 @@ class MockInterface(Mock):
self.jabber_state_images = {'16': Mock(), '32': Mock(),
'opened': Mock(), 'closed': Mock()}
class MockLogger(Mock):
def __init__(self):
Mock.__init__(self, {'write': None, 'get_transports_type': {}})
class MockContact(Mock):
def __nonzero__(self):
return True
import random
class MockSession(Mock):

View File

@ -4,7 +4,7 @@
'''
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
@ -35,20 +35,21 @@ for o, a in opts:
sys.exit(2)
# new test modules need to be added manually
modules = ( 'test_xmpp_dispatcher_nb',
'test_xmpp_client_nb',
'test_xmpp_transports_nb',
'test_resolver',
'test_caps',
'test_contacts',
'test_gui_interface',
modules = ( 'unit.test_xmpp_dispatcher_nb',
'unit.test_xmpp_transports_nb',
'unit.test_caps',
'unit.test_contacts',
'unit.test_gui_interface',
'unit.test_sessions',
)
#modules = ()
if use_x:
modules += ('test_gui_event_integration',
'test_roster',
'test_sessions',
modules += ('integration.test_gui_event_integration',
'integration.test_roster',
'integration.test_resolver',
'integration.test_xmpp_client_nb',
'integration.test_xmpp_transports_nb'
)
nb_errors = 0

5
test/unit/__init__.py Normal file
View File

@ -0,0 +1,5 @@
'''
This package just contains plain unit tests
'''

View File

@ -3,13 +3,15 @@ import unittest
import lib
lib.setup_env()
from gajim_mocks import *
gajim.logger = MockLogger()
from common import logging_helpers
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):
@ -76,9 +78,8 @@ class Test(unittest.TestCase):
sut.dispatch(event, 'account', 'data')
self.assertTrue(self.called_a and self.called_b,
msg="Both handlers should have been called")
def test_links_regexp_entire(self):
def test_links_regexp_entire(self):
sut = Interface()
def assert_matches_all(str_):
m = sut.basic_pattern_re.match(str_)

View File

@ -5,19 +5,27 @@ import time
import lib
lib.setup_env()
import notify
from common import gajim
from common import xmpp
from common.stanza_session import StanzaSession
from session import ChatControlSession
from mock import Mock, expectParams
from gajim_mocks import *
from common.stanza_session import StanzaSession
gajim.interface = MockInterface()
# name to use for the test account
account_name = 'test'
class TestStanzaSession(unittest.TestCase):
''' Testclass for common/stanzasession.py '''
def setUp(self):
self.jid = 'test@example.org/Gajim'
self.conn = MockConnection(account_name, {'send_stanza': None})
@ -68,14 +76,10 @@ class TestStanzaSession(unittest.TestCase):
calls = self.conn.mockGetNamedCalls('send_stanza')
self.assertEqual(0, len(calls))
from session import ChatControlSession
gajim.interface = MockInterface()
import notify
class TestChatControlSession(unittest.TestCase):
''' Testclass for session.py '''
def setUp(self):
self.jid = 'test@example.org/Gajim'
self.conn = MockConnection(account_name, {'send_stanza': None})

View 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: