diff options
author | kali <kali@leap.se> | 2012-08-27 05:45:58 +0900 |
---|---|---|
committer | kali <kali@leap.se> | 2012-08-27 05:49:41 +0900 |
commit | 2bbe0e0a2d852a1a7261b2fa927eab6e8f41c8c3 (patch) | |
tree | 2dbd03421f32e78c54b0df4855058acd5c8ae1c8 | |
parent | 09a68fab7d39521ffb5017abaffdb4c946cd5034 (diff) |
change default_provider_path to base.constants
fix tests by introducing a (dirtish) workaround for
check for openvpn keys during vpn connection initialization.
noted that eipconnection constructor should be better not
having that class of side-effects.
-rw-r--r-- | src/leap/base/config.py | 3 | ||||
-rw-r--r-- | src/leap/base/constants.py | 8 | ||||
-rw-r--r-- | src/leap/base/tests/test_config.py | 5 | ||||
-rw-r--r-- | src/leap/eip/tests/test_config.py | 6 | ||||
-rw-r--r-- | src/leap/eip/tests/test_eipconnection.py | 19 |
5 files changed, 37 insertions, 4 deletions
diff --git a/src/leap/base/config.py b/src/leap/base/config.py index 8455f9de..4d7db018 100644 --- a/src/leap/base/config.py +++ b/src/leap/base/config.py @@ -13,6 +13,7 @@ logger = logging.getLogger(name=__name__) logger.setLevel('DEBUG') from leap.base import exceptions +from leap.base import constants from leap.util.fileutil import (mkdir_p) @@ -135,7 +136,7 @@ def get_config_file(filename, folder=None): def get_default_provider_path(): default_subpath = os.path.join("providers", - "default") + constants.DEFAULT_TEST_PROVIDER) default_provider_path = get_config_file( '', folder=default_subpath) diff --git a/src/leap/base/constants.py b/src/leap/base/constants.py new file mode 100644 index 00000000..55308a31 --- /dev/null +++ b/src/leap/base/constants.py @@ -0,0 +1,8 @@ +"""constants to be used in base module""" + +# default provider placeholder +# using `example.org` we make sure that this +# is not going to be resolved during the tests phases +# (we expect testers to add it to their /etc/hosts + +DEFAULT_TEST_PROVIDER = "testprovider.example.org" diff --git a/src/leap/base/tests/test_config.py b/src/leap/base/tests/test_config.py index 0a98dbaf..67be0e54 100644 --- a/src/leap/base/tests/test_config.py +++ b/src/leap/base/tests/test_config.py @@ -8,6 +8,7 @@ import mock import requests from leap.base import config +from leap.base import constants from leap.base import exceptions from leap.util.fileutil import mkdir_p from leap.testing.basetest import BaseLeapTest @@ -215,7 +216,9 @@ class ConfigHelperFunctions(BaseLeapTest): """ self.assertEqual( config.get_default_provider_path(), - os.path.expanduser('~/.config/leap/providers/default/') + os.path.expanduser( + '~/.config/leap/providers/%s/' % + constants.DEFAULT_TEST_PROVIDER) ) # validate ip diff --git a/src/leap/eip/tests/test_config.py b/src/leap/eip/tests/test_config.py index b6b06346..ed9fe270 100644 --- a/src/leap/eip/tests/test_config.py +++ b/src/leap/eip/tests/test_config.py @@ -7,8 +7,9 @@ try: except ImportError: import unittest -from leap.testing.basetest import BaseLeapTest +from leap.base import constants from leap.eip import config as eip_config +from leap.testing.basetest import BaseLeapTest _system = platform.system() @@ -62,7 +63,8 @@ class EIPConfigTest(BaseLeapTest): args.append('unix') args.append('--config') args.append(os.path.expanduser( - '~/.config/leap/providers/default/openvpn.conf')) + '~/.config/leap/providers/%s/openvpn.conf' + % constants.DEFAULT_TEST_PROVIDER)) return args # build command string diff --git a/src/leap/eip/tests/test_eipconnection.py b/src/leap/eip/tests/test_eipconnection.py index 51772b7c..dee28935 100644 --- a/src/leap/eip/tests/test_eipconnection.py +++ b/src/leap/eip/tests/test_eipconnection.py @@ -1,6 +1,7 @@ import ConfigParser import logging import platform +import os logging.basicConfig() logger = logging.getLogger(name=__name__) @@ -12,6 +13,7 @@ except ImportError: from mock import Mock, patch # MagicMock +from leap.base import constants from leap.eip.eipconnection import EIPConnection from leap.eip.exceptions import ConnectionRefusedError @@ -59,6 +61,10 @@ class EIPConductorTest(unittest.TestCase): "for the running platform: %s" % _system) + def touch(self, filepath): + with open(filepath, 'w') as fp: + fp.write('') + # # tests # @@ -75,6 +81,19 @@ 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) |