diff --git a/gradient/api_sdk/repositories/jobs.py b/gradient/api_sdk/repositories/jobs.py index f6c1f665..a8169138 100644 --- a/gradient/api_sdk/repositories/jobs.py +++ b/gradient/api_sdk/repositories/jobs.py @@ -1,6 +1,7 @@ from gradient import config from gradient.api_sdk import serializers -from .common import ListResources, CreateResource, BaseRepository, GetResource +from gradient.api_sdk.clients import http_client +from .common import ListResources, CreateResource, BaseRepository, GetResource, DeleteResource, StopResource from ..serializers import JobSchema, LogRowSchema @@ -106,26 +107,24 @@ def _get_client(self, use_vpc=False): return self.http_client -class DeleteJob(GetBaseJobApiUrlMixin, BaseRepository): +class DeleteJob(GetBaseJobApiUrlMixin, DeleteResource): def get_request_url(self, **kwargs): - return "/job/{}/destroy/".format(kwargs.get("id_")) + return "/jobs/{}/destroy".format(kwargs.get("id")) - def delete(self, id_, **kwargs): - url = self.get_request_url(id_=id_) - response = self.client.post(url) - self._validate_response(response) + def _send_request(self, client, url, json_data=None): + response = client.post(url, json=json_data) + return response -class StopJob(GetBaseJobApiUrlMixin, BaseRepository): +class StopJob(GetBaseJobApiUrlMixin, StopResource): def get_request_url(self, **kwargs): - return "/job/{}/stop/".format(kwargs.get('id_')) + return "/jobs/{}/stop".format(kwargs.get('id')) - def stop(self, id_, **kwargs): - url = self.get_request_url(id_=id_) - response = self.client.post(url) - self._validate_response(response) + def _send_request(self, client, url, json_data=None): + response = client.post(url, json=json_data) + return response class ListJobArtifacts(GetBaseJobApiUrlMixin, ListResources): @@ -152,20 +151,22 @@ def _get_request_params(self, kwargs): return params -class DeleteJobArtifacts(GetBaseJobApiUrlMixin, BaseRepository): +class DeleteJobArtifacts(GetBaseJobApiUrlMixin, DeleteResource): VALIDATION_ERROR_MESSAGE = "Failed to delete resource" def get_request_url(self, **kwargs): - return "/jobs/{}/artifactsDestroy/".format(kwargs.get("id_")) - - def delete(self, id_, **kwargs): - url = self.get_request_url(id_=id_) - - params = self._get_request_params(kwargs) - - client = self._get_client() - response = client.post(url, json=kwargs.get("json"), params=params) - self._validate_response(response) + return "/jobs/{}/artifactsDestroy".format(kwargs.get("id")) + + def _send(self, url, use_vpc=False, **kwargs): + client = self._get_client(use_vpc=use_vpc) + params_data = self._get_request_params(kwargs) + response = self._send_request(client, url, params_data=params_data) + gradient_response = http_client.GradientResponse.interpret_response(response) + return gradient_response + + def _send_request(self, client, url, params_data=None): + response = client.post(url, params=params_data) + return response def _get_request_params(self, kwargs): filters = dict() diff --git a/gradient/cli/jobs.py b/gradient/cli/jobs.py index dd390369..ff681c8d 100644 --- a/gradient/cli/jobs.py +++ b/gradient/cli/jobs.py @@ -32,7 +32,7 @@ def jobs_group(): help="Delete job with given ID", ) @api_key_option -def delete_job(job_id, api_key=None): +def delete_job(job_id, api_key): command = jobs_commands.DeleteJobCommand(api_key=api_key) command.execute(job_id) diff --git a/tests/functional/test_jobs.py b/tests/functional/test_jobs.py index 380bfec0..985dcc92 100644 --- a/tests/functional/test_jobs.py +++ b/tests/functional/test_jobs.py @@ -311,7 +311,7 @@ def test_should_send_valid_post_request_when_destroying_artifacts_with_files_spe "some_key"]) assert result.exit_code == 0, result.exc_info - post_patched.assert_called_with("{}/jobs/{}/artifactsDestroy/".format(self.URL, job_id), + post_patched.assert_called_with("{}/jobs/{}/artifactsDestroy".format(self.URL, job_id), files=None, headers=self.EXPECTED_HEADERS_WITH_CHANGED_API_KEY, json=None, @@ -324,7 +324,7 @@ def test_should_send_valid_post_request_when_destroying_artifacts_without_files_ job_id = "some_job_id" result = self.runner.invoke(cli.cli, ["jobs", "artifacts", "destroy", job_id, "--apiKey", "some_key"]) - post_patched.assert_called_with("{}/jobs/{}/artifactsDestroy/".format(self.URL, job_id), + post_patched.assert_called_with("{}/jobs/{}/artifactsDestroy".format(self.URL, job_id), files=None, headers=self.EXPECTED_HEADERS_WITH_CHANGED_API_KEY, json=None, @@ -340,7 +340,7 @@ def test_should_read_options_from_yaml_file(self, post_patched, jobs_artifacts_d result = self.runner.invoke(cli.cli, command) assert result.exit_code == 0, result.exc_info - post_patched.assert_called_with("{}/jobs/some_id/artifactsDestroy/".format(self.URL), + post_patched.assert_called_with("{}/jobs/some_id/artifactsDestroy".format(self.URL), files=None, headers=self.EXPECTED_HEADERS_WITH_CHANGED_API_KEY, json=None,