It's all about the answers!

Ask a question

Map Testcases in existing test plan in RQM using Python script

Priyaranjan Panda (11) | asked May 09, 3:06 a.m.
I have a test plan in RQM and only one testcase mapped.

My requirement :
I have test plan name & ID
Testcase name along with ID
I need to write a python script which will map testcases in particular test plan.

I wrote below code:

import requests
import base64
import os
import xml.etree.ElementTree as ET

cur_dir = os.path.dirname(os.path.realpath(__file__))
cert_path = os.path.join(cur_dir, 'Input', 'Certificate', 'GlobalRootCA_RQM.crt.crt')
# Define RQM API endpoint for updating test plans

# Define test case identifiers to be mapped to the test plan
test_case_identifiers = [

# Define the request payload
root = ET.Element("testPlan")
for identifier in test_case_identifiers:
    testcase = ET.SubElement(root, "testcase")
    ET.SubElement(testcase, "dc:identifier").text = identifier

ET.SubElement(root, "dc:title").text = "Smoke Test Plan 1"  # Update the title if needed

xml_payload = ET.tostring(root)

# Authenticate and make a PUT request to update the test plan
response = requests.put(update_test_plan_url, data=xml_payload, headers={"Content-Type": "application/xml"}, auth=("UserName", "Password"), verify=cert_path)

# Check if the request was successful
if response.status_code == 200:
    print("Test cases mapped successfully to the test plan")
    print("Failed to map test cases to the test plan")
    print("Response:", response.text)
I am getting response.status_code "200" and printing "Test cases mapped successfully to the test plan"  but no testcase mapped.

Note: in code I have updated actual UserName and password. 

Can you please suggest what modification required in code.

Ian Barnard commented May 09, 12:50 p.m. | edited May 09, 12:51 p.m.

Multiple possible problems:
1. You probably aren't authenticated - try GET (with header Accept: application/rdf+xml) from a protected resource like /qm/process/project-areas if you get HTML then you aren't authenticated.
2. Even if you are authenticated for the PUT if you need to continue with other operations use a requests session and then the authentication cookies will automatically be provided on subsequent operations.
3. to update a resource you most likely need to use header OSLC-Core-Version: 2.0 and also to provide the etag from previously GETting the resource

Be the first one to answer this question!

Register or to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.