def decoApiCallWithoutArgs(methodAPI): """ Decorator for calling server methods without arguments """ # register methods without positional and optional arguments registerMethod(methodAPI.__name__) @wraps(methodAPI) def wrapperWithoutArgs(self): return self.callServerWithPosArgs(methodAPI.__name__) return wrapperWithoutArgs
def decoApiCallWithArgs(methodAPI): """ Decorator for calling a server method with arguments """ # register methods positional and optional arguments registerMethod(methodAPI.__name__, argNamesPositional, argNamesOptional) # define the method server call @wraps(methodAPI) def wrapperWithArgs(self, *argsPositional, **argsOptional): return self.callServerWithPosArgs(methodAPI.__name__, *argsPositional, **argsOptional) return wrapperWithArgs
def test_noWrapperName_decoApiCallAddAttachment(): " decorator test: original function name should be unchanged " registerMethod('orig_funcname5') @decoApiCallAddAttachment def orig_funcname5(a_api): "orig doc string5" return 'noArgs' assert 'orig_funcname5' == orig_funcname5.__name__ assert 'orig doc string5' == orig_funcname5.__doc__ assert 'testlinkdecorators_test' in orig_funcname5.__module__
def test_noWrapperName_decoApiCallAddDevKey(): " decorator test: original function name should be unchanged " registerMethod('orig_funcname3') @decoApiCallAddDevKey def orig_funcname3(a_api, *argsPositional, **argsOptional): "orig doc string3" return argsPositional, argsOptional assert 'orig_funcname3' == orig_funcname3.__name__ assert 'orig doc string3' == orig_funcname3.__doc__ assert 'testlinkdecorators_test' in orig_funcname3.__module__
def test_noWrapperName_decoApiCallAddDevKey(self): " decorator test: original function name should be unchanged " registerMethod('orig_funcname3') @decoApiCallAddDevKey def orig_funcname3(a_api, *argsPositional, **argsOptional): "orig doc string" return argsPositional, argsOptional self.assertEqual('orig_funcname3', orig_funcname3.__name__) self.assertEqual('orig doc string', orig_funcname3.__doc__) self.assertEqual('testlinkdecoratorstest', orig_funcname3.__module__)
def test_noWrapperName_decoApiCallAddAttachment(self): " decorator test: original function name should be unchanged " registerMethod('orig_funcname5') @decoApiCallAddAttachment def orig_funcname5(a_api): "orig doc string" return 'noArgs' self.assertEqual('orig_funcname5', orig_funcname5.__name__) self.assertEqual('orig doc string', orig_funcname5.__doc__) self.assertEqual('testlinkdecoratorstest', orig_funcname5.__module__)
def test_decoApiCallAddDevKey(dummy_api): " decorator test: argsOptional should be extended with devKey" registerMethod('a_func') @decoApiCallAddDevKey def a_func(a_api, *argsPositional, **argsOptional): return argsPositional, argsOptional # check method argument definition allArgs = getArgsForMethod('a_func') assert (['devKey'], []) == allArgs # check call arguments response = a_func(dummy_api) assert {'devKey' : dummy_api.devKey} == response[1]
def test_decoApiCallAddDevKey(self): " decorator test: argsOptional should be extended with devKey" registerMethod('a_func') @decoApiCallAddDevKey def a_func(a_api, *argsPositional, **argsOptional): return argsPositional, argsOptional # check method argument definition allArgs = getArgsForMethod('a_func') self.assertEqual((['devKey'], []), allArgs) # check call arguments response = a_func(self.api) self.assertEqual({'devKey' : self.api.devKey}, response[1])
def test_decoApiCallAddDevKey(self): " decorator test: argsOptional should be extended with devKey" registerMethod('a_func') @decoApiCallAddDevKey def a_func(a_api, *argsPositional, **argsOptional): return argsPositional, argsOptional # check method argument definition allArgs = getArgsForMethod('a_func') self.assertEqual((['devKey'], []), allArgs) # check call arguments response = a_func(self.api) self.assertEqual({'devKey': self.api.devKey}, response[1])
def test_decoApiCallAddAttachment(self): " decorator test: argsOptional should be extended attachment file infos" registerMethod('func_addAttachment') @decoApiCallAddAttachment def func_addAttachment(a_api, *argsPositional, **argsOptional): return argsPositional, argsOptional # check method argument definition allArgs = getArgsForMethod('func_addAttachment') self.assertEqual((['devKey'], ['attachmentfile']), allArgs) # check call arguments response = func_addAttachment(self.api, 'a_file') self.assertEqual({'devKey' : self.api.devKey, 'filename': 'name a_file', 'filetype': 'type a_file', 'content' : 'content a_file'}, response[1])
def test_decoApiCallAddAttachment(dummy_api): " decorator test: argsOptional should be extended attachment file infos" registerMethod('func_addAttachment') @decoApiCallAddAttachment def func_addAttachment(a_api, *argsPositional, **argsOptional): return argsPositional, argsOptional # check method argument definition allArgs = getArgsForMethod('func_addAttachment') assert (['devKey'], ['attachmentfile']) == allArgs # check call arguments response = func_addAttachment(dummy_api, 'a_file') assert response[1] == {'devKey' : dummy_api.devKey, 'filename': 'name a_file', 'filetype': 'type a_file', 'content' : 'content a_file'}