summaryrefslogtreecommitdiff
path: root/src/leap/base/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/base/tests')
-rw-r--r--src/leap/base/tests/test_config.py (renamed from src/leap/base/tests/test_configuration.py)92
-rw-r--r--src/leap/base/tests/test_providers.py123
2 files changed, 177 insertions, 38 deletions
diff --git a/src/leap/base/tests/test_configuration.py b/src/leap/base/tests/test_config.py
index 17c8ed1f..c5231de2 100644
--- a/src/leap/base/tests/test_configuration.py
+++ b/src/leap/base/tests/test_config.py
@@ -1,13 +1,14 @@
-import mock
import os
import platform
-import requests
+import socket
import tempfile
+import mock
+import requests
+
+from leap.base import config
from leap.testing.basetest import BaseLeapTest
-from leap.base.configuration import Configuration
-from leap.base import configuration as config
try:
import unittest2 as unittest
@@ -19,6 +20,9 @@ _system = platform.system()
class DefinitionTestCase(BaseLeapTest):
+ # XXX See how to merge with test_providers
+ # -- kali 2012-08-24 00:38
+
__name__ = "provider_config_tests"
def setUp(self):
@@ -49,23 +53,23 @@ class DefinitionTestCase(BaseLeapTest):
u'serial': 1,
u'services': [u'eip'],
u'version': u'0.1.0'}
- cf = Configuration("http://localhost/")
+ cf = config.Configuration("http://localhost/")
self.assertIn('default', cf.providers)
def test_connection_error(self):
with mock.patch.object(requests, "get") as mock_method:
mock_method.side_effect = requests.ConnectionError
- cf = Configuration()
+ cf = config.Configuration()
self.assertIsInstance(cf.error, str)
def test_file_not_found(self):
with mock.patch.object(requests, "get") as mock_method:
mock_method.side_effect = requests.HTTPError
- cf = Configuration()
+ cf = config.Configuration()
self.assertIsInstance(cf.error, str)
def test_invalid_url(self):
- cf = Configuration("ht")
+ cf = config.Configuration("ht")
self.assertTrue(cf.error)
@@ -73,6 +77,12 @@ class ConfigHelperFunctions(BaseLeapTest):
__name__ = "config_helper_tests"
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
#
# tests
#
@@ -105,6 +115,40 @@ class ConfigHelperFunctions(BaseLeapTest):
"""
self._missing_test_for_plat(do_raise=True)
+ #
+ # XXX hey, I'm raising exceptions here
+ # on purpose. just wanted to make sure
+ # that the skip stuff is doing it right.
+ # If you're working on win/macos tests,
+ # feel free to remove tests that you see
+ # are too redundant.
+
+ @unittest.skipUnless(_system == "Linux", "linux only")
+ def test_lin_get_config_dir(self):
+ """
+ nice config dir? (linux)
+ """
+ self.assertEqual(
+ config.get_config_dir(),
+ #XXX not correct!!!
+ #hardcoded home
+ '/home/%s/.config/leap' %
+ self.get_username())
+
+ @unittest.skipUnless(_system == "Darwin", "mac only")
+ def test_mac_get_config_dir(self):
+ """
+ nice config dir? (mac)
+ """
+ self._missing_test_for_plat(do_raise=True)
+
+ @unittest.skipUnless(_system == "Windows", "win only")
+ def test_win_get_config_dir(self):
+ """
+ nice config dir? (win)
+ """
+ self._missing_test_for_plat(do_raise=True)
+
# provider paths
@unittest.skipUnless(_system == "Linux", "linux only")
@@ -136,34 +180,6 @@ class ConfigHelperFunctions(BaseLeapTest):
"""
pass
- #
- # XXX hey, I'm raising exceptions here
- # on purpose. just wanted to make sure
- # that the skip stuff is doing it right.
- # If you're working on win/macos tests,
- # feel free to remove tests that you see
- # are too redundant.
- @unittest.skipUnless(_system == "Linux", "linux only")
- def test_lin_get_config_dir(self):
- """
- nice config dir? (linux)
- """
- self.assertEqual(
- config.get_config_dir(),
- '/home/%s/.config/leap' %
- self.get_username())
-
- @unittest.skipUnless(_system == "Darwin", "mac only")
- def test_mac_get_config_dir(self):
- """
- nice config dir? (mac)
- """
- self._missing_test_for_plat(do_raise=True)
-
- @unittest.skipUnless(_system == "Windows", "win only")
- def test_win_get_config_dir(self):
- """
- nice config dir? (win)
- """
- self._missing_test_for_plat(do_raise=True)
+if __name__ == "__main__":
+ unittest.main()
diff --git a/src/leap/base/tests/test_providers.py b/src/leap/base/tests/test_providers.py
new file mode 100644
index 00000000..2f029930
--- /dev/null
+++ b/src/leap/base/tests/test_providers.py
@@ -0,0 +1,123 @@
+import json
+try:
+ import unittest2 as unittest
+except ImportError:
+ import unittest
+
+import os
+
+from leap.testing.basetest import BaseLeapTest
+from leap.base import providers
+
+EXPECTED_DEFAULT_CONFIG = {
+ "api_version": "0.1.0",
+ "description": "test provider",
+ "display_name": "test provider",
+ "domain": "testprovider.example.org",
+ "enrollment_policy": "open",
+ "serial": 1,
+ "services": [
+ "eip"
+ ],
+ "version": "0.1.0"
+}
+
+
+class TestLeapProviderDefinition(BaseLeapTest):
+ def setUp(self):
+ self.definition = providers.LeapProviderDefinition()
+ #XXX change to self.definition.config when property is fixed
+ self.config = self.definition.get_config()
+
+ def tearDown(self):
+ if hasattr(self, 'testfile') and os.path.isfile(self.testfile):
+ os.remove(self.testfile)
+
+ # tests
+
+ def test_provider_dump(self):
+ # check a good provider definition is dumped to disk
+ self.testfile = self.get_tempfile('test.json')
+ self.definition.save(to=self.testfile)
+ deserialized = json.load(open(self.testfile, 'rb'))
+ self.assertEqual(deserialized, EXPECTED_DEFAULT_CONFIG)
+
+ def test_provider_dump_to_slug(self):
+ # same as above, but we test the ability to save to a
+ # file generated from the slug.
+ # XXX THIS TEST SHOULD MOVE TO test_baseconfig
+ self.definition.save()
+ filename = self.definition.filename
+ deserialized = json.load(open(filename, 'rb'))
+ self.assertEqual(deserialized, EXPECTED_DEFAULT_CONFIG)
+
+ def test_provider_load(self):
+ # check loading provider from disk file
+ self.testfile = self.get_tempfile('test_load.json')
+ with open(self.testfile, 'w') as wf:
+ wf.write(json.dumps(EXPECTED_DEFAULT_CONFIG))
+ self.definition.load(fromfile=self.testfile)
+ self.assertDictEqual(self.config,
+ EXPECTED_DEFAULT_CONFIG)
+
+ @unittest.skip
+ def test_load_malformed_json_definition(self):
+ raise NotImplementedError
+
+ @unittest.skip
+ def test_type_validation(self):
+ # check various type validation
+ # type cast
+ raise NotImplementedError
+
+
+class TestLeapProvider(BaseLeapTest):
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ ###
+
+ # XXX ??
+
+
+class TestLeapProviderSet(BaseLeapTest):
+
+ def setUp(self):
+ self.providers = providers.LeapProviderSet()
+
+ def tearDown(self):
+ pass
+ ###
+
+ def test_get_zero_count(self):
+ self.assertEqual(self.providers.count, 0)
+
+ @unittest.skip
+ def test_count_defined_providers(self):
+ # check the method used for making
+ # the list of providers
+ raise NotImplementedError
+
+ @unittest.skip
+ def test_get_default_provider(self):
+ raise NotImplementedError
+
+ @unittest.skip
+ def test_should_be_at_least_one_provider_after_init(self):
+ # when we init an empty environment,
+ # there should be at least one provider,
+ # that will be a dump of the default provider definition
+ # somehow a high level test
+ raise NotImplementedError
+
+ @unittest.skip
+ def test_get_eip_remote_from_default_provider(self):
+ # from: default provider
+ # expect: remote eip domain
+ raise NotImplementedError
+
+if __name__ == "__main__":
+ unittest.main()