def create_issue(self, issue_type_id, project_id, summary, description): end_point = "rest/api/2/issue" payload = { "fields": { "project": { "id": project_id }, "summary": summary, "description": description, "issuetype": { "id": issue_type_id } } } response = requests.post(self.url + end_point, auth=(self.user, self.token), json=payload) if tools.is_json(response.text): # JSON RESPONSE: convert response to JSON json_result = json.loads(response.text) # PRINT RESPONSE: pretty print with 4 indent print(json.dumps(json_result, indent=4, sort_keys=True)) issue_key = jp.match1("key", json_result) issue_id = jp.match1("id", json_result) print(f"Issure create with key {issue_key} and ID {issue_id}") return issue_key, issue_id
def get_list_of_execution_by_cycle(self, cycle_id, project_id, version_id): end_point = 'executions/search/cycle/' canonical_path = f"GET&{self.RELATIVE_PATH}{end_point}{cycle_id}&projectId={project_id}&versionId={version_id}" token = self.jwt.generate_jwt(canonical_path) headers = { 'Authorization': f'JWT {token}', 'Content-Type': 'text/plain', 'zapiAccessKey': self.access_key } # Get List of Executions By Cycle print("Getting list of execution ID's by Cycle") raw_result = requests.get(self.ZAPI_CLOUD_URL + self.RELATIVE_PATH + end_point + cycle_id + '?versionId=' + version_id + '&projectId=' + project_id, headers=headers) assert raw_result.status_code == 200 if tools.is_json(raw_result.text): # JSON RESPONSE: convert response to JSON json_result = json.loads(raw_result.text) # PRINT RESPONSE: pretty print with 4 indent # print(json.dumps(json_result, indent=4, sort_keys=True)) # Getting Execution ID Lists execution_ids = jp.match("$.searchObjectList[*].execution.id", json_result) print(f"Execution ID's are {execution_ids}") return execution_ids
def get_create_issue_meta_data(self): end_point = '/rest/api/2/issue/createmeta' response = requests.get(self.url + end_point, auth=(self.user, self.token)) if tools.is_json(response.text): # JSON RESPONSE: convert response to JSON json_result = json.loads(response.text) # PRINT RESPONSE: pretty print with 4 indent print(json.dumps(json_result, indent=4, sort_keys=True))
def update_execution(self, execution_id, project_id, version_id, cycle_id, issue_id, status): end_point = 'execution/' canonical_path = f"PUT&{self.RELATIVE_PATH}{end_point}{execution_id}&" token = self.jwt.generate_jwt(canonical_path) headers = { 'Authorization': f'JWT {token}', 'Content-Type': 'application/json', 'zapiAccessKey': self.access_key } # REQUEST PAYLOAD: to update execution update_test = { 'status': { "id": status }, 'issueId': int(issue_id), 'projectId': int(project_id), 'versionId': int(version_id), 'cycleId': cycle_id } counter = 0 status_flag = 0 raw_result = None while status_flag != 200 and counter < 3: raw_result = requests.put(self.ZAPI_CLOUD_URL + self.RELATIVE_PATH + end_point + execution_id, headers=headers, json=update_test) status_flag = raw_result.status_code counter = counter + 1 # print(raw_result.text) if raw_result: if tools.is_json(raw_result.text): # JSON RESPONSE: convert response to JSON json_result = json.loads(raw_result.text) status_code = jp.match1("$.execution.status.id", json_result) assert status_code == status print("Test run updated successfully for issue id {}".format( issue_id)) # PRINT RESPONSE: pretty print with 4 indent # print(json.dumps(json_result, indent=4, sort_keys=True)) else: print("The request didn't run")
def get_issue_id_with_issue_name(self, issue_name): end_point = f"/rest/api/latest/issue/{issue_name}" response = requests.get(self.url + end_point, auth=(self.user, self.token)) assert response.status_code == 200 if tools.is_json(response.text): # JSON RESPONSE: convert response to JSON json_result = json.loads(response.text) # PRINT RESPONSE: pretty print with 4 indent # print(json.dumps(json_result, indent=4, sort_keys=True)) issue_id = jp.match1("id", json_result) print(f"Issue id for key {issue_name} is:{issue_id}") return issue_id
def get_issue_id_with_key(self, key): end_point = '/rest/api/2/search' response = requests.get(self.url + end_point, auth=(self.user, self.token)) assert response.status_code == 200 if tools.is_json(response.text): # JSON RESPONSE: convert response to JSON json_result = json.loads(response.text) # PRINT RESPONSE: pretty print with 4 indent # print(json.dumps(json_result, indent=4, sort_keys=True)) issue_id = jp.match1("$.issues[?(key='" + key + "')].id", json_result) print(f"Issue id for key {key} is:{issue_id}") return issue_id
def get_version_id_with_name(self, version_name, project_id): end_point = f"rest/api/2/project/{project_id}/version" response = requests.get(self.url + end_point, auth=(self.user, self.token)) assert response.status_code == 200 if tools.is_json(response.text): # JSON RESPONSE: convert response to JSON json_result = json.loads(response.text) # PRINT RESPONSE: pretty print with 4 indent # print(json.dumps(json_result, indent=4, sort_keys=True)) version_id = jp.match1( "$.values[?(name='" + version_name + "')].id", json_result) print(f"Version ID {version_id} with Name {version_name}") return version_id
def create_execution(self, issue_id, project_id, version_id, cycle_id, status=tools.Status.PASS.value): end_point = 'execution' canonical_path = f"POST&{self.RELATIVE_PATH}{end_point}&" token = self.jwt.generate_jwt(canonical_path) headers = { 'Authorization': f'JWT {token}', 'Content-Type': 'application/json', 'zapiAccessKey': self.access_key } # REQUEST PAYLOAD: to Create Execution create_execution = { 'status': { "id": status }, 'issueId': issue_id, 'projectId': int(project_id), 'versionId': int(version_id), 'cycleId': cycle_id } print("Creating Execution") raw_result = requests.post(self.ZAPI_CLOUD_URL + self.RELATIVE_PATH + end_point, headers=headers, json=create_execution) if tools.is_json(raw_result.text): json_result = json.loads(raw_result.text) print(json.dumps(json_result, indent=4, sort_keys=True)) return raw_result.json()