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

Auto add results to test cases


#1

Hi,

I get a list of testcase id’s into an array, then loop through this array to add test case id’s into an results array, like this:

for x testcase_ids:
result_details = '{“case_id”: ’ + str(x) + ‘,“status_id”: 1,“version”:“1.0”,“comment”:“test”}’
results.append(result_details)
result_list = ‘,’.join(results)
data = “{‘results’: [” + result_list + “]}”
print(data)

The output of ‘data’ looks like this:
“{‘results’: [{“case_id”: 101,“status_id”: 1,“version”:“1.0”,“comment”:“Test”},{“case_id”: 102,“status_id”: 1,“version”:“1.0”,“comment”:“Test”},{“case_id”: 103,“status_id”: 1,“version”:“1.0”,“comment”:“Test”}]}”

Which looks perfect to import into testrail via via __send_request(self, method, uri, data). But I get this error: {‘error’: ‘Invalid or incomplete JSON string in API request.’}

However, if I manually take the output of ‘data’ and assign it like this it imports into testrail perfectly:
data2 = {‘results’: [{“case_id”: 101,“status_id”: 1,“version”:“1.0”,“comment”:“Test”},{“case_id”: 102,“status_id”: 1,“version”:“1.0”,“comment”:“Test”},{“case_id”: 103,“status_id”: 1,“version”:“1.0”,“comment”:“Test”}]}

result = self.api.add_results_for_cases(run_id, data2) - Success!

So if i adjust my data string to:
data3 = {‘results’: “[” + result_list + “]”}

Add results fail again…
result = self.api.add_results_for_cases(run_id, data3)
Add results: {‘error’: ‘Field :results is not a valid array.’}

Thanks for an advice.

J.