def handleAdditionalResponseHeadersIfNeeded(completeResponse): # log.log(handleAdditionalResponseHeadersIfNeeded, f'Complete response: {completeResponse}') if ObjectHelper.isTuple(completeResponse): if 3 == len(completeResponse): if ObjectHelper.isTuple(completeResponse[0]): ###- ((serviceResponse, serviceHeader), controllerHeader, status) return completeResponse[0][0], { **completeResponse[1][0], **completeResponse[0][1] }, completeResponse[1][1] return completeResponse elif 2 == len(completeResponse): if ObjectHelper.isTuple(completeResponse[0]) and 2 == len( completeResponse[0]): ###- ((serviceResponse, serviceHeader), status) return completeResponse[0][0], completeResponse[0][ 1], completeResponse[1] elif ObjectHelper.isTuple(completeResponse[1]) and 2 == len( completeResponse[1]): ###- (serviceResponse, (serviceHeader, status)) --> this case should never happens return completeResponse[0], completeResponse[1][ 0], completeResponse[1][1] else: ###- (serviceResponse, status) --> missing header return completeResponse[0], dict(), completeResponse[1] elif ObjectHelper.isList(completeResponse) and 2 == len(completeResponse): ###- it can only be guessed at this point ###- (serviceResponse, status) --> missing header return completeResponse[0], dict(), completeResponse[1] ###- totally lost at this point return completeResponse
def innerResourceInstanceMethod(*args, **kwargs): resourceInstance = args[0] completeResponse = None try: FlaskManager.validateArgs(args, requestClass, resourceInstanceMethod) completeResponse = resourceInstanceMethod(*args, **kwargs) ###- This simple client cannot handle headers or anything this much elegant if ObjectHelper.isTuple( completeResponse) and 0 < len(completeResponse): completeResponse = completeResponse[0] except Exception as exception: log.log(innerResourceInstanceMethod, 'Failure at client method execution', exception=exception, muteStackTrace=True) raise exception return completeResponse
def isPythonFrameworkHttpsResponse(controllerResponse): return (ObjectHelper.isTuple(controllerResponse) or ObjectHelper.isList(controllerResponse) ) and 2 == len(controllerResponse)
def basicMethods(): # arrange def generatorInstance(): while True: yield False break STR_INSTANCE = str() BOOLEAN_INSTANCE = bool() INTEGER_INSTANCE = int() FLOAT_INSTANCE = float() DICTIONARY_INSTANCE = dict() LIST_INSTANCE = list() TUPLE_INSTANCE = tuple() SET_INSTANCE = set() GENERATOR_INSTANCE = generatorInstance() STR_FILLED_INSTANCE = 'str()' BOOLEAN_FILLED_INSTANCE = True INTEGER_FILLED_INSTANCE = 2 FLOAT_FILLED_INSTANCE = 3.3 DICTIONARY_FILLED_INSTANCE = {'dict()': dict()} LIST_FILLED_INSTANCE = [list(), list()] TUPLE_FILLED_INSTANCE = (tuple(), tuple()) SET_FILLED_INSTANCE = {'set()', 2} # act # assert assert ObjectHelper.isNotNone(STR_INSTANCE) assert ObjectHelper.isNotNone(BOOLEAN_INSTANCE) assert ObjectHelper.isNotNone(INTEGER_INSTANCE) assert ObjectHelper.isNotNone(FLOAT_INSTANCE) assert ObjectHelper.isNotNone(DICTIONARY_INSTANCE) assert ObjectHelper.isNotNone(LIST_INSTANCE) assert ObjectHelper.isNotNone(TUPLE_INSTANCE) assert ObjectHelper.isNotNone(SET_INSTANCE) assert ObjectHelper.isNotNone(GENERATOR_INSTANCE) assert ObjectHelper.isNotNone(STR_FILLED_INSTANCE) assert ObjectHelper.isNotNone(BOOLEAN_FILLED_INSTANCE) assert ObjectHelper.isNotNone(INTEGER_FILLED_INSTANCE) assert ObjectHelper.isNotNone(FLOAT_FILLED_INSTANCE) assert ObjectHelper.isNotNone(DICTIONARY_FILLED_INSTANCE) assert ObjectHelper.isNotNone(LIST_FILLED_INSTANCE) assert ObjectHelper.isNotNone(TUPLE_FILLED_INSTANCE) assert ObjectHelper.isNotNone(SET_FILLED_INSTANCE) assert not ObjectHelper.isNone(STR_FILLED_INSTANCE) assert not ObjectHelper.isNone(BOOLEAN_FILLED_INSTANCE) assert not ObjectHelper.isNone(INTEGER_FILLED_INSTANCE) assert not ObjectHelper.isNone(FLOAT_FILLED_INSTANCE) assert not ObjectHelper.isNone(DICTIONARY_FILLED_INSTANCE) assert not ObjectHelper.isNone(LIST_FILLED_INSTANCE) assert not ObjectHelper.isNone(TUPLE_FILLED_INSTANCE) assert not ObjectHelper.isNone(SET_FILLED_INSTANCE) assert not ObjectHelper.isNone(GENERATOR_INSTANCE) assert not ObjectHelper.isList(STR_FILLED_INSTANCE) assert not ObjectHelper.isList(BOOLEAN_FILLED_INSTANCE) assert not ObjectHelper.isList(INTEGER_FILLED_INSTANCE) assert not ObjectHelper.isList(FLOAT_FILLED_INSTANCE) assert not ObjectHelper.isList(DICTIONARY_FILLED_INSTANCE) assert ObjectHelper.isList(LIST_FILLED_INSTANCE) assert not ObjectHelper.isList(TUPLE_FILLED_INSTANCE) assert not ObjectHelper.isList(SET_FILLED_INSTANCE) assert not ObjectHelper.isList(GENERATOR_INSTANCE) assert ObjectHelper.isNotList(STR_FILLED_INSTANCE) assert ObjectHelper.isNotList(BOOLEAN_FILLED_INSTANCE) assert ObjectHelper.isNotList(INTEGER_FILLED_INSTANCE) assert ObjectHelper.isNotList(FLOAT_FILLED_INSTANCE) assert ObjectHelper.isNotList(DICTIONARY_FILLED_INSTANCE) assert not ObjectHelper.isNotList(LIST_FILLED_INSTANCE) assert ObjectHelper.isNotList(TUPLE_FILLED_INSTANCE) assert ObjectHelper.isNotList(SET_FILLED_INSTANCE) assert ObjectHelper.isNotList(GENERATOR_INSTANCE) assert not ObjectHelper.isSet(STR_FILLED_INSTANCE) assert not ObjectHelper.isSet(BOOLEAN_FILLED_INSTANCE) assert not ObjectHelper.isSet(INTEGER_FILLED_INSTANCE) assert not ObjectHelper.isSet(FLOAT_FILLED_INSTANCE) assert not ObjectHelper.isSet(DICTIONARY_FILLED_INSTANCE) assert not ObjectHelper.isSet(LIST_FILLED_INSTANCE) assert not ObjectHelper.isSet(TUPLE_FILLED_INSTANCE) assert ObjectHelper.isSet(SET_FILLED_INSTANCE) assert not ObjectHelper.isSet(GENERATOR_INSTANCE) assert ObjectHelper.isNotSet(STR_FILLED_INSTANCE) assert ObjectHelper.isNotSet(BOOLEAN_FILLED_INSTANCE) assert ObjectHelper.isNotSet(INTEGER_FILLED_INSTANCE) assert ObjectHelper.isNotSet(FLOAT_FILLED_INSTANCE) assert ObjectHelper.isNotSet(DICTIONARY_FILLED_INSTANCE) assert ObjectHelper.isNotSet(LIST_FILLED_INSTANCE) assert ObjectHelper.isNotSet(TUPLE_FILLED_INSTANCE) assert not ObjectHelper.isNotSet(SET_FILLED_INSTANCE) assert ObjectHelper.isNotSet(GENERATOR_INSTANCE) assert not ObjectHelper.isTuple(STR_FILLED_INSTANCE) assert not ObjectHelper.isTuple(BOOLEAN_FILLED_INSTANCE) assert not ObjectHelper.isTuple(INTEGER_FILLED_INSTANCE) assert not ObjectHelper.isTuple(FLOAT_FILLED_INSTANCE) assert not ObjectHelper.isTuple(DICTIONARY_FILLED_INSTANCE) assert not ObjectHelper.isTuple(LIST_FILLED_INSTANCE) assert ObjectHelper.isTuple(TUPLE_FILLED_INSTANCE) assert not ObjectHelper.isTuple(SET_FILLED_INSTANCE) assert not ObjectHelper.isTuple(GENERATOR_INSTANCE) assert ObjectHelper.isNotTuple(STR_FILLED_INSTANCE) assert ObjectHelper.isNotTuple(BOOLEAN_FILLED_INSTANCE) assert ObjectHelper.isNotTuple(INTEGER_FILLED_INSTANCE) assert ObjectHelper.isNotTuple(FLOAT_FILLED_INSTANCE) assert ObjectHelper.isNotTuple(DICTIONARY_FILLED_INSTANCE) assert ObjectHelper.isNotTuple(LIST_FILLED_INSTANCE) assert not ObjectHelper.isNotTuple(TUPLE_FILLED_INSTANCE) assert ObjectHelper.isNotTuple(SET_FILLED_INSTANCE) assert ObjectHelper.isNotTuple(GENERATOR_INSTANCE) assert not ObjectHelper.isDictionary(STR_FILLED_INSTANCE) assert not ObjectHelper.isDictionary(BOOLEAN_FILLED_INSTANCE) assert not ObjectHelper.isDictionary(INTEGER_FILLED_INSTANCE) assert not ObjectHelper.isDictionary(FLOAT_FILLED_INSTANCE) assert ObjectHelper.isDictionary(DICTIONARY_FILLED_INSTANCE) assert not ObjectHelper.isDictionary(LIST_FILLED_INSTANCE) assert not ObjectHelper.isDictionary(TUPLE_FILLED_INSTANCE) assert not ObjectHelper.isDictionary(SET_FILLED_INSTANCE) assert not ObjectHelper.isDictionary(GENERATOR_INSTANCE) assert ObjectHelper.isNotDictionary(STR_FILLED_INSTANCE) assert ObjectHelper.isNotDictionary(BOOLEAN_FILLED_INSTANCE) assert ObjectHelper.isNotDictionary(INTEGER_FILLED_INSTANCE) assert ObjectHelper.isNotDictionary(FLOAT_FILLED_INSTANCE) assert not ObjectHelper.isNotDictionary(DICTIONARY_FILLED_INSTANCE) assert ObjectHelper.isNotDictionary(LIST_FILLED_INSTANCE) assert ObjectHelper.isNotDictionary(TUPLE_FILLED_INSTANCE) assert ObjectHelper.isNotDictionary(SET_FILLED_INSTANCE) assert ObjectHelper.isNotDictionary(GENERATOR_INSTANCE) assert not ObjectHelper.isCollection(STR_FILLED_INSTANCE) assert not ObjectHelper.isCollection(BOOLEAN_FILLED_INSTANCE) assert not ObjectHelper.isCollection(INTEGER_FILLED_INSTANCE) assert not ObjectHelper.isCollection(FLOAT_FILLED_INSTANCE) assert ObjectHelper.isCollection(DICTIONARY_FILLED_INSTANCE) assert ObjectHelper.isCollection(LIST_FILLED_INSTANCE) assert ObjectHelper.isCollection(TUPLE_FILLED_INSTANCE) assert ObjectHelper.isCollection(SET_FILLED_INSTANCE) assert not ObjectHelper.isCollection(GENERATOR_INSTANCE) assert ObjectHelper.isNotCollection(STR_FILLED_INSTANCE) assert ObjectHelper.isNotCollection(BOOLEAN_FILLED_INSTANCE) assert ObjectHelper.isNotCollection(INTEGER_FILLED_INSTANCE) assert ObjectHelper.isNotCollection(FLOAT_FILLED_INSTANCE) assert not ObjectHelper.isNotCollection(DICTIONARY_FILLED_INSTANCE) assert not ObjectHelper.isNotCollection(LIST_FILLED_INSTANCE) assert not ObjectHelper.isNotCollection(TUPLE_FILLED_INSTANCE) assert not ObjectHelper.isNotCollection(SET_FILLED_INSTANCE) assert ObjectHelper.isNotCollection(GENERATOR_INSTANCE) assert not ObjectHelper.isDictionaryClass(STR_FILLED_INSTANCE) assert not ObjectHelper.isDictionaryClass(BOOLEAN_FILLED_INSTANCE) assert not ObjectHelper.isDictionaryClass(INTEGER_FILLED_INSTANCE) assert not ObjectHelper.isDictionaryClass(FLOAT_FILLED_INSTANCE) assert not ObjectHelper.isDictionaryClass(DICTIONARY_FILLED_INSTANCE) assert not ObjectHelper.isDictionaryClass(LIST_FILLED_INSTANCE) assert not ObjectHelper.isDictionaryClass(TUPLE_FILLED_INSTANCE) assert not ObjectHelper.isDictionaryClass(SET_FILLED_INSTANCE) assert not ObjectHelper.isDictionaryClass(GENERATOR_INSTANCE) assert ObjectHelper.isNotDictionaryClass(STR_FILLED_INSTANCE) assert ObjectHelper.isNotDictionaryClass(BOOLEAN_FILLED_INSTANCE) assert ObjectHelper.isNotDictionaryClass(INTEGER_FILLED_INSTANCE) assert ObjectHelper.isNotDictionaryClass(FLOAT_FILLED_INSTANCE) assert ObjectHelper.isNotDictionaryClass(DICTIONARY_FILLED_INSTANCE) assert ObjectHelper.isNotDictionaryClass(LIST_FILLED_INSTANCE) assert ObjectHelper.isNotDictionaryClass(TUPLE_FILLED_INSTANCE) assert ObjectHelper.isNotDictionaryClass(SET_FILLED_INSTANCE) assert ObjectHelper.isNotDictionaryClass(GENERATOR_INSTANCE) assert not ObjectHelper.isDictionaryClass(type(STR_FILLED_INSTANCE)) assert not ObjectHelper.isDictionaryClass(type(BOOLEAN_FILLED_INSTANCE)) assert not ObjectHelper.isDictionaryClass(type(INTEGER_FILLED_INSTANCE)) assert not ObjectHelper.isDictionaryClass(type(FLOAT_FILLED_INSTANCE)) assert ObjectHelper.isDictionaryClass(type(DICTIONARY_FILLED_INSTANCE)) assert not ObjectHelper.isDictionaryClass(type(LIST_FILLED_INSTANCE)) assert not ObjectHelper.isDictionaryClass(type(TUPLE_FILLED_INSTANCE)) assert not ObjectHelper.isDictionaryClass(type(SET_FILLED_INSTANCE)) assert not ObjectHelper.isDictionaryClass(type(GENERATOR_INSTANCE)) assert ObjectHelper.isNotDictionaryClass(type(STR_FILLED_INSTANCE)) assert ObjectHelper.isNotDictionaryClass(type(BOOLEAN_FILLED_INSTANCE)) assert ObjectHelper.isNotDictionaryClass(type(INTEGER_FILLED_INSTANCE)) assert ObjectHelper.isNotDictionaryClass(type(FLOAT_FILLED_INSTANCE)) assert not ObjectHelper.isNotDictionaryClass( type(DICTIONARY_FILLED_INSTANCE)) assert ObjectHelper.isNotDictionaryClass(type(LIST_FILLED_INSTANCE)) assert ObjectHelper.isNotDictionaryClass(type(TUPLE_FILLED_INSTANCE)) assert ObjectHelper.isNotDictionaryClass(type(SET_FILLED_INSTANCE)) assert ObjectHelper.isNotDictionaryClass(type(GENERATOR_INSTANCE)) assert ObjectHelper.isNativeClass(type(STR_FILLED_INSTANCE)) assert ObjectHelper.isNativeClass(type(BOOLEAN_FILLED_INSTANCE)) assert ObjectHelper.isNativeClass(type(INTEGER_FILLED_INSTANCE)) assert ObjectHelper.isNativeClass(type(FLOAT_FILLED_INSTANCE)) assert not ObjectHelper.isNativeClass(type(DICTIONARY_FILLED_INSTANCE)) assert not ObjectHelper.isNativeClass(type(LIST_FILLED_INSTANCE)) assert not ObjectHelper.isNativeClass(type(TUPLE_FILLED_INSTANCE)) assert not ObjectHelper.isNativeClass(type(SET_FILLED_INSTANCE)) assert ObjectHelper.isNativeClass(type(GENERATOR_INSTANCE)) assert not ObjectHelper.isNotNativeClass(type(STR_FILLED_INSTANCE)) assert not ObjectHelper.isNotNativeClass(type(BOOLEAN_FILLED_INSTANCE)) assert not ObjectHelper.isNotNativeClass(type(INTEGER_FILLED_INSTANCE)) assert not ObjectHelper.isNotNativeClass(type(FLOAT_FILLED_INSTANCE)) assert ObjectHelper.isNotNativeClass(type(DICTIONARY_FILLED_INSTANCE)) assert ObjectHelper.isNotNativeClass(type(LIST_FILLED_INSTANCE)) assert ObjectHelper.isNotNativeClass(type(TUPLE_FILLED_INSTANCE)) assert ObjectHelper.isNotNativeClass(type(SET_FILLED_INSTANCE)) assert not ObjectHelper.isNotNativeClass(type(GENERATOR_INSTANCE)) assert ObjectHelper.isNativeClassInstance(STR_FILLED_INSTANCE) assert ObjectHelper.isNativeClassInstance(BOOLEAN_FILLED_INSTANCE) assert ObjectHelper.isNativeClassInstance(INTEGER_FILLED_INSTANCE) assert ObjectHelper.isNativeClassInstance(FLOAT_FILLED_INSTANCE) assert not ObjectHelper.isNativeClassInstance(DICTIONARY_FILLED_INSTANCE) assert not ObjectHelper.isNativeClassInstance(LIST_FILLED_INSTANCE) assert not ObjectHelper.isNativeClassInstance(TUPLE_FILLED_INSTANCE) assert not ObjectHelper.isNativeClassInstance(SET_FILLED_INSTANCE) assert ObjectHelper.isNativeClassInstance(GENERATOR_INSTANCE) assert not ObjectHelper.isNotNativeClassIsntance(STR_FILLED_INSTANCE) assert not ObjectHelper.isNotNativeClassIsntance(BOOLEAN_FILLED_INSTANCE) assert not ObjectHelper.isNotNativeClassIsntance(INTEGER_FILLED_INSTANCE) assert not ObjectHelper.isNotNativeClassIsntance(FLOAT_FILLED_INSTANCE) assert ObjectHelper.isNotNativeClassIsntance(DICTIONARY_FILLED_INSTANCE) assert ObjectHelper.isNotNativeClassIsntance(LIST_FILLED_INSTANCE) assert ObjectHelper.isNotNativeClassIsntance(TUPLE_FILLED_INSTANCE) assert ObjectHelper.isNotNativeClassIsntance(SET_FILLED_INSTANCE) assert not ObjectHelper.isNotNativeClassIsntance(GENERATOR_INSTANCE) assert ObjectHelper.isNone(None) assert not ObjectHelper.isNotNone(None) assert not ObjectHelper.isList(None) assert ObjectHelper.isNotList(None) assert not ObjectHelper.isSet(None) assert ObjectHelper.isNotSet(None) assert not ObjectHelper.isTuple(None) assert ObjectHelper.isNotTuple(None) assert not ObjectHelper.isDictionary(None) assert ObjectHelper.isNotDictionary(None) assert not ObjectHelper.isCollection(None) assert ObjectHelper.isNotCollection(None) assert not ObjectHelper.isDictionaryClass(None) assert ObjectHelper.isNotDictionaryClass(None) assert not ObjectHelper.isNativeClass(None) assert ObjectHelper.isNotNativeClass(None) assert not ObjectHelper.isNativeClassInstance(None) assert ObjectHelper.isNotNativeClassIsntance(None) assert not ObjectHelper.isNone(type(None)) assert ObjectHelper.isNotNone(type(None)) assert not ObjectHelper.isList(type(None)) assert ObjectHelper.isNotList(type(None)) assert not ObjectHelper.isDictionary(type(None)) assert ObjectHelper.isNotDictionary(type(None)) assert not ObjectHelper.isCollection(type(None)) assert ObjectHelper.isNotCollection(type(None)) assert not ObjectHelper.isDictionaryClass(type(None)) assert ObjectHelper.isNotDictionaryClass(type(None)) assert not ObjectHelper.isNativeClass(type(None)) assert ObjectHelper.isNotNativeClass(type(None)) assert not ObjectHelper.isNativeClassInstance(type(None)) assert ObjectHelper.isNotNativeClassIsntance(type(None))
def isPythonFrameworkHttpsResponseBody(completeResponse): return (ObjectHelper.isTuple(completeResponse)) and ( 3 == len(completeResponse)) and (isinstance( completeResponse[1], dict)) and (isinstance(completeResponse[-1], EnumItem) or isinstance(completeResponse[-1], int))