Skip to content

Commit b6374ca

Browse files
author
Markus Bong
authored
Merge pull request #25 from devolo/fix/minor_fixes
minor optimizations
2 parents 2a15fca + e613936 commit b6374ca

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [2.2.1] - 2022/03/25
88

9-
## Fixed
9+
### Fixed
1010

1111
- Toggling build_url and code_base
1212

adaptavist/_helper.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ def get_executor() -> str:
1515

1616
def build_folder_names(result: Dict[str, Any], folder_name: str = "") -> List[Any]:
1717
"""Build list of folder names from a hierarchical dictionary."""
18-
folders = []
1918
folder_name = "/".join((folder_name, result.get("name", ""))).replace("//", "/")
20-
folders.append(folder_name)
21-
19+
folders = [folder_name]
2220
if not result.get("children"):
2321
return folders
2422

@@ -37,12 +35,12 @@ def raise_on_kwargs_not_empty(kwargs):
3735
def update_field(current_values: List[Any], request_data: Dict[str, Any], key: str, new_values: List[Any]) -> None:
3836
"""Append list entries to an existing list and add it to a dictionary, if the new list is different."""
3937
if new_values and new_values[0] == "-" and current_values != new_values[1:]:
40-
request_data.update({key: new_values[1:]})
38+
request_data[key] = new_values[1:]
4139
return
4240

4341
combined_values = current_values + list(set(new_values) - set(current_values))
4442
if current_values != combined_values:
45-
request_data.update({key: combined_values})
43+
request_data[key] = combined_values
4644

4745

4846
def update_multiline_field(current_content: str, request_data: Dict[str, Any], key: str, new_values: List[str]) -> None:

adaptavist/adaptavist.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self, jira_server: str, jira_username: str, jira_password: str):
2626
self.jira_server = jira_server
2727
self.jira_username = jira_username
2828

29-
self._adaptavist_api_url = self.jira_server + "/rest/atm/1.0"
29+
self._adaptavist_api_url = f'{self.jira_server}/rest/atm/1.0'
3030
self._authentication = requests.auth.HTTPBasicAuth(self.jira_username, jira_password)
3131
self._headers = {"Accept": "application/json", "Content-type": "application/json"}
3232
self._logger = logging.getLogger(__name__)
@@ -163,7 +163,7 @@ def get_test_cases(self, search_mask: str = "folder <= \"/\"") -> List[Dict[str,
163163
request_url = f"{self._adaptavist_api_url}/testcase/search?query={quote_plus(search_mask)}&startAt={i}"
164164
self._logger.debug("Asking for test cases with search mask '%s' starting at %i", search_mask, i + 1)
165165
request = self._get(request_url)
166-
result = [] if not request else request.json()
166+
result = request.json() if request else []
167167
if not result:
168168
break
169169
test_cases = [*test_cases, *result]
@@ -507,7 +507,7 @@ def get_test_run_by_name(self, test_run_name: str) -> Dict[str, Any]:
507507
request_url = f"{self.jira_server}/rest/tests/1.0/testrun/search?startAt={i}&maxResults=10000&query={search_mask}&fields=id,key,name"
508508
self._logger.debug("Asking for 10000 test runs starting at %i", i + 1)
509509
request = self._get(request_url)
510-
results = [] if not request else request.json()["results"]
510+
results = request.json()["results"] if request else []
511511
if not results:
512512
break
513513
test_runs = [*test_runs, *results]
@@ -535,7 +535,7 @@ def get_test_runs(self, search_mask: str = "folder = \"/\"", **kwargs: Any) -> L
535535
request_url = f"{self._adaptavist_api_url}/testrun/search?query={quote_plus(search_mask)}&startAt={i}&maxResults=1000&fields={quote_plus(fields)}"
536536
self._logger.debug("Asking for 1000 test runs starting at %i using search mask %s", i + 1, search_mask)
537537
request = self._get(request_url)
538-
result = [] if not request else request.json()
538+
result = request.json() if request else []
539539
if not result:
540540
break
541541
test_runs = [*test_runs, *result]
@@ -655,7 +655,7 @@ def get_test_execution_results(self, last_result_only: bool = True) -> List[Dict
655655
request_url = f"{self.jira_server}/rest/tests/1.0/reports/testresults?startAt={i}&maxResults=10000"
656656
self._logger.debug("Asking for 10000 test results starting at %i", i + 1)
657657
request = self._get(request_url)
658-
results = [] if not request else request.json()["results"]
658+
results = request.json()["results"] if request else []
659659
if not results:
660660
break
661661
test_results = [*test_results, *results]
@@ -746,10 +746,7 @@ def get_test_result(self, test_run_key: str, test_case_key: str) -> Dict[str, An
746746
:returns: Test result
747747
"""
748748
response = self.get_test_results(test_run_key)
749-
for item in response:
750-
if item["testCaseKey"] == test_case_key:
751-
return item
752-
return {}
749+
return next((item for item in response if item["testCaseKey"] == test_case_key), {})
753750

754751
def create_test_result(self, test_run_key: str, test_case_key: str, status: str = STATUS_NOT_EXECUTED, **kwargs: Any) -> Optional[int]:
755752
"""
@@ -995,9 +992,12 @@ def _put(self, request_url: str, data: Any) -> Optional[requests.Response]:
995992
def _upload_file(self, request_url: str, attachment: BinaryIO, filename: str) -> bool:
996993
"""Upload file to Adaptavist."""
997994
stream = requests_toolbelt.MultipartEncoder(fields={"file": (filename, attachment, "application/octet-stream")})
998-
headers = {**self._headers}
999-
headers["Content-type"] = stream.content_type
1000-
headers["X-Atlassian-Token"] = "nocheck"
995+
headers = {
996+
**self._headers,
997+
"Content-type": stream.content_type,
998+
"X-Atlassian-Token": "nocheck",
999+
}
1000+
10011001
filename = filename or attachment.name
10021002

10031003
try:

0 commit comments

Comments
 (0)