From bccadf76552f19f3eb17a25cda1cb488c0479a25 Mon Sep 17 00:00:00 2001 From: aherlihy Date: Mon, 7 Mar 2016 13:45:46 +0100 Subject: [PATCH] Add better error handling to tests --- mongo_connector/test_utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mongo_connector/test_utils.py b/mongo_connector/test_utils.py index b9153ee4..9fc0eebc 100644 --- a/mongo_connector/test_utils.py +++ b/mongo_connector/test_utils.py @@ -84,8 +84,11 @@ def get_config(self): def _make_post_request(self): config = _post_request_template.copy() config.update(self.get_config()) - return requests.post( + ret = requests.post( _mo_url(self._resource), timeout=None, json=config).json() + if type(ret) == list: # Will return a list if an error occurred. + raise RuntimeError("Error sending POST to cluster: %s" % (ret)) + return ret def client(self, **kwargs): client = pymongo.MongoClient(self.uri, **kwargs) @@ -185,8 +188,6 @@ def get_config(self): def start(self): # We never need to restart a sharded cluster, only start new ones. response = self._make_post_request() - if 'shards' not in response: - raise RuntimeError("Error starting cluster: %s" % (response)) for shard in response['shards']: if shard['id'] == 'demo-set-0': repl1_id = shard['_id']