2222
2323import unittest
2424from testlink .testlinkerrors import TLResponseError
25- from testlink .testlinkargs import registerMethod , getApiArgsForMethod
25+ from testlink .testlinkargs import registerMethod , getArgsForMethod
2626from testlink .testlinkdecorators import decoApiCallAddAttachment ,\
2727decoApiCallAddDevKey , decoApiCallWithoutArgs , \
2828decoMakerApiCallReplaceTLResponseError , decoMakerApiCallWithArgs
@@ -34,6 +34,13 @@ class testlinkdecoratorsTestCase(unittest.TestCase):
3434 devKey = '007'
3535 def setUp (self ):
3636 self .api = self
37+
38+ def _getAttachmentArgs (self , attachmentfile ):
39+ # simulation of TestlinkAPIGeneric._getAttachmentArgs()
40+ # needed in test_decoApiCallAddAttachment
41+ return {'filename' : 'name %s' % attachmentfile ,
42+ 'filetype' : 'type %s' % attachmentfile ,
43+ 'content' : 'content %s' % attachmentfile }
3744
3845# def tearDown(self):
3946# pass
@@ -60,7 +67,6 @@ def DummyMethod(a_api):
6067 pass
6168
6269 posArgs = getMethodsWithPositionalArgs ()
63- print posArgs
6470 self .assertEqual (['Uno' , 'due' , 'tre' ], posArgs ['DummyMethod' ])
6571
6672 def test_noWrapperName_decoApiCallWithArgs (self ):
@@ -84,8 +90,8 @@ def a_func(a_api, *argsPositional, **argsOptional):
8490 return argsPositional , argsOptional
8591
8692 # check method argument definition
87- allArgs = getApiArgsForMethod ('a_func' )
88- self .assertEqual (['devKey' ], allArgs )
93+ allArgs = getArgsForMethod ('a_func' )
94+ self .assertEqual (( ['devKey' ], []) , allArgs )
8995 # check call arguments
9096 response = a_func (self .api )
9197 self .assertEqual ({'devKey' : self .api .devKey }, response [1 ])
@@ -158,9 +164,27 @@ def orig_funcname4(a_api, *argsPositional, **argsOptional):
158164 self .assertEqual ('orig doc string' , orig_funcname4 .__doc__ )
159165 self .assertEqual ('testlinkdecoratorstest' , orig_funcname4 .__module__ )
160166
167+ def test_decoApiCallAddAttachment (self ):
168+ " decorator test: argsOptional should be extended attachment file infos"
169+
170+ registerMethod ('func_addAttachment' )
171+ @decoApiCallAddAttachment
172+ def func_addAttachment (a_api , * argsPositional , ** argsOptional ):
173+ return argsPositional , argsOptional
174+
175+ # check method argument definition
176+ allArgs = getArgsForMethod ('func_addAttachment' )
177+ self .assertEqual ((['devKey' ], ['attachmentfile' ]), allArgs )
178+ # check call arguments
179+ response = func_addAttachment (self .api , 'a_file' )
180+ self .assertEqual ({'devKey' : self .api .devKey , 'filename' : 'name a_file' ,
181+ 'filetype' : 'type a_file' , 'content' : 'content a_file' },
182+ response [1 ])
183+
161184 def test_noWrapperName_decoApiCallAddAttachment (self ):
162185 " decorator test: original function name should be unchanged "
163186
187+ registerMethod ('orig_funcname5' )
164188 @decoApiCallAddAttachment
165189 def orig_funcname5 (a_api ):
166190 "orig doc string"
0 commit comments