diff --git a/saharaclient/api/job_binaries.py b/saharaclient/api/job_binaries.py index b7798e23..683337c6 100644 --- a/saharaclient/api/job_binaries.py +++ b/saharaclient/api/job_binaries.py @@ -49,3 +49,7 @@ class JobBinariesManager(base.ResourceManager): if resp.status_code != 200: self._raise_api_exception(resp) return resp.content + + def update(self, job_binary_id, data): + return self._update( + '/job-binaries/%s' % job_binary_id, data, 'job_binary') diff --git a/saharaclient/api/shell.py b/saharaclient/api/shell.py index 3b46057b..290e6683 100644 --- a/saharaclient/api/shell.py +++ b/saharaclient/api/shell.py @@ -723,6 +723,27 @@ def do_job_binary_delete(cs, args): # TODO(mattf): No indication of result +@utils.arg('--name', + help='Name of the job binary to update.') +@utils.arg('--id', + metavar='', + help='Id of the job binary to update.') +@utils.arg('--json', + default=sys.stdin, + type=argparse.FileType('r'), + help='JSON representation of job binary update.') +def do_job_binary_update(cs, args): + """Update a job binary.""" + update_data = json.loads(args.json.read()) + result = cs.job_binaries.update( + args.id or + _get_by_id_or_name(cs.job_binaries, name=args.name).id, + update_data + ) + + _show_job_binary(result) + + # # Jobs # ~~~~ diff --git a/saharaclient/tests/unit/test_job_binaries.py b/saharaclient/tests/unit/test_job_binaries.py index e2c1fa43..4d3b9880 100644 --- a/saharaclient/tests/unit/test_job_binaries.py +++ b/saharaclient/tests/unit/test_job_binaries.py @@ -29,6 +29,16 @@ class JobBinaryTest(base.BaseTestCase): } } + update_body = { + 'name': 'Updatedname', + 'url': 'Updatedurl', + 'description': 'Updateddescr', + 'extra': { + 'user': 'user', + 'password': 'Updated123' + } + } + def test_create_job_binary(self): url = self.URL + '/job-binaries' self.responses.post(url, status_code=202, @@ -78,3 +88,12 @@ class JobBinaryTest(base.BaseTestCase): self.assertEqual(url, self.responses.last_request.url) self.assertEqual(b'data', resp) + + def test_job_binary_update(self): + url = self.URL + '/job-binaries/id' + self.responses.put(url, + status_code=202, + json={'job_binary': self.update_body}) + + resp = self.client.job_binaries.update("id", self.update_body) + self.assertEqual(self.update_body["name"], resp.name)