From 336fc4debd65f997e602e327ac2a7b1a5215b890 Mon Sep 17 00:00:00 2001 From: Endre Karlson Date: Fri, 12 Jun 2015 13:08:36 +0200 Subject: [PATCH] Add utility code for negative testing Change-Id: Iae2daccd40fc890ab00bc35d071ab8edb44a6b51 --- functionaltests/api/v2/base.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/functionaltests/api/v2/base.py b/functionaltests/api/v2/base.py index 60c01140..a90cf51c 100644 --- a/functionaltests/api/v2/base.py +++ b/functionaltests/api/v2/base.py @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. """ +from tempest_lib import exceptions + from functionaltests.api.v2.clients.quotas_client import QuotasClient from functionaltests.api.v2.models.quotas_model import QuotasModel from functionaltests.common.base import BaseDesignateTest @@ -33,3 +35,21 @@ class DesignateV2Test(BaseDesignateTest): 'recordset_records': 9999999, 'zone_records': 9999999, 'zone_recordsets': 9999999}})) + + def _assert_invalid_uuid(self, method, *args, **kw): + """ + Test that UUIDs used in the URL is valid. + """ + self._assert_exception( + exceptions.BadRequest, 'invalid_uuid', 400, method, *args) + + def _assert_exception(self, exc, type_, status, method, *args, **kwargs): + """ + Checks the response that a api call with a exception contains the + wanted data. + """ + try: + method(*args, **kwargs) + except exc as e: + self.assertEqual(status, e.resp_body['code']) + self.assertEqual(type_, e.resp_body['type'])