コード例 #1
0
ファイル: api_validation.py プロジェクト: justelex/Findeco
class ErrorResponseValidator(object):
    def __init__(self):
        self.validator = JSONValidator(errorResponse_schema)

    def validate(self, data):
        self.validator.validate(data)
        if not data['errorResponse']['errorID'] in ERROR_LIST:
            raise JSONValidationError('Invalid errorID "%s"'%data['errorResponse']['errorID'])
コード例 #2
0
ファイル: api_validation.py プロジェクト: Lhurgoyfina/Findeco
 def __init__(self):
     self.validator = JSONValidator(errorResponse_schema)
コード例 #3
0
    'errorResponse': {
        'errorID': string,
        'additionalInfo': [string, None]
    }
}

ERROR_LIST = [
    "_UnknownNode", "_UnknownUser", "_UnknownEmailAddress",
    "_MissingPOSTParameter", "_IllegalPath", "_NotAuthenticated",
    "_PermissionDenied", "_DisabledAccount", "_UsernameNotAvailable",
    "_EmailAddressNotAvailable", "_InvalidUsername", "_InvalidLogin",
    "_InvalidEmailAddress", "_InvalidActivationKey", "_InvalidURL",
    "_InvalidMircobloggingOptions", "_ServerError"
]

validators = {name: JSONValidator(s) for name, s in schema.items()}


# #############################################################################
class ErrorResponseValidator(object):
    def __init__(self):
        self.validator = validators['errorResponse']

    def validate(self, data):
        self.validator.validate(data)
        if not data['errorResponse']['errorID'] in ERROR_LIST:
            raise JSONValidationError('Invalid errorID "%s"' %
                                      data['errorResponse']['errorID'])


errorResponseValidator = ErrorResponseValidator()