How to use test_plan_details method in Kiwi

Best Python code snippet using Kiwi_python

jira_api.py

Source:jira_api.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""Common functions used while generating engineering and executive csv reports."""3#4# Copyright (c) 2022 Seagate Technology LLC and/or its Affiliates5#6# This program is free software: you can redistribute it and/or modify7# it under the terms of the GNU Affero General Public License as published8# by the Free Software Foundation, either version 3 of the License, or9# (at your option) any later version.10# This program is distributed in the hope that it will be useful,11# but WITHOUT ANY WARRANTY; without even the implied warranty of12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13# GNU Affero General Public License for more details.14# You should have received a copy of the GNU Affero General Public License15# along with this program. If not, see <https://www.gnu.org/licenses/>.16#17# For any questions about this software or licensing,18# please email opensource@seagate.com or cortx-questions@seagate.com.19import getpass20import os21import re22import sys23from collections import Counter24from datetime import date25from http import HTTPStatus26import requests27from jira import JIRA28BUGS_PRIORITY = ["Blocker", "Critical", "Major", "Minor", "Trivial"]29TEST_STATUS = ["PASS", "FAIL", "ABORTED", "BLOCKED", "TODO"]30FEATURES = [31 " Longevity",32 " Performance",33 " Security",34 "Application Testing (UDX, BearOS etc..)",35 "Capacity tests",36 "Cluster Health Operations",37 "Cluster Manager Operation (Provision)",38 "Cluster Monitor Operation (Alerts)",39 "Cluster Support (Logging, support bundle, health schema)",40 "Cluster User Operation (CSM)",41 "CSM GUI Cluster User Operation Tests",42 "Data Integrity",43 "Data recovery",44 "Failure Tests",45 "FRU Replacement Validation",46 "Functionality",47 "High Availability",48 "Interface",49 "IO Workload",50 "Lyve Pilot Tests",51 "Open-Source Tests",52 "Platform Operations",53 "Robustness and Reliability",54 "S3 IO load tests",55 "S3 Operations",56 "Scalability",57 "Stress Tests",58 "System Integration",59]60def get_test_executions_from_test_plan(test_plan: str, username: str, password: str) -> [dict]:61 """62 Summary: Get test executions from test plan.63 Description: Returns dictionary of test executions from test plan.64 Args:65 test_plan (str): Test plan number in JIRA66 username (str): JIRA Username67 password (str): JIRA Password68 Returns:69 List of dictionaries70 Each dict will have id, key, summary, self, testEnvironments71 [{"id": 311993, "key": "TEST-16653", "summary": "TE:Auto-Stability-Release 515",72 "self": "https://jts.seagate.com/rest/api/2/issue/311993",73 "testEnvironments": ["515_full"]},74 {"id": 311992, "key": "TEST-16652", "summary": "TE:Manual-RAS_Release 515",75 "self": "https://jts.seagate.com/rest/api/2/issue/311992",76 "testEnvironments": ["515_full"]}]77 """78 jira_url = f'https://jts.seagate.com/rest/raven/1.0/api/testplan/{test_plan}/testexecution'79 response = requests.get(jira_url, auth=(username, password))80 if response.status_code == HTTPStatus.OK:81 return response.json()82 print(f'get_test_executions GET on {jira_url} failed')83 print(f'RESPONSE={response.text}\n'84 f'HEADERS={response.request.headers}\n'85 f'BODY={response.request.body}')86 sys.exit(1)87def get_test_list_from_test_plan(test_plan: str, username: str, password: str) -> [dict]:88 """89 Args:90 test_plan (str): Test plan number in JIRA91 username (str): JIRA Username92 password (str): JIRA Password93 Returns:94 List of dictionaries95 Each dict will have id, key, latestStatus keys96 [{'id': 265766, 'key': 'TEST-4871', 'latestStatus': 'PASS'},97 {'id': 271956, 'key': 'TEST-6930', 'latestStatus': 'PASS'}]98 """99 jira_url = f'https://jts.seagate.com/rest/raven/1.0/api/testplan/{test_plan}/test'100 responses = []101 i = 0102 while True:103 i = i + 1104 query = {'limit': 100, 'page': i}105 response = requests.get(jira_url, auth=(username, password), params=query)106 if response.status_code == HTTPStatus.OK and response.json():107 responses.extend(response.json())108 elif response.status_code == HTTPStatus.OK and not response.json():109 break110 else:111 print(f'get_test_list GET on {jira_url} failed')112 print(f'RESPONSE={response.text}\n'113 f'HEADERS={response.request.headers}\n'114 f'BODY={response.request.body}')115 sys.exit(1)116 return responses117def get_test_from_test_execution(test_execution: str, username: str, password: str):118 """119 Args:120 test_execution (str): Test execution number in JIRA121 username (str): JIRA Username122 password (str): JIRA Password123 Returns:124 [{"key":"TEST-10963", "status":"FAIL", "defects": []}, {...}]125 "defects" = [{key:"EOS-123", "summary": "Bug Title", "status": "New/Started/Closed"},{}]126 """127 responses = []128 jira_url = f'https://jts.seagate.com/rest/raven/1.0/api/testexec/{test_execution}/test'129 i = 0130 while True:131 i = i + 1132 query = {'detailed': "true", 'limit': 100, 'page': i}133 response = requests.get(jira_url, auth=(username, password), params=query)134 if response.status_code == HTTPStatus.OK and response.json():135 responses.extend(response.json())136 elif response.status_code == HTTPStatus.OK and not response.json():137 break138 else:139 print(f'get_test_from_test_execution GET on {jira_url} failed')140 print(f'RESPONSE={response.text}\n'141 f'HEADERS={response.request.headers}\n'142 f'BODY={response.request.body}')143 sys.exit(1)144 return responses145def get_issue_details(issue_id: str, username: str, password: str):146 """147 Args:148 issue_id (str): Bug ID or TEST ID string149 username (str): JIRA Username150 password (str): JIRA Password151 Returns:152 {153 "fields":{154 "labels":["Integration","QA"],155 "environment":"515",156 "components":[157 {158 "name": "CSM"159 },160 {161 "name": "CFT"162 }163 ],164 "priority":{"name": "Critical"},165 "summary": "JIRA Title",166 "status": {"name": "In Progress"},167 "issuelinks": [{"inwardIssue": {"key": "TEST-5342"}},168 {"inwardIssue": {"key": "TEST-1034"}}]169 },170 }171 """172 jira_url = "https://jts.seagate.com/"173 options = {'server': jira_url}174 auth_jira = JIRA(options, basic_auth=(username, password))175 return auth_jira.issue(issue_id)176def get_defects_from_test_plan(test_plan: str, username: str, password: str) -> set:177 """Get defect list from given test plan."""178 defects = set()179 # Get test execution keys from test plan180 test_executions = get_test_executions_from_test_plan(test_plan, username, password)181 te_keys = [te["key"] for te in test_executions]182 # Get test and defect details for each test execution183 test_keys = {te: get_test_from_test_execution(te, username, password) for te in te_keys}184 # Collect defects185 for _, tests in test_keys.items():186 for test in tests:187 if test["status"] == "FAIL" and test["defects"]:188 for defect in test["defects"]:189 defects.add(defect["key"])190 return defects191def get_details_from_test_plan(test_plan: str, username: str, password: str) -> dict:192 """Get details for given test plan."""193 test_plan_details = get_issue_details(test_plan, username, password)194 fields = {"platformType": test_plan_details.fields.customfield_22982,195 "serverType": test_plan_details.fields.customfield_22983,196 "enclosureType": test_plan_details.fields.customfield_22984,197 "branch": test_plan_details.fields.customfield_22981,198 "buildNo": test_plan_details.fields.customfield_22980}199 out_dict = {}200 for key, value in fields.items():201 if value:202 out_dict.update({key: value[0]})203 else:204 print(f"Test Plan {test_plan} has {key} field empty.")205 sys.exit(1)206 env = test_plan_details.fields.environment207 if env:208 match = re.match(r"([0-9]+)([a-z]+)", env, re.I)209 if not match:210 print(f"Environment field for Test Plan {test_plan} does not have correct format "211 f"e.g. 3Node or 1node.")212 sys.exit(1)213 out_dict["nodes"] = f"{match.groups()[0]} {match.groups()[1]}"214 else:215 print(f"Environment field for Test Plan {test_plan} is empty."216 f"Example values, 3Node or 1node.")217 sys.exit(1)218 return out_dict219def get_main_table_data(tp_info: dict, report_type: str):220 """Get header table data."""221 data = [[f"CFT {report_type} Report"], ["Product", "Lyve Rack - 2"],222 ["Build", f"{tp_info['branch']} {tp_info['buildNo']}"],223 ["Date", date.today().strftime("%B %d, %Y")],224 ["System", f"{tp_info['nodes']} {tp_info['platformType']}"]]225 return data226def get_reported_bug_table_data(test_plan: str, username: str, password: str):227 """Get reported bug table data."""228 test_bugs = {x: 0 for x in BUGS_PRIORITY}229 cortx_bugs = {x: 0 for x in BUGS_PRIORITY}230 defects = get_defects_from_test_plan(test_plan, username, password)231 for defect in defects:232 defect = get_issue_details(defect, username, password)233 components = [component.name for component in defect.fields.components]234 if "CFT" in components or "Automation" in components:235 test_bugs[defect.fields.priority.name] += 1236 else:237 cortx_bugs[defect.fields.priority.name] += 1238 data = [239 ["Reported Bugs"], ["Priority", "Test Issues", "Cortx Issues"],240 ["Total", sum(test_bugs.values()), sum(cortx_bugs.values())],241 ]242 for priority in BUGS_PRIORITY:243 data.extend([[priority, test_bugs[priority], cortx_bugs[priority]]])244 return data245def get_overall_qa_report_table_data(test_plan: str, test_plan1: str,246 build: str, username: str, password: str):247 """Get overall qa report table data."""248 tests = get_test_list_from_test_plan(test_plan, username, password)249 count_0 = Counter(test['latestStatus'] for test in tests)250 build1 = "NA"251 count_1 = Counter()252 if test_plan1:253 build1 = get_details_from_test_plan(test_plan1, username, password)["buildNo"]254 tests = get_test_list_from_test_plan(test_plan1, username, password)255 count_1 = Counter(test['latestStatus'] for test in tests)256 data = [257 ["Overall QA Report"], ["", build, build1],258 ["Total", sum(count_0.values()), sum(count_1.values())],259 ]260 for status in TEST_STATUS:261 data.extend([262 [status.capitalize(), count_0[status], count_1[status]],263 ])264 return data265def get_username_password():266 """Get username and password from JIRA."""267 try:268 username = os.environ["JIRA_ID"]269 password = os.environ["JIRA_PASSWORD"]270 except KeyError:271 username = input("JIRA username: ")272 password = getpass.getpass("JIRA password: ")...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

...22 try:23 self.assertEquals(response.status_code, 200)24 except AssertionError, e:25 assert response.status_code in self.status_codes26 def test_plan_details(self):27 location = '/plan/%s/' % self.plan_id28 response = self.c.get(location)29 try:30 self.assertEquals(response.status_code, 200)31 except AssertionError, e:32 assert response.status_code in self.status_codes33 def test_plan_cases(self):34 location = '/plan/%s/cases/' % self.plan_id35 response = self.c.get(location)36 try:37 self.assertEquals(response.status_code, 200)38 except AssertionError, e:39 assert response.status_code in self.status_codes40 def test_plan_importcase(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kiwi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful