summaryrefslogtreecommitdiff
path: root/src/leap/base
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 /src/leap/base
parent8763866e0a4fc822f198e2e768993fdb9a38ef80 (diff)
hide jsonschema exception in tests
Diffstat (limited to 'src/leap/base')
-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
3 files changed, 17 insertions, 11 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__":