Skip to content
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

Fix delete cases #62

Merged
merged 6 commits into from
Apr 16, 2022
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
20 changes: 13 additions & 7 deletions testrail_api/_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,19 @@ def delete_case(self, case_id: int, soft: int = 0) -> Optional[dict]:
)

def delete_cases(
self, project_id: int, suite_id: Optional[int] = None, soft: int = 0
self,
project_id: int,
case_ids: List[int],
suite_id: Optional[int] = None,
soft: int = 0,
) -> None:
"""
Deletes multiple test cases from a project or test suite.

:param project_id:
The ID of the project
:param case_ids:
The case ids to be deleted
:param suite_id:
The ID of the suite (Only required if project is in multi-suite mode)
:param soft:
Expand All @@ -482,13 +488,13 @@ def delete_cases(
Including soft=1 will not actually delete the entity.
Omitting the soft parameter, or submitting soft=0 will delete the test case.
"""
params = {"soft": soft}
if suite_id:
params["suite_id"] = suite_id
params = {"soft": soft, "case_ids": case_ids, "project_id": project_id}

return self._session.request(
METHODS.POST, "delete_cases/{}".format(project_id), params=params
)
if suite_id:
url_path = "delete_cases/{}".format(suite_id)
else:
url_path = "delete_cases"
return self._session.request(METHODS.POST, url_path, params=params)

def copy_cases_to_section(self, section_id: int, case_ids: List[int]):
"""
Expand Down
26 changes: 14 additions & 12 deletions tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ def update_cases_suite(r, suite_id=None):
return 200, {}, r.body.decode()


def delete_cases(r, suite_id=None, soft=0):
def delete_cases(r, project_id=None, case_ids=None, suite_id=None, soft=0):
assert int(r.params['soft']) == soft
assert int(r.params['project_id']) == project_id
assert r.params['case_ids'] == ','.join(map(str, case_ids))
if suite_id:
assert int(r.params['suite_id']) == suite_id
assert 'delete_cases/{}&'.format(suite_id) in r.url
else:
assert 'suite_id' not in r.params
assert 'delete_cases&' in r.url
return 200, {}, ''


Expand Down Expand Up @@ -133,25 +135,25 @@ def test_update_cases_suite(api, mock, host):
def test_delete_cases_no_suite_id(api, mock, host):
mock.add_callback(
responses.POST,
'{}index.php?/api/v2/delete_cases/5'.format(host),
delete_cases,
'{}index.php?/api/v2/delete_cases'.format(host),
partial(delete_cases, project_id=1, case_ids=[5,6]),
)
api.cases.delete_cases(5)
api.cases.delete_cases(1, [5,6])


def test_delete_cases_suite_id(api, mock, host):
mock.add_callback(
responses.POST,
'{}index.php?/api/v2/delete_cases/5'.format(host),
partial(delete_cases, suite_id=1),
'{}index.php?/api/v2/delete_cases/1'.format(host),
partial(delete_cases, project_id=1, suite_id=1, case_ids=[5,6]),
)
api.cases.delete_cases(5, 1)
api.cases.delete_cases(1, [5,6], 1)


def test_delete_cases_suite_id_soft(api, mock, host):
mock.add_callback(
responses.POST,
'{}index.php?/api/v2/delete_cases/5'.format(host),
partial(delete_cases, suite_id=1, soft=1),
'{}index.php?/api/v2/delete_cases/1'.format(host),
partial(delete_cases, project_id=1, suite_id=1, soft=1, case_ids=[5,6]),
)
api.cases.delete_cases(5, 1, 1)
api.cases.delete_cases(1, [5,6], 1, 1)