From 10292cac27bc2f10e2b5768c84091a73105bc495 Mon Sep 17 00:00:00 2001 From: kali Date: Mon, 27 Aug 2012 06:37:10 +0900 Subject: make eipconductor test use BaseLeapTest --- src/leap/eip/tests/test_eipconnection.py | 50 ++++++++++++++------------------ src/leap/testing/basetest.py | 17 +++++++++++ 2 files changed, 38 insertions(+), 29 deletions(-) (limited to 'src/leap') diff --git a/src/leap/eip/tests/test_eipconnection.py b/src/leap/eip/tests/test_eipconnection.py index dee28935..7d8acad6 100644 --- a/src/leap/eip/tests/test_eipconnection.py +++ b/src/leap/eip/tests/test_eipconnection.py @@ -16,6 +16,7 @@ from mock import Mock, patch # MagicMock from leap.base import constants from leap.eip.eipconnection import EIPConnection from leap.eip.exceptions import ConnectionRefusedError +from leap.testing.basetest import BaseLeapTest _system = platform.system() @@ -36,11 +37,30 @@ class MockedEIPConnection(EIPConnection): self.args = [1, 2, 3] -class EIPConductorTest(unittest.TestCase): +class EIPConductorTest(BaseLeapTest): __name__ = "eip_conductor_tests" def setUp(self): + # XXX there's a conceptual/design + # mistake here. + # If we're testing just attrs after init, + # init shold not be doing so much side effects. + + # for instance: + # We have to TOUCH a keys file because + # we're triggerig the key checks FROM + # the constructo. me not like that, + # key checker should better be called explicitelly. + filepath = os.path.expanduser( + '~/.config/leap/providers/%s/openvpn.keys' + % constants.DEFAULT_TEST_PROVIDER) + self.touch(filepath) + self.chmod600(filepath) + + # we init the manager with only + # some methods mocked + self.manager = Mock( name="openvpnmanager_mock") @@ -50,21 +70,6 @@ class EIPConductorTest(unittest.TestCase): def tearDown(self): del self.con - # - # helpers - # - - def _missing_test_for_plat(self, do_raise=False): - if do_raise: - raise NotImplementedError( - "This test is not implemented " - "for the running platform: %s" % - _system) - - def touch(self, filepath): - with open(filepath, 'w') as fp: - fp.write('') - # # tests # @@ -81,19 +86,6 @@ class EIPConductorTest(unittest.TestCase): """ default attrs as expected """ - # XXX there's a conceptual/design - # mistake here. - # If we're testing just attrs after init, - # init shold not be doing so much side effects. - - # for instance: - # We have to TOUCH a keys file because - # we're triggerig the key checks FROM - # the constructo. me not like that, - # key checker should better be called explicitelly. - self.touch(os.path.expanduser( - '~/.config/leap/providers/%s/openvpn.keys' - % constants.DEFAULT_TEST_PROVIDER)) con = self.con self.assertEqual(con.autostart, True) self.assertEqual(con.missing_pkexec, False) diff --git a/src/leap/testing/basetest.py b/src/leap/testing/basetest.py index 8d9264f1..881f56c9 100644 --- a/src/leap/testing/basetest.py +++ b/src/leap/testing/basetest.py @@ -9,6 +9,7 @@ except ImportError: import unittest from leap.base.config import get_username, get_groupname +from leap.util.fileutil import mkdir_p, check_and_fix_urw_only _system = platform.system() @@ -64,3 +65,19 @@ class BaseLeapTest(unittest.TestCase): "This test is not implemented " "for the running platform: %s" % _system) + + def touch(self, filepath): + folder, filename = os.path.split(filepath) + if not os.path.isdir(folder): + mkdir_p(folder) + # XXX should move to test_basetest + self.assertTrue(os.path.isdir(folder)) + + with open(filepath, 'w') as fp: + fp.write(' ') + + # XXX should move to test_basetest + self.assertTrue(os.path.isfile(filepath)) + + def chmod600(self, filepath): + check_and_fix_urw_only(filepath) -- cgit v1.2.3