def validateResponseClass(responseClass, controllerResponse): if isNotPythonFrameworkHttpsResponse(controllerResponse): raiseBadResponseImplementation( f'Python Framework response cannot be null. It should be a list like this: [{"RESPONSE_CLASS" if ObjectHelper.isNone(responseClass) else responseClass if ObjectHelper.isNotList(responseClass) else responseClass[0]}, HTTPS_CODE]' ) if ObjectHelper.isNotNone(responseClass): if Serializer.isSerializerList(responseClass): if 0 == len(responseClass): log.warning(validateResponseClass, f'"responseClass" was not defined') elif 1 == len(responseClass): if ObjectHelper.isNotList(responseClass[0]): if not isinstance(controllerResponse[0], responseClass[0]): raiseBadResponseImplementation( f'Response class does not match expected class. Expected "{responseClass[0].__name__}", response "{controllerResponse[0].__class__.__name__}"' ) elif ObjectHelper.isNotList(responseClass[0][0]): if ObjectHelper.isNotList(controllerResponse[0]): raiseBadResponseImplementation( f'Response is not a list. Expected "{responseClass[0].__class__.__name__}", but found "{controllerResponse[0].__class__.__name__}"' ) elif Serializer.isSerializerList( controllerResponse[0] ) and 0 < len(controllerResponse[0]) and not isinstance( controllerResponse[0][0], responseClass[0][0]): raiseBadResponseImplementation( f'Response element class does not match expected element class. Expected "{responseClass[0][0].__name__}", response "{controllerResponse[0][0].__class__.__name__}"' ) else: if not isinstance(controllerResponse[0], responseClass): raiseBadResponseImplementation( f'Response class does not match expected class. Expected "{responseClass.__name__}", response "{controllerResponse[0].__class__.__name__}"' ) else: log.warning(validateResponseClass, f'"responseClass" was not defined')
def validateArgs(args, requestClass, method): if ObjectHelper.isNotNone(requestClass): resourceInstance = args[0] if Serializer.isSerializerList(requestClass): if 0 < len(requestClass): for index in range(len(requestClass)): if Serializer.isSerializerList( args[index + 1]) and len(args[index + 1]) > 0: expecteObjectClass = requestClass[index][0] for objectInstance in args[index + 1]: GlobalException.validateArgs( resourceInstance, method, objectInstance, expecteObjectClass) else: objectRequest = args[index + 1] expecteObjectClass = requestClass[index] GlobalException.validateArgs(resourceInstance, method, objectRequest, expecteObjectClass) else: objectRequest = args[1] expecteObjectClass = requestClass GlobalException.validateArgs(resourceInstance, method, objectRequest, expecteObjectClass)