summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkali <kali@leap.se>2013-01-31 09:09:54 +0900
committerkali <kali@leap.se>2013-01-31 09:28:15 +0900
commitda8a8ac4ebc62f7549d2927c41472561541abfa2 (patch)
tree730c6423a6a8cc1d0ef2b1345f1affcbb1c332c2
parent8763866e0a4fc822f198e2e768993fdb9a38ef80 (diff)
hide jsonschema exception in tests
-rw-r--r--src/leap/base/pluggableconfig.py9
-rw-r--r--src/leap/base/tests/test_providers.py6
-rw-r--r--src/leap/base/tests/test_validation.py13
-rw-r--r--src/leap/eip/tests/test_checks.py5
4 files changed, 19 insertions, 14 deletions
diff --git a/src/leap/base/pluggableconfig.py b/src/leap/base/pluggableconfig.py
index 3517db6b..6f9f3f6f 100644
--- a/src/leap/base/pluggableconfig.py
+++ b/src/leap/base/pluggableconfig.py
@@ -26,6 +26,10 @@ __all__ = ['PluggableConfig',
# exceptions
+class ValidationError(Exception):
+ pass
+
+
class UnknownOptionException(Exception):
"""exception raised when a non-configuration
value is present in the configuration"""
@@ -107,7 +111,10 @@ class JSONAdaptor(ConfigAdaptor):
def validate(self, config, schema_obj):
schema_json = JSONSchemaEncoder().encode(schema_obj)
schema = json.loads(schema_json)
- jsonschema.validate(config, schema)
+ try:
+ jsonschema.validate(config, schema)
+ except jsonschema.ValidationError:
+ raise ValidationError
adaptors['json'] = JSONAdaptor()
diff --git a/src/leap/base/tests/test_providers.py b/src/leap/base/tests/test_providers.py
index f257f54d..92bc1f2f 100644
--- a/src/leap/base/tests/test_providers.py
+++ b/src/leap/base/tests/test_providers.py
@@ -6,9 +6,7 @@ except ImportError:
import unittest
import os
-import jsonschema
-
-#from leap import __branding as BRANDING
+from leap.base.pluggableconfig import ValidationError
from leap.testing.basetest import BaseLeapTest
from leap.base import providers
@@ -96,7 +94,7 @@ class TestLeapProviderDefinition(BaseLeapTest):
_config = copy.deepcopy(self.config)
# bad type, raise validation error
_config['domain'] = 111
- with self.assertRaises(jsonschema.ValidationError):
+ with self.assertRaises(ValidationError):
self.definition.validate(_config)
@unittest.skip
diff --git a/src/leap/base/tests/test_validation.py b/src/leap/base/tests/test_validation.py
index 87e99648..b45fbe3a 100644
--- a/src/leap/base/tests/test_validation.py
+++ b/src/leap/base/tests/test_validation.py
@@ -1,5 +1,6 @@
import copy
import datetime
+from functools import partial
#import json
try:
import unittest2 as unittest
@@ -7,8 +8,6 @@ except ImportError:
import unittest
import os
-import jsonschema
-
from leap.base.config import JSONLeapConfig
from leap.base import pluggableconfig
from leap.testing.basetest import BaseLeapTest
@@ -76,16 +75,18 @@ class TestJSONLeapConfigValidation(BaseLeapTest):
def test_broken_int(self):
_config = copy.deepcopy(SAMPLE_CONFIG_DICT)
_config['prop_one'] = '1'
- with self.assertRaises(jsonschema.ValidationError):
- self.sampleconfig.validate(_config)
+ self.assertRaises(
+ pluggableconfig.ValidationError,
+ partial(self.sampleconfig.validate, _config))
def test_format_property(self):
# JsonSchema Validator does not check the format property.
# We should have to extend the Configuration class
blah = copy.deepcopy(SAMPLE_CONFIG_DICT)
blah['prop_uri'] = 'xxx'
- with self.assertRaises(pluggableconfig.TypeCastException):
- self.sampleconfig.validate(blah)
+ self.assertRaises(
+ pluggableconfig.TypeCastException,
+ partial(self.sampleconfig.validate, blah))
if __name__ == "__main__":
diff --git a/src/leap/eip/tests/test_checks.py b/src/leap/eip/tests/test_checks.py
index ab11037a..f42a0eeb 100644
--- a/src/leap/eip/tests/test_checks.py
+++ b/src/leap/eip/tests/test_checks.py
@@ -11,11 +11,10 @@ import urlparse
from mock import (patch, Mock)
-import jsonschema
-#import ping
import requests
from leap.base import config as baseconfig
+from leap.base import pluggableconfig
from leap.base.constants import (DEFAULT_PROVIDER_DEFINITION,
DEFINITION_EXPECTED_PATH)
from leap.eip import checks as eipchecks
@@ -125,7 +124,7 @@ class EIPCheckTest(BaseLeapTest):
#with self.assertRaises(eipexceptions.EIPMissingDefaultProvider):
# XXX we should catch this as one of our errors, but do not
# see how to do it quickly.
- with self.assertRaises(jsonschema.ValidationError):
+ with self.assertRaises(pluggableconfig.ValidationError):
#import ipdb;ipdb.set_trace()
checker.eipconfig.load(fromfile=eipcfg_path)
checker.check_is_there_default_provider()