From 2e5bf4d0d2b205cc76221cbe253176bdbc56d3a3 Mon Sep 17 00:00:00 2001 From: Stephan Erb Date: Thu, 5 Nov 2009 09:06:46 +0100 Subject: [PATCH] Organize tests into unit and integration tests. Integration tests can depend on UI, network or both. Unittests use neither. --- test/integration/__init__.py | 6 ++ .../test_gui_event_integration.py | 0 test/{ => integration}/test_resolver.py | 0 test/{ => integration}/test_roster.py | 0 test/{ => integration}/test_xmpp_client_nb.py | 0 .../test_xmpp_transports_nb.py | 59 +------------- test/lib/gajim_mocks.py | 4 + test/runtests.py | 23 +++--- test/unit/__init__.py | 5 ++ test/{ => unit}/test_caps.py | 0 test/{ => unit}/test_contacts.py | 0 test/{ => unit}/test_gui_interface.py | 13 +-- test/{ => unit}/test_sessions.py | 16 ++-- test/{ => unit}/test_xmpp_dispatcher_nb.py | 0 test/unit/test_xmpp_transports_nb.py | 80 +++++++++++++++++++ 15 files changed, 126 insertions(+), 80 deletions(-) create mode 100644 test/integration/__init__.py rename test/{ => integration}/test_gui_event_integration.py (100%) rename test/{ => integration}/test_resolver.py (100%) rename test/{ => integration}/test_roster.py (100%) rename test/{ => integration}/test_xmpp_client_nb.py (100%) rename test/{ => integration}/test_xmpp_transports_nb.py (82%) create mode 100644 test/unit/__init__.py rename test/{ => unit}/test_caps.py (100%) rename test/{ => unit}/test_contacts.py (100%) rename test/{ => unit}/test_gui_interface.py (95%) rename test/{ => unit}/test_sessions.py (99%) rename test/{ => unit}/test_xmpp_dispatcher_nb.py (100%) create mode 100644 test/unit/test_xmpp_transports_nb.py diff --git a/test/integration/__init__.py b/test/integration/__init__.py new file mode 100644 index 000000000..0adf844f1 --- /dev/null +++ b/test/integration/__init__.py @@ -0,0 +1,6 @@ +''' + +This package contains integration tests. Integration tests are tests +which require or include UI, network or both. + +''' \ No newline at end of file diff --git a/test/test_gui_event_integration.py b/test/integration/test_gui_event_integration.py similarity index 100% rename from test/test_gui_event_integration.py rename to test/integration/test_gui_event_integration.py diff --git a/test/test_resolver.py b/test/integration/test_resolver.py similarity index 100% rename from test/test_resolver.py rename to test/integration/test_resolver.py diff --git a/test/test_roster.py b/test/integration/test_roster.py similarity index 100% rename from test/test_roster.py rename to test/integration/test_roster.py diff --git a/test/test_xmpp_client_nb.py b/test/integration/test_xmpp_client_nb.py similarity index 100% rename from test/test_xmpp_client_nb.py rename to test/integration/test_xmpp_client_nb.py diff --git a/test/test_xmpp_transports_nb.py b/test/integration/test_xmpp_transports_nb.py similarity index 82% rename from test/test_xmpp_transports_nb.py rename to test/integration/test_xmpp_transports_nb.py index edc2f3ebb..f6cbab510 100644 --- a/test/test_xmpp_transports_nb.py +++ b/test/integration/test_xmpp_transports_nb.py @@ -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...''' diff --git a/test/lib/gajim_mocks.py b/test/lib/gajim_mocks.py index 44b18f037..d45e488e6 100644 --- a/test/lib/gajim_mocks.py +++ b/test/lib/gajim_mocks.py @@ -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): diff --git a/test/runtests.py b/test/runtests.py index bb7e86191..5a9f5f663 100755 --- a/test/runtests.py +++ b/test/runtests.py @@ -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 diff --git a/test/unit/__init__.py b/test/unit/__init__.py new file mode 100644 index 000000000..8e5f2ad7c --- /dev/null +++ b/test/unit/__init__.py @@ -0,0 +1,5 @@ +''' + +This package just contains plain unit tests + +''' \ No newline at end of file diff --git a/test/test_caps.py b/test/unit/test_caps.py similarity index 100% rename from test/test_caps.py rename to test/unit/test_caps.py diff --git a/test/test_contacts.py b/test/unit/test_contacts.py similarity index 100% rename from test/test_contacts.py rename to test/unit/test_contacts.py diff --git a/test/test_gui_interface.py b/test/unit/test_gui_interface.py similarity index 95% rename from test/test_gui_interface.py rename to test/unit/test_gui_interface.py index b2acc019f..57b91ad4b 100644 --- a/test/test_gui_interface.py +++ b/test/unit/test_gui_interface.py @@ -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_) diff --git a/test/test_sessions.py b/test/unit/test_sessions.py similarity index 99% rename from test/test_sessions.py rename to test/unit/test_sessions.py index a28b9259b..724bac56d 100644 --- a/test/test_sessions.py +++ b/test/unit/test_sessions.py @@ -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}) diff --git a/test/test_xmpp_dispatcher_nb.py b/test/unit/test_xmpp_dispatcher_nb.py similarity index 100% rename from test/test_xmpp_dispatcher_nb.py rename to test/unit/test_xmpp_dispatcher_nb.py diff --git a/test/unit/test_xmpp_transports_nb.py b/test/unit/test_xmpp_transports_nb.py new file mode 100644 index 000000000..b81f60d61 --- /dev/null +++ b/test/unit/test_xmpp_transports_nb.py @@ -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: