2020# this test works WITHOUT an online TestLink Server
2121# no calls are send to a TestLink Server
2222
23- import sys
23+ import sys , os . path
2424
2525if sys .version_info [0 ] == 2 and sys .version_info [1 ] == 6 :
2626 # py26 needs backport unittest2
@@ -665,8 +665,24 @@ def test_whatArgs_getLastExecutionResult(self):
665665 argsDescription = self .api .whatArgs ('getLastExecutionResult' )
666666 self .assertIn ('options=<options>' , argsDescription )
667667 self .assertIn ('getBugs' , argsDescription )
668+
669+ def test__getAttachmentArgs_textfile (self ):
670+ "py3 issue #39 TypeError: expected bytes-like object, not str"
671+ NEWATTACHMENT_PY = os .path .realpath (__file__ )
672+ # under py2, on windows text files should be open with 'r' mode and
673+ # binary files with 'rb'
674+ # see http://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
675+ # under py3, text files open with 'r' on windows makes problem
676+ # see https://github.com/lczub/TestLink-API-Python-client/issues/39
677+ a_file = open (NEWATTACHMENT_PY )
678+ args = self .api ._getAttachmentArgs (a_file )
679+ self .assertEqual ('testlinkapigeneric_offline_test.py' , args ['filename' ])
680+ self .assertEqual ('text/plain' , args ['filetype' ])
681+ self .assertIsNotNone (args ['content' ])
682+
683+
668684
669-
685+
670686if __name__ == "__main__" :
671687 #import sys;sys.argv = ['', 'Test.testName']
672688 unittest .main ()
0 commit comments