Skip to content

Commit

Permalink
[ISSUE-128] job delete (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
QFer authored Jan 14, 2022
1 parent 4f8451d commit 5565007
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
8 changes: 2 additions & 6 deletions src/quantuminspire/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,21 +463,17 @@ def get_jobs_from_project(self, project_id: int) -> List[Dict[str, Any]]:
ret: List[Dict[str, Any]] = jobs
return ret

def delete_job(self, job_id: int) -> Dict[str, Any]:
def delete_job(self, job_id: int) -> None:
""" Deletes the job identified by `job_id`.
Only jobs can be deleted that are registered for the user the API is currently authenticated for.
:param job_id: The job identification number.
:return:
The deleted job indicated by the job identification number.
See :meth:`~.get_job` for a description of the job properties.
:raises ApiError: If the job identified by `job_id` does not exist.
"""
try:
return dict(self._action(['jobs', 'delete'], params={'id': job_id}))
self._action(['jobs', 'delete'], params={'id': job_id})
except ErrorMessage as err_msg:
raise ApiError(f'Job with id {job_id} does not exist!') from err_msg

Expand Down
4 changes: 1 addition & 3 deletions src/tests/quantuminspire/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,9 @@ def test_get_jobs_from_asset_raises_api_error(self):
def test_delete_job_has_correct_in_and_output(self):
identity = 509
expected_payload = {'id': identity}
expected = self.__mock_job_handler(expected_payload, 'delete', None, None, ['test', 'delete'], expected_payload)
self.coreapi_client.handlers['jobs'] = partial(self.__mock_job_handler, expected_payload, 'delete')
api = QuantumInspireAPI('FakeURL', self.authentication, coreapi_client_class=self.coreapi_client)
actual = api.delete_job(job_id=identity)
self.assertEqual(actual, expected)
self.assertIsNone(api.delete_job(job_id=identity))

def test_delete_job_raises_api_error(self):
identity = 999
Expand Down

0 comments on commit 5565007

Please sign in to comment.