def test_validator_should_certify_json(self):
        json_schema_dict = json.loads(fixtures.json_schema_1)
        validator = Validator(json_schema_dict)

        gotten = validator.assert_json(fixtures.json_1)

        self.assertEqual(gotten, True)
    def test_validator_should_certify_json_from_schema_file(self):
        with open(self.json_schema_file_path, 'w') as jss_file:
            jss_file.write(fixtures.json_schema_1)

        validator = Validator.from_path(self.json_schema_file_path)

        gotten = validator.assert_json(fixtures.json_1)

        self.assertEqual(gotten, True)
def validate(args):
    from six.moves.urllib.request import urlopen

    json_data = Recorder.open_with_basic_auth(args.json_source, args.auth).read()
    validator = Validator.from_path(args.json_schema_file_path)
    is_valid = validator.assert_json(json_data)

    if is_valid:
        print(" * JSON is valid")
    else:
        print(" ! JSON is broken ")
        print(validator.error_message)
def validate(args):
    from urllib2 import urlopen

    json_data = urlopen(args.json_source).read()
    validator = Validator.from_path(args.json_schema_file_path)
    is_valid = validator.assert_json(json_data)

    if is_valid:
        print " * JSON is valid"
    else:
        print " ! JSON is broken "
        print validator.error_message
Example #5
0
def validate(args):
    from six.moves.urllib.request import urlopen

    json_data = urlopen(args.json_source).read()
    validator = Validator.from_path(args.json_schema_file_path)
    is_valid = validator.assert_json(json_data)

    if is_valid:
        print (" * JSON is valid")
    else:
        print (" ! JSON is broken ")
        print (validator.error_message)
Example #6
0
def validate(rest_url, json_schema_file_path):
    """
	The function validates the json returned by given REST API using JSON schema

    """
    from urllib2 import urlopen

    json_data = urlopen(rest_url).read()
    validator = Validator.from_path(json_schema_file_path)
    print json_data
    is_valid = validator.assert_json(json_data)

    if is_valid:
        print " Returned JSON is valid"
    else:
        print " Returned JSON is invalid "
        print validator.error_message
        raise Exception("Returned  JSON is invalid %s" %
                        validator.error_message)