From 4a37679fdfc6553eaaedd3d4ba179c5ba7d2bd8c Mon Sep 17 00:00:00 2001 From: Kiall Mac Innes Date: Thu, 19 May 2016 18:05:54 +0100 Subject: [PATCH] Add several negative RecordSet tests Change-Id: I18a8d0810e1eb83050cba88ed04f8a2902f2fcc0 --- .../tests/api/v2/test_recordset.py | 71 +++++++++++++++++++ designate_tempest_plugin/tests/base.py | 48 +++++++++++++ 2 files changed, 119 insertions(+) diff --git a/designate_tempest_plugin/tests/api/v2/test_recordset.py b/designate_tempest_plugin/tests/api/v2/test_recordset.py index a943b0c6..8e5a5e77 100644 --- a/designate_tempest_plugin/tests/api/v2/test_recordset.py +++ b/designate_tempest_plugin/tests/api/v2/test_recordset.py @@ -16,6 +16,7 @@ from tempest import config from tempest import test from tempest.lib import decorators from tempest.lib import exceptions as lib_exc +from tempest.lib.common.utils import data_utils as lib_data_utils import ddt from designate_tempest_plugin.tests import base @@ -184,6 +185,76 @@ class RecordsetsNegativeTest(BaseRecordsetsTest): lambda: self.client.create_recordset( self.zone['id'], recordset_data)) + @decorators.idempotent_id('b6dad57e-5ce9-4fa5-8d66-aebbcd23b4ad') + def test_get_nonexistent_recordset(self): + LOG.info('Create a zone') + _, zone = self.zone_client.create_zone() + self.addCleanup(self.zone_client.delete_zone, zone['id']) + + LOG.info('Attempt to get an invalid Recordset') + with self.assertRaisesDns( + lib_exc.NotFound, 'recordset_not_found', 404): + self.client.show_recordset(zone['id'], lib_data_utils.rand_uuid()) + + @decorators.idempotent_id('93d744a8-0dfd-4650-bcef-1e6ad632ad72') + def test_get_nonexistent_recordset_invalid_id(self): + LOG.info('Create a zone') + _, zone = self.zone_client.create_zone() + self.addCleanup(self.zone_client.delete_zone, zone['id']) + + LOG.info('Attempt to get an invalid Recordset') + with self.assertRaisesDns(lib_exc.BadRequest, 'invalid_uuid', 400): + self.client.show_recordset(zone['id'], 'invalid') + + @decorators.idempotent_id('da08f19a-7f10-47cc-8b41-994507190812') + def test_update_nonexistent_recordset(self): + LOG.info('Create a zone') + _, zone = self.zone_client.create_zone() + self.addCleanup(self.zone_client.delete_zone, zone['id']) + + recordset_data = data_utils.rand_recordset_data('A', zone['name']) + + LOG.info('Attempt to update an invalid Recordset') + with self.assertRaisesDns( + lib_exc.NotFound, 'recordset_not_found', 404): + self.client.update_recordset( + zone['id'], lib_data_utils.rand_uuid(), recordset_data) + + @decorators.idempotent_id('158340a1-3f69-4aaa-9968-956190563768') + def test_update_nonexistent_recordset_invalid_id(self): + LOG.info('Create a zone') + _, zone = self.zone_client.create_zone() + self.addCleanup(self.zone_client.delete_zone, zone['id']) + + recordset_data = data_utils.rand_recordset_data('A', zone['name']) + + LOG.info('Attempt to update an invalid Recordset') + with self.assertRaisesDns(lib_exc.BadRequest, 'invalid_uuid', 400): + self.client.update_recordset( + zone['id'], 'invalid', recordset_data) + + @decorators.idempotent_id('64bd94d4-54bd-4bee-b6fd-92ede063234e') + def test_delete_nonexistent_recordset(self): + LOG.info('Create a zone') + _, zone = self.zone_client.create_zone() + self.addCleanup(self.zone_client.delete_zone, zone['id']) + + LOG.info('Attempt to delete an invalid Recordset') + with self.assertRaisesDns( + lib_exc.NotFound, 'recordset_not_found', 404): + self.client.delete_recordset( + zone['id'], lib_data_utils.rand_uuid()) + + @decorators.idempotent_id('5948b599-a332-4dcb-840b-afc825075ba3') + def test_delete_nonexistent_recordset_invalid_id(self): + LOG.info('Create a zone') + _, zone = self.zone_client.create_zone() + self.addCleanup(self.zone_client.delete_zone, zone['id']) + + LOG.info('Attempt to get an invalid Recordset') + with self.assertRaisesDns(lib_exc.BadRequest, 'invalid_uuid', 400): + self.client.delete_recordset(zone['id'], 'invalid') + class RootRecordsetsTests(BaseRecordsetsTest): diff --git a/designate_tempest_plugin/tests/base.py b/designate_tempest_plugin/tests/base.py index c86b38a0..8f3e83d3 100644 --- a/designate_tempest_plugin/tests/base.py +++ b/designate_tempest_plugin/tests/base.py @@ -21,6 +21,38 @@ from designate_tempest_plugin import clients CONF = config.CONF +class AssertRaisesDns(object): + def __init__(self, test_class, exc, type_, code): + self.test_class = test_class + self.exc = exc + self.type_ = type_ + self.code = code + + def __enter__(self): + pass + + def __exit__(self, exc_type, exc_value, traceback): + if exc_type is None: + try: + exc_name = self.exc.__name__ + except AttributeError: + exc_name = str(self.exc) + raise self.failureException( + "{0} not raised".format(exc_name)) + + if issubclass(exc_type, self.exc): + self.test_class.assertEqual( + self.code, exc_value.resp_body['code']) + + self.test_class.assertEqual( + self.type_, exc_value.resp_body['type']) + + return True + + # Unexpected exceptions will be reraised + return False + + class BaseDnsTest(test.BaseTestCase): """Base class for DNS tests.""" @@ -49,6 +81,22 @@ class BaseDnsTest(test.BaseTestCase): self.assertIn(key, actual) self.assertEqual(value, actual[key], key) + def assertRaisesDns(self, exc, type_, code, callable_=None, *args, + **kwargs): + """ + Checks the response that a api call with a exception contains the + expected data + + Usable as both a ordinary function, and a context manager + """ + context = AssertRaisesDns(self, exc, type_, code) + + if callable_ is None: + return context + + with context: + callable_(*args, **kwargs) + class BaseDnsV1Test(BaseDnsTest): """Base class for DNS V1 API tests."""