def test_can_handle_other_error_from_put(self): with patch.object(_Resource, "put") as mocked: mocked.side_effect = DodgyServerError resource = Resource("http://localhost:7474/db/data/node/spam") try: resource.put() except GraphError as error: assert isinstance(error.__cause__, DodgyServerError) else: assert False
class ServerErrorTestCase(GraphTestCase): def setUp(self): self.non_existent_resource = Resource( "http://localhost:7474/db/data/x") def test_can_handle_json_error_from_get(self): try: self.non_existent_resource.get() except GraphError as error: cause = error.__cause__ assert isinstance(cause, _ClientError) assert isinstance(cause, _Response) assert cause.status_code == 404 else: assert False def test_can_handle_json_error_from_put(self): try: self.non_existent_resource.put("") except GraphError as error: cause = error.__cause__ assert isinstance(cause, _ClientError) assert isinstance(cause, _Response) assert cause.status_code == 404 else: assert False def test_can_handle_json_error_from_post(self): try: self.non_existent_resource.post("") except GraphError as error: cause = error.__cause__ assert isinstance(cause, _ClientError) assert isinstance(cause, _Response) assert cause.status_code == 404 else: assert False def test_can_handle_json_error_from_delete(self): try: self.non_existent_resource.delete() except GraphError as error: cause = error.__cause__ assert isinstance(cause, _ClientError) assert isinstance(cause, _Response) assert cause.status_code == 404 else: assert False def test_can_handle_other_error_from_get(self): with patch.object(_Resource, "get") as mocked: mocked.side_effect = DodgyServerError resource = Resource("http://localhost:7474/db/data/node/spam") try: resource.get() except GraphError as error: assert isinstance(error.__cause__, DodgyServerError) else: assert False def test_can_handle_other_error_from_put(self): with patch.object(_Resource, "put") as mocked: mocked.side_effect = DodgyServerError resource = Resource("http://localhost:7474/db/data/node/spam") try: resource.put() except GraphError as error: assert isinstance(error.__cause__, DodgyServerError) else: assert False def test_can_handle_other_error_from_post(self): with patch.object(_Resource, "post") as mocked: mocked.side_effect = DodgyServerError resource = Resource("http://localhost:7474/db/data/node/spam") try: resource.post() except GraphError as error: assert isinstance(error.__cause__, DodgyServerError) else: assert False def test_can_handle_other_error_from_delete(self): with patch.object(_Resource, "delete") as mocked: mocked.side_effect = DodgyServerError resource = Resource("http://localhost:7474/db/data/node/spam") try: resource.delete() except GraphError as error: assert isinstance(error.__cause__, DodgyServerError) else: assert False