0

I have the curl command, but not sure about how to run that in python script.

curl -H "Content-Type: application/json" -u "username:password" -d '{ "name":"something" }' "https://xxxxxxxx"

I'm planning to use subprocess, but the api documents aren't very helpful.

Also does anyone know how to get the sectionId from testrail?

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
Khalil
  • 21
  • 1
  • 6

2 Answers2

1

Bill from TestRail here. You can find a link to our Python bindings here:

http://docs.gurock.com/testrail-api2/bindings-python

Regarding getting the section ID, you can use the get_sections method for a project/suite to return all the section details including IDs. You can find more info on that here:

http://docs.gurock.com/testrail-api2/reference-sections#get_sections

If you're looking for the section ID for a specific test case, you can get that from the get_case method.

billk
  • 11
  • 1
  • While these links may answer the question, it is better to include the essential parts of the answer here and provide the links for reference. Link-only answers can become invalid if the linked page changes. – Cleb Jul 08 '15 at 08:18
  • Yeah, I made it work using python bindings. Thank you! – Khalil Jul 08 '15 at 20:38
0

You probably want to use the requests package for this. The curl command translates to something like this:

import json
import requests

response = requests.post('https://xxxxxxxx',
                         data=json.dumps({'name': 'something'}),
                         headers={'Content-Type': 'application/json'},
                         auth=('username', 'password'))
response_data = response.json()

If you really want to use subprocess, you can do something like this:

import subprocess

curl_args = ['curl', '-H', 'Content-Type: application/json', '-u', 'username:password',
             '-d', '{ "name":"something" }', 'https://xxxxxxxx']
curl_output = subprocess.check_output(curl_args)

I consider the latter approach less "Pythonic".

augurar
  • 12,081
  • 6
  • 50
  • 65