Skip to content

Commit 282f7ab

Browse files
author
Luiko Czub
committed
api info reports also the python version #40
testlinkapigeneric.__str__ prompts now the python version as additional info minor additional enhancement for test and example, which works with text file attachments: replace *os.path.realpath(__file__)* with *os.path.join(os.path.dirname(__file__),fname.py* cause __file__ could be a compiled python file *.pyc, if the test run is repeated without changing the test code
1 parent d61db36 commit 282f7ab

File tree

6 files changed

+65
-28
lines changed

6 files changed

+65
-28
lines changed

example/TestLinkExample.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
from testlink import TestlinkAPIClient, TestLinkHelper
6060
from testlink.testlinkerrors import TLResponseError
6161
import sys, os.path
62+
from platform import python_version
6263

6364
# precondition a)
6465
# SERVER_URL and KEY are defined in environment
@@ -99,8 +100,8 @@
99100
NEWBUILD_A='%s' % myApiVersion
100101
NEWBUILD_B='%s' % myApiVersion
101102

102-
NEWATTACHMENT_PY= os.path.realpath(__file__)
103-
this_file_dirname=os.path.dirname(NEWATTACHMENT_PY)
103+
this_file_dirname=os.path.dirname(__file__)
104+
NEWATTACHMENT_PY= os.path.join(this_file_dirname, 'TestLinkExample.py')
104105
NEWATTACHMENT_PNG=os.path.join(this_file_dirname, 'PyGreat.png')
105106

106107
# Servers TestLink Version
@@ -163,8 +164,8 @@
163164
# else:
164165
# print "Error creating the project '%s': %s " % (NEWPROJECT,isOk)
165166
# sys.exit(-1)
166-
projInfo = 'Example created with Python API class %s in TL %s' % \
167-
( myApiVersion, myTLVersion )
167+
projInfo = 'Example created with Python API class %s (PY %s) in TL %s' % \
168+
( myApiVersion, python_version(), myTLVersion )
168169
newProject = myTestLink.createTestProject(NEWPROJECT, NEWPREFIX,
169170
notes=projInfo, active=1, public=1,
170171
options={'requirementsEnabled' : 0, 'testPriorityEnabled' : 1,

example/TestLinkExampleGenericApi.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from testlink import TestlinkAPIGeneric, TestLinkHelper
4949
from testlink.testlinkerrors import TLResponseError
5050
import sys, os.path
51+
from platform import python_version
5152

5253
# precondition a)
5354
# SERVER_URL and KEY are defined in environment
@@ -88,8 +89,8 @@
8889
NEWBUILD_A='%s' % myApiVersion
8990
NEWBUILD_B='%s' % myApiVersion
9091

91-
NEWATTACHMENT_PY= os.path.realpath(__file__)
92-
this_file_dirname=os.path.dirname(NEWATTACHMENT_PY)
92+
this_file_dirname=os.path.dirname(__file__)
93+
NEWATTACHMENT_PY= os.path.join(this_file_dirname, 'TestLinkExampleGenericApi.py')
9394
NEWATTACHMENT_PNG=os.path.join(this_file_dirname, 'PyGreat.png')
9495

9596
# Servers TestLink Version
@@ -133,8 +134,8 @@
133134
print("")
134135

135136
# Creates the project
136-
projInfo = 'Example created with Python API class %s in TL %s' % \
137-
( myApiVersion, myTLVersion )
137+
projInfo = 'Example created with Python API class %s (PY %s) in TL %s' % \
138+
( myApiVersion, python_version(), myTLVersion )
138139
newProject = myTestLink.createTestProject(NEWPROJECT, NEWPREFIX,
139140
notes=projInfo, active=1, public=1,
140141
options={'requirementsEnabled' : 1, 'testPriorityEnabled' : 1,

src/testlink/testlinkapigeneric.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
# ------------------------------------------------------------------------
1919

2020
import sys
21-
if sys.version_info[0] < 3:
21+
IS_PY3 = sys.version_info[0] < 3
22+
if IS_PY3:
2223
import xmlrpclib
2324
else:
2425
import xmlrpc.client as xmlrpclib
26+
from platform import python_version
27+
2528
from . import testlinkerrors
2629
from .testlinkhelper import TestLinkHelper, VERSION
2730
from .testlinkargs import getMethodsWithPositionalArgs, getArgsForMethod
@@ -1363,11 +1366,12 @@ def connectionInfo(self):
13631366

13641367
def __str__(self):
13651368
message = """
1366-
TestLink API - class %s - version %s
1369+
TestLink API - class %s - version %s (PY %s)
13671370
@authors: %s
13681371
%s
13691372
"""
1370-
return message % (self.__class__.__name__, self.__version__,
1373+
return message % (self.__class__.__name__, self.__version__,
1374+
python_version(),
13711375
self.__author__, self.connectionInfo())
13721376

13731377

test/utest-offline/testlinkapigeneric_offline_test.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@
189189
}
190190
}
191191

192+
# example text file attachment = this python file
193+
# why not using os.path.realpath(__file__)
194+
# -> cause __file__ could be compiled python file *.pyc, if the test run is
195+
# repeated without changing the test code
196+
ATTACHMENT_EXAMPLE_TEXT= os.path.join(os.path.dirname(__file__),
197+
'testlinkapigeneric_offline_test.py')
198+
192199

193200
class DummyAPIGeneric(TestlinkAPIGeneric):
194201
""" Dummy for Simulation TestLinkAPIGeneric.
@@ -668,21 +675,33 @@ def test_whatArgs_getLastExecutionResult(self):
668675

669676
def test__getAttachmentArgs_textfile(self):
670677
"py3 issue #39 TypeError: expected bytes-like object, not str"
671-
NEWATTACHMENT_PY= os.path.realpath(__file__)
672678
# under py2, on windows text files should be open with 'r' mode and
673679
# binary files with 'rb'
674680
# see http://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
675681
# under py3, text files open with 'r' on windows makes problem
676682
# see https://github.com/lczub/TestLink-API-Python-client/issues/39
677-
a_file=open(NEWATTACHMENT_PY)
683+
a_file=open(ATTACHMENT_EXAMPLE_TEXT)
678684
args = self.api._getAttachmentArgs(a_file)
685+
# repeating this test failed in second run, cause filename is then
686+
# 'testlinkapigeneric_offline_test.pyc'
679687
self.assertEqual('testlinkapigeneric_offline_test.py', args['filename'])
680-
# filetype is also os depended, either 'text/plain' or 'text/x-pyth0n'
688+
# filetype is also OS depended, either 'text/plain' or 'text/x-python'
681689
self.assertIn('text/', args['filetype'])
682690
self.assertIsNotNone(args['content'])
683691

684-
685-
692+
# def test__getAttachmentArgs_filepath(self):
693+
# "enhancement #40 handle file patch instead file object"
694+
# args = self.api._getAttachmentArgs(ATTACHMENT_EXAMPLE_TEXT)
695+
# self.assertEqual('testlinkapigeneric_offline_test.py', args['filename'])
696+
# # filetype is also OS depended, either 'text/plain' or 'text/x-python'
697+
# self.assertIn('text/', args['filetype'])
698+
# self.assertIsNotNone(args['content'])
699+
700+
def test___str__pyversion(self):
701+
self.api.loadScenario(SCENARIO_TL199)
702+
api_info = self.api.__str__()
703+
py_info = '(PY %i.' % sys.version_info[0]
704+
self.assertIn(py_info, api_info)
686705

687706
if __name__ == "__main__":
688707
#import sys;sys.argv = ['', 'Test.testName']

test/utest-online/testlinkapi_generic_online_test.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
from testlink import TestlinkAPIGeneric, TestLinkHelper
4848
from testlink.testlinkerrors import TLResponseError
4949

50+
# example text file attachment = this python file
51+
# why not using os.path.realpath(__file__)
52+
# -> cause __file__ could be compiled python file *.pyc, if the test run is
53+
# repeated without changing the test code
54+
ATTACHMENT_EXAMPLE_TEXT= os.path.join(os.path.dirname(__file__),
55+
'testlinkapi_generic_online_test.py')
5056

5157
class TestLinkAPIOnlineTestCase(unittest.TestCase):
5258
""" TestCases for TestlinkAPIClient - interacts with a TestLink Server.
@@ -241,37 +247,37 @@ def test_deleteTestCaseSteps_unknownID(self):
241247
self.client.deleteTestCaseSteps('N-4711', steps, version=1)
242248

243249
def test_uploadRequirementSpecificationAttachment_unknownID(self):
244-
attachemantFile = open(os.path.realpath(__file__), 'r')
250+
attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
245251
with self.assertRaisesRegex(TLResponseError, '6004.*4712'):
246252
self.client.uploadRequirementSpecificationAttachment(attachemantFile, 4712,
247253
title='title 4713', description='descr. 4714')
248254

249255
def test_uploadRequirementAttachment_unknownID(self):
250-
attachemantFile = open(os.path.realpath(__file__), 'r')
256+
attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
251257
with self.assertRaisesRegex(TLResponseError, '6004.*4712'):
252258
self.client.uploadRequirementAttachment(attachemantFile, 4712,
253259
title='title 4713', description='descr. 4714')
254260

255261
def test_uploadTestProjectAttachment_unknownID(self):
256-
attachemantFile = open(os.path.realpath(__file__), 'r')
262+
attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
257263
with self.assertRaisesRegex(TLResponseError, '7000.*4712'):
258264
self.client.uploadTestProjectAttachment(attachemantFile, 4712,
259265
title='title 4713', description='descr. 4714')
260266

261267
def test_uploadTestSuiteAttachment_unknownID(self):
262-
attachemantFile = open(os.path.realpath(__file__), 'r')
268+
attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
263269
with self.assertRaisesRegex(TLResponseError, '8000.*4712'):
264270
self.client.uploadTestSuiteAttachment(attachemantFile, 4712,
265271
title='title 4713', description='descr. 4714')
266272

267273
def test_uploadTestCaseAttachment_unknownID(self):
268-
attachemantFile = open(os.path.realpath(__file__), 'r')
274+
attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
269275
with self.assertRaisesRegex(TLResponseError, '5000.*testcaseid'):
270276
self.client.uploadTestCaseAttachment(attachemantFile, 4712,
271277
title='title 4713', description='descr. 4714')
272278

273279
def test_uploadAttachment_unknownID(self):
274-
attachemantFile = open(os.path.realpath(__file__), 'r')
280+
attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
275281
with self.assertRaisesRegex(TLResponseError, '6004.*4712'):
276282
self.client.uploadAttachment(attachemantFile, 4712, 'nodes_hierarchy',
277283
title='title 4713', description='descr. 4714')

test/utest-online/testlinkapi_online_test.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
from testlink import TestlinkAPIClient, TestLinkHelper
4747
from testlink.testlinkerrors import TLResponseError
4848

49+
# example text file attachment = this python file
50+
# why not using os.path.realpath(__file__)
51+
# -> cause __file__ could be compiled python file *.pyc, if the test run is
52+
# repeated without changing the test code
53+
ATTACHMENT_EXAMPLE_TEXT= os.path.join(os.path.dirname(__file__),
54+
'testlinkapi_online_test.py')
4955

5056
class TestLinkAPIOnlineTestCase(unittest.TestCase):
5157
""" TestCases for TestlinkAPIClient - interacts with a TestLink Server.
@@ -231,37 +237,37 @@ def test_deleteTestCaseSteps_unknownID(self):
231237
self.client.deleteTestCaseSteps('N-4711', steps, version=1)
232238

233239
def test_uploadRequirementSpecificationAttachment_unknownID(self):
234-
attachemantFile = open(os.path.realpath(__file__), 'r')
240+
attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
235241
with self.assertRaisesRegex(TLResponseError, '6004.*4712'):
236242
self.client.uploadRequirementSpecificationAttachment(attachemantFile, 4712,
237243
title='title 4713', description='descr. 4714')
238244

239245
def test_uploadRequirementAttachment_unknownID(self):
240-
attachemantFile = open(os.path.realpath(__file__), 'r')
246+
attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
241247
with self.assertRaisesRegex(TLResponseError, '6004.*4712'):
242248
self.client.uploadRequirementAttachment(attachemantFile, 4712,
243249
title='title 4713', description='descr. 4714')
244250

245251
def test_uploadTestProjectAttachment_unknownID(self):
246-
attachemantFile = open(os.path.realpath(__file__), 'r')
252+
attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
247253
with self.assertRaisesRegex(TLResponseError, '7000.*4712'):
248254
self.client.uploadTestProjectAttachment(attachemantFile, 4712,
249255
title='title 4713', description='descr. 4714')
250256

251257
def test_uploadTestSuiteAttachment_unknownID(self):
252-
attachemantFile = open(os.path.realpath(__file__), 'r')
258+
attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
253259
with self.assertRaisesRegex(TLResponseError, '8000.*4712'):
254260
self.client.uploadTestSuiteAttachment(attachemantFile, 4712,
255261
title='title 4713', description='descr. 4714')
256262

257263
def test_uploadTestCaseAttachment_unknownID(self):
258-
attachemantFile = open(os.path.realpath(__file__), 'r')
264+
attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
259265
with self.assertRaisesRegex(TLResponseError, '5000.*testcaseid'):
260266
self.client.uploadTestCaseAttachment(attachemantFile, 4712,
261267
title='title 4713', description='descr. 4714')
262268

263269
def test_uploadAttachment_unknownID(self):
264-
attachemantFile = open(os.path.realpath(__file__), 'r')
270+
attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
265271
with self.assertRaisesRegex(TLResponseError, '6004.*4712'):
266272
self.client.uploadAttachment(attachemantFile, 4712, 'nodes_hierarchy',
267273
title='title 4713', description='descr. 4714')

0 commit comments

Comments
 (0)