Esempio n. 1
0
def validateCompleteResponse(responseClass, completeResponse):
    if isNotPythonFrameworkHttpsResponseBody(completeResponse):
        raiseBadResponseImplementation(
            f'It should be a tuple like this: ({"RESPONSE_CLASS" if ObjectHelper.isNone(responseClass) else responseClass if ObjectHelper.isNotList(responseClass) else responseClass[0]}, HEADERS, HTTPS_CODE). But it is: {completeResponse}'
        )
    if ObjectHelper.isNotNone(responseClass):
        if Serializer.isSerializerList(responseClass):
            if 0 == len(responseClass):
                log.log(validateCompleteResponse,
                        f'"responseClass" was not defined')
            elif 1 == len(responseClass):
                if ObjectHelper.isNotList(responseClass[0]):
                    if not isinstance(completeResponse[0], responseClass[0]):
                        raiseBadResponseImplementation(
                            f'Response does not match expected class. Expected "{responseClass[0].__name__}", but got "{completeResponse[0].__class__.__name__}"'
                        )
                elif ObjectHelper.isNotList(responseClass[0][0]):
                    if ObjectHelper.isNotList(completeResponse[0]):
                        raiseBadResponseImplementation(
                            f'Response is not a list. Expected "{responseClass[0].__class__.__name__}", but found "{completeResponse[0].__class__.__name__}"'
                        )
                    elif Serializer.isSerializerList(
                            completeResponse[0]
                    ) and 0 < len(completeResponse[0]) and not isinstance(
                            completeResponse[0][0], responseClass[0][0]):
                        raiseBadResponseImplementation(
                            f'Response element class does not match expected element class. Expected "{responseClass[0][0].__name__}", response "{completeResponse[0][0].__class__.__name__}"'
                        )
        else:
            if not isinstance(completeResponse[0], responseClass):
                raiseBadResponseImplementation(
                    f'Response does not match expected class. Expected "{responseClass.__name__}", but got "{completeResponse[0].__class__.__name__}"'
                )
    else:
        log.log(validateCompleteResponse, f'"responseClass" was not defined')
Esempio n. 2
0
def validateArgs(args, requestClass, resourceInstanceMethod):
    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]:
                            ExceptionHandler.validateArgs(
                                resourceInstance, resourceInstanceMethod,
                                objectInstance, expecteObjectClass)
                    else:
                        objectRequest = args[index + 1]
                        expecteObjectClass = requestClass[index]
                        ExceptionHandler.validateArgs(resourceInstance,
                                                      resourceInstanceMethod,
                                                      objectRequest,
                                                      expecteObjectClass)
        else:
            objectRequest = args[1]
            expecteObjectClass = requestClass
            ExceptionHandler.validateArgs(resourceInstance,
                                          resourceInstanceMethod,
                                          objectRequest, expecteObjectClass)