Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

Python testrail update_case API!


#1

Hi !

I have been using testrail apis for a little bit, but I have mostly scanned testcases and issued a lot of get api commands.

I have a need now to update certain testcase ids with a certain value in a custom field. Also, at a later time, I may have a need to update standard fields as well.

Can someone pls. share with me - how a sample code with - update_case API would look like, if I wanted to say update a case with id ‘444555’ with a ‘custom_reference’ field as ‘Auto infra support is unavailable and will be provided later.’

Sorry, if this question has been asked earlier on some other thread. I wasn’t able to find a response to my question and hence this post.

Thanks and regards,
Akshay


#2

Assuming you followed the python binding example of intializing:

client = APIClient("https://yourTestRail.host.name/")
client.user = your_username
client.password = your_password

Then the following would update the example case:

update_reference = {'custom_reference': 'Auto infra support is unavailable and will be provided later.'}
client.send_post('update_case/444555', update_reference)

It would probably be a good idea to wrap some exception handling around it, such as:

update_reference = {'custom_reference': 'Auto infra support is unavailable and will be provided later.'}
try:
    client.send_post('update_case/444555', update_reference)
except APIError as e:
    print("[ERROR] update_case API error: {0}".format(e))
except:
    print("[ERROR] Unexpected update_case error: ", sys.exc_info()[0], sys.exc_info()[1])

(I didn’t try this with my own instance, so I apologize for any syntax errors or typos.)