lczub / TestLink-API-Python-client

A Python client to use the TestLink API
104 stars 63 forks source link

Error while updating test case if same test name already exists #138

Closed abhay2703 closed 3 years ago

abhay2703 commented 4 years ago

While updating test case if the test name already exists then API updateTestCase fails with the below error:

Traceback (most recent call last):
  File "E:/Abhay/Work/Python/TestlinkConnect/TestlinkTest.py", line 238, in <module>
    tc_import.addTCs()
  File "E:/Abhay/Work/Python/TestlinkConnect/TestlinkTest.py", line 58, in addTCs
    self.updateTC(TCData)
  File "E:/Abhay/Work/Python/TestlinkConnect/TestlinkTest.py", line 176, in updateTC
    self.myTestLink.updateTestCase(TCData['TLExtId'][1], testcasename=TCData['TCName'][1], summary=TCData['TCSummary'][1], steps=StepsList, preconditions=TCData['TCPreCondition'][1], executiontype=executionType)
  File "C:\Python38\lib\site-packages\testlink\testlinkdecorators.py", line 112, in wrapperAddDevKey
    return methodAPI(self, *argsPositional, **argsOptional)
  File "C:\Python38\lib\site-packages\testlink\testlinkdecorators.py", line 99, in wrapperWithArgs
    return self.callServerWithPosArgs(methodAPI.__name__, 
  File "C:\Python38\lib\site-packages\testlink\testlinkapigeneric.py", line 1584, in callServerWithPosArgs
    self._checkResponse(response, methodNameAPI, argsOptional) 
  File "C:\Python38\lib\site-packages\testlink\testlinkapigeneric.py", line 2165, in _checkResponse
    raise testlinkerrors.TLResponseError(
testlink.testlinkerrors.TLResponseError: (updateTestCase) - LOCALIZE: API_TESTCASE_SIBLING_WITH_SAME_NAME_EXISTS
updateTestCase({'testcasename': 'TC_443', 'summary': 'Verify the behavior of XYZ', 'steps': [{'step_number': 1, 'actions': 'Execute 1', 'expected_results': 'Expect 1', 'execution_type': 0}], 'preconditions': 'Preconsition 1', 'executiontype': 1, 'devKey': '01234567890', 'testcaseexternalid': 'TC-3877'})

Process finished with exit code 1

This check shouldn't be done before adding the test case itself? This will avoid adding the test case with same name and error can be handled at that instance, rather than handling at a later point during test case updation.

Regards, Abhay

lczub commented 4 years ago

Hello Abhay,

please don't forget, you are working with an API, not with full service all user interface. Improvements are welcome and feel free to add new service methods to TestlinkAPIClient.

If you add a pre check, you would have also to raise an exception like what you see currently. So what would be the benefit? You would run into the risk, that you define on the client different rules as the server uses. The API Client has no knowledge about internal server rules.

Better approach would be, that you surround your api calls with a try - except handling, .

Regards Luiko

abhay2703 commented 4 years ago

Dear Luiko,

Thanks for the prompt response.

That was a suggestion for consistency in API and server rules. But still your point is 100% valid that it has no real benefit.

And currently I am using try-except (as you suggested) to handle the error while updating test cases.

Thanks and Regards, Abhay