From 449f53f687e62535d7a5f183f67e474043389ec4 Mon Sep 17 00:00:00 2001 From: Vincent Llorens Date: Mon, 20 Feb 2017 13:08:50 +0100 Subject: [PATCH] fix one instance of "except Exception" Sem-Ver: bugfix Change-Id: Ic8f557c99e32990816fe0bbc8f6fa1dbcaa8593c --- synergy/client/command.py | 16 ++++++++-------- .../unit/test_client_command_httpcommand.py | 10 ---------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/synergy/client/command.py b/synergy/client/command.py index 3d06d62..aaa2cfb 100644 --- a/synergy/client/command.py +++ b/synergy/client/command.py @@ -37,16 +37,16 @@ class HTTPCommand(object): def execute(self, synergy_url, payload=None): request = requests.get(synergy_url, params=payload) - - if request.status_code != requests.codes.ok: - request.raise_for_status() - - self.results = request.json() + request.raise_for_status() try: - return json.loads(request.text, object_hook=objectHookHandler) - except Exception: - return request.json() + self.results = json.loads( + request.text, + object_hook=objectHookHandler) + except ValueError: + self.results = request.json() + + return self.results def getResults(self): return self.results diff --git a/synergy/tests/unit/test_client_command_httpcommand.py b/synergy/tests/unit/test_client_command_httpcommand.py index 1b8300c..d241db6 100644 --- a/synergy/tests/unit/test_client_command_httpcommand.py +++ b/synergy/tests/unit/test_client_command_httpcommand.py @@ -39,16 +39,6 @@ class TestHTTPCommand(base.TestCase): self.http_command.configureParser, "dummy_subparser") - def test_execute_request_fail(self): - mock_response = mock.Mock() - # bad status code that will raise an error - mock_response.status_code = 400 - - with mock.patch.object(requests, "get", return_value=mock_response): - self.http_command.execute("dummy_url") - - mock_response.raise_for_status.assert_called() - def test_execute_success(self): mock_response = mock.Mock() mock_response.text = '{"test": true}' # mock a simple json response