Skip to content

[Xray] Optimize param passing & error handling #895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions atlassian/confluence.py
Original file line number Diff line number Diff line change
Expand Up @@ -2679,5 +2679,5 @@ def raise_for_status(self, response):
error_msg = j["message"]
except Exception:
response.raise_for_status()

raise HTTPError(error_msg, response=response)
else:
raise HTTPError(error_msg, response=response)
4 changes: 2 additions & 2 deletions atlassian/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -3914,5 +3914,5 @@ def raise_for_status(self, response):
error_msg = "\n".join(j["errorMessages"] + [k + ": " + v for k, v in j["errors"].items()])
except Exception:
response.raise_for_status()

raise HTTPError(error_msg, response=response)
else:
raise HTTPError(error_msg, response=response)
4 changes: 2 additions & 2 deletions atlassian/service_desk.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,5 +778,5 @@ def raise_for_status(self, response):
error_msg = j["errorMessage"]
except Exception:
response.raise_for_status()

raise HTTPError(error_msg, response=response)
else:
raise HTTPError(error_msg, response=response)
32 changes: 27 additions & 5 deletions atlassian/xray.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding=utf-8
import logging
import re

from requests import HTTPError
from .rest_client import AtlassianRestAPI

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -535,11 +535,19 @@ def get_test_repo_folder_tests(self, project_key, folder_id, all_descendants=Fal
:param page: Page of paginated data (first 1)
:param limit: Amount of Tests per paginated data.
:return: Returns list of the Tests contained in a given folder of the test repository.
Note: param "page" and "limit" must coexist, otherwise rest api will raise 400
"""
url = "rest/raven/1.0/api/testrepository/{0}/folders/{1}/tests?allDescendants={2}&page={3}&limit={4}".format(
project_key, folder_id, all_descendants, page, limit
)
return self.get(url)
url = "rest/raven/1.0/api/testrepository/{0}/folders/{1}/tests".format(project_key, folder_id)
params = {}

if all_descendants:
params["allDescendants"] = all_descendants
if page:
params["page"] = page
if limit:
params["limit"] = limit

return self.get(url, params=params)

def update_test_repo_folder_tests(self, project_key, folder_id, add=None, remove=None):
"""
Expand All @@ -557,3 +565,17 @@ def update_test_repo_folder_tests(self, project_key, folder_id, add=None, remove
data = {"add": add, "remove": remove}
url = "rest/raven/1.0/api/testrepository/{0}/folders/{1}/tests".format(project_key, folder_id)
return self.put(url, data=data)

def raise_for_status(self, response):
"""
Checks the response for an error status and raises an exception with the error message provided by the server
:param response:
:return:
"""
if 400 <= response.status_code < 600:
try:
error_msg = response.text
except Exception:
response.raise_for_status()
else:
raise HTTPError(error_msg, response=response)