@@ -0,0 +1,2752 @@
+# Licensed to the StackStorm, Inc ('StackStorm') under one or more%0A# contributor license agreements.  See the NOTICE file distributed with%0A# this work for additional information regarding copyright ownership.%0A# The ASF licenses this file to You under the Apache License, Version 2.0%0A# (the %22License%22); you may not use this file except in compliance with%0A# the License.  You may obtain a copy of the License at%0A#%0A#     http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS,%0A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A# See the License for the specific language governing permissions and%0A# limitations under the License.%0A%0Afrom unittest2 import TestCase%0Afrom jsonschema.exceptions import ValidationError%0A%0Afrom st2common.util import schema as util_schema%0A%0ATEST_SCHEMA_1 = %7B%0A    'additionalProperties': False,%0A    'title': 'foo',%0A    'description': 'Foo.',%0A    'type': 'object',%0A    'properties': %7B%0A        'cmd_no_default': %7B%0A            'description': 'Foo',%0A            'required': True,%0A            'type': 'string'%0A        %7D%0A    %7D%0A%7D%0A%0ATEST_SCHEMA_2 = %7B%0A    'additionalProperties': False,%0A    'title': 'foo',%0A    'description': 'Foo.',%0A    'type': 'object',%0A    'properties': %7B%0A        'cmd_default': %7B%0A            'default': 'date',%0A            'description': 'Foo',%0A            'required': True,%0A            'type': 'string'%0A        %7D%0A    %7D%0A%7D%0A%0A%0Aclass JSONSchemaTestCase(TestCase):%0A    def test_use_default_value(self):%0A        # No default, no value provided, should fail%0A        instance = %7B%7D%0A        validator = util_schema.get_validator()%0A%0A        expected_msg = '%5C'cmd_no_default%5C' is a required property'%0A        self.assertRaisesRegexp(ValidationError, expected_msg, util_schema.validate,%0A                                instance=instance, schema=TEST_SCHEMA_1, cls=validator,%0A                                use_default=True)%0A%0A        # No default, value provided%0A        instance = %7B'cmd_no_default': 'foo'%7D%0A        util_schema.validate(instance=instance, schema=TEST_SCHEMA_1, cls=validator,%0A                             use_default=True)%0A%0A        # default value provided, no value, should pass%0A        instance = %7B%7D%0A        validator = util_schema.get_validator()%0A        util_schema.validate(instance=instance, schema=TEST_SCHEMA_2, cls=validator,%0A                             use_default=True)%0A%0A        # default value provided, value provided, should pass%0A        instance = %7B'cmd_default': 'foo'%7D%0A        validator = util_schema.get_validator()%0A        util_schema.validate(instance=instance, schema=TEST_SCHEMA_2, cls=validator,%0A                             use_default=True)%0A

Add test case for "use_default".