From ffbca79ae0438472bd6b33cb021770e23c364cac Mon Sep 17 00:00:00 2001 From: Honza Kral Date: Wed, 10 Jul 2013 13:40:33 +0200 Subject: [PATCH] Added catch support for yaml tests, dummy for now --- test_elasticsearch/test_server/test_common.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test_elasticsearch/test_server/test_common.py b/test_elasticsearch/test_server/test_common.py index c1afdfa1..04b456f4 100644 --- a/test_elasticsearch/test_server/test_common.py +++ b/test_elasticsearch/test_server/test_common.py @@ -40,6 +40,8 @@ class YamlTestCase(TestCase): def run_do(self, action): """ Perform an api call with given parameters. """ + + catch = action.pop('catch', None) self.assertEquals(1, len(action)) method, args = list(action.items())[0] @@ -56,12 +58,23 @@ class YamlTestCase(TestCase): if k in args: args[PARAMS_RENAMES[k]] = args.pop(k) - self.last_response = api(**args) + try: + self.last_response = api(**args) + except: + if not catch: + raise + self.run_catch(catch) + else: + if catch: + raise AssertionError('Failed to catch %r in %r.' % (catch, self.last_response)) + + def run_catch(self, catch): + pass def run_length(self, action): self.run_is(action, len) - def run_is(self, action, transform=None): + def run_match(self, action, transform=None): """ Match part of last response to test data. """ # matching part of the reponse dict