Unable to fetch and update custom field like test_environment, jira_tickets_raised$37 in JAMA via python

43 views Asked by At

I am trying to use Pyjama to fetch info for a test cycle - such as all test plans associated with a unique test cycle including all fields in each of the testcases like- test_environment, jira_tickets_raised$37 etc. but when I fetch it - I only get a few fields as output

{'id': 12680265, 'documentKey': 'CONN-TSTRN-138649', 'globalId': 'GID-8244217', 'itemType': 37, 'project': 109, 'createdDate': '2024-02-08T22:43:04.000+0000', 'modifiedDate': '2024-02-14T00:17:11.000+0000', 'lastActivityDate': '2024-02-14T00:17:11.000+0000', 'createdBy': 475, 'modifiedBy': 950, 'fields': {'documentKey': 'CONN-TSTRN-138649', 'globalId': 'GID-8244217', 'name': 'Verifying install start time when Ostree failed to download ', 'description': 'test', 'testPlan': 12680238, 'testCycle': 12680263, 'testRunSetName': 'Venkata_Bugs', 'testCase': 12669717, 'testRunSteps': [{'action': 'testtt', 'expectedResult': 'cdgd', 'notes': '<p>TCU-223087</p>', 'status': 'PASSED'}, {'action': '<p>2 .TEst it</p>', 'expectedResult': '<p>testing</p>', 'notes': ' ', 'status': 'PASSED'}, {'action': '<p>3 .Ok yes</p>', 'expectedResult': '<p>should generate Error code as FAILED TO DOWNLOAD</p>', 'notes': ' ', 'status': 'PASSED'}, {'action': '<p>4. Install start time set </p>', 'expectedResult': '<p>set install start time as there is no user start installation</p>', 'notes': ' ', 'status': 'PASSED'}], 'modifiedDate': '2024-02-14', 'testRunStatus': 'PASSED', 'project': 109, 'forcePassed': False, 'executionDate': '2024-02-14', 'gates_rtiv$37': False, 'gates_rtsv$37': False, 'smoke_test$37': False}, 'resources': {'self': {'allowed': ['GET', 'PUT', 'PATCH']}}, 'testCaseVersionNumber': 1, 'testCaseCurrentVersionNumber': 1, 'sortOrderFromTestGroup': 0, 'testGroup': [12680263, 37509], 'type': 'testruns'}

enter image description here

test_environment, jira tickets raised,software build number, build number etc. don't show up at all!

Here is my code:

import os
from py_jama_rest_client.client import JamaClient
import json

# Retrieve Jama API credentials from environment variables
jama_api_username = 's'
jama_api_password = 'v'

if not (jama_api_username and jama_api_password):
    raise ValueError("Jama API username and password must be provided as environment variables.")

# Jama Connect API base URL
base_url = 'https://abc.jamacloud.com'

# Project ID for which you want to retrieve test runs
project_id = "109"

# Test Cycle ID
test_cycle_id = 126808263  # Replace with the actual Test Cycle ID you want to retrieve

# Assignee ID for which you want to update test runs
assignee_id_to_update = 9570

# Initialize JamaClient
jama_client = JamaClient(host_domain=base_url, credentials=(jama_api_username, jama_api_password), oauth=True)

# Get information for a specific test cycle
test_cycle = jama_client.get_test_cycle(test_cycle_id)

# Print raw full data
print("Raw Full Data:")
print(json.dumps(test_cycle, indent=2))
print("\n")

# Print information about the test cycle
cycle_id = test_cycle["id"]
cycle_name = test_cycle["fields"]["name"]

# Get test runs for the test cycle
test_runs = jama_client.get_testruns(test_cycle_id)

# Print test cycle information
print(f"Test Cycle: {cycle_name} (ID: {cycle_id})\n")

# Update only the test runs assigned to the specified assignee
for test_run in test_runs:
    test_run_id = test_run["id"]
    print(f"Test Run:{test_run}")
    print(f"Test Run ID: {test_run_id}")
    print(json.dumps(test_run, indent=2))
    print("\n")

    # Extract and print name, description, and test run steps
    name = test_run["fields"]["name"]
    description = test_run["fields"]["description"]
    test_run_steps = test_run["fields"]["testRunSteps"]
    #jira = test_run["fields"]["jira_tickets_raised$37"] -- THIS FAILS!!!!!!!!!!!!!
    print(f"Name: {name}")
    print(f"Description: {description}\n")
    print(f"Jira:{jira}")
    print("Test Run Steps:")
    for i, step in enumerate(test_run_steps):
        action = step["action"].strip('<p>').strip('</p>')
        expected_result = step["expectedResult"].strip('<p>').strip('</p>')
        notes = step["notes"].strip('<p>').strip('</p>')
        status = step["status"].strip('<p>').strip('</p>')

        print(f"Step {i + 1}:")
        print(f"  Action: {action}")
        print(f"  Expected Result: {expected_result}")
        print(f"  Notes: {notes}\n")
        print(f"  Step: {step}\n")

    print("\n")
0

There are 0 answers