summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkali <kali@leap.se>2012-08-27 06:37:10 +0900
committerkali <kali@leap.se>2012-08-27 06:37:10 +0900
commit10292cac27bc2f10e2b5768c84091a73105bc495 (patch)
treefa232d1c1fb560c1364ec035a16a49d9deb8decd
parent2bbe0e0a2d852a1a7261b2fa927eab6e8f41c8c3 (diff)
make eipconductor test use BaseLeapTest
-rw-r--r--src/leap/eip/tests/test_eipconnection.py50
-rw-r--r--src/leap/testing/basetest.py17
2 files changed, 38 insertions, 29 deletions
diff --git a/src/leap/eip/tests/test_eipconnection.py b/src/leap/eip/tests/test_eipconnection.py
index dee2893..7d8acad 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")
@@ -51,21 +71,6 @@ class EIPConductorTest(unittest.TestCase):
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 8d9264f..881f56c 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)