summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEndre Karlson <endre.karlson@hp.com>2014-02-26 18:28:06 +0100
committerGerrit Code Review <review@openstack.org>2014-03-03 18:43:07 +0000
commit2636e2c5cd8024f0c93af443f8ac6a3f3d440136 (patch)
treeaa0d9aecb0a0255f8d42f77397174b74604c1b59
parent97d5512041003d1230bd3bd84029cf9a18e749e1 (diff)
downloaddesignate-2636e2c5cd8024f0c93af443f8ac6a3f3d440136.tar.gz
Ensure that wanted API calls returns exceptions
* Previous checks only checked status and not content. * One method to use across all V2 tests. * Switch existing _assert_* methods to use this. Closes-Bug: #1283527 Change-Id: If49460965b08789286df4287862a0c96d2d8b44d
-rw-r--r--designate/tests/test_api/test_v2/__init__.py72
-rw-r--r--designate/tests/test_api/test_v2/test_floatingips.py52
-rw-r--r--designate/tests/test_api/test_v2/test_records.py84
-rw-r--r--designate/tests/test_api/test_v2/test_recordsets.py95
-rw-r--r--designate/tests/test_api/test_v2/test_tlds.py5
-rw-r--r--designate/tests/test_api/test_v2/test_zones.py148
6 files changed, 252 insertions, 204 deletions
diff --git a/designate/tests/test_api/test_v2/__init__.py b/designate/tests/test_api/test_v2/__init__.py
index 40ef657f..cd366bb2 100644
--- a/designate/tests/test_api/test_v2/__init__.py
+++ b/designate/tests/test_api/test_v2/__init__.py
@@ -62,14 +62,54 @@ class ApiV2TestCase(ApiTestCase):
super(ApiV2TestCase, self).tearDown()
def _assert_invalid_uuid(self, method, url_format, *args, **kw):
+ """
+ Test that UUIDs used in the URL is valid.
+ """
count = url_format.count('%s')
for i in itertools.product(INVALID_ID, repeat=count):
- response = method(url_format % i, status=400)
- self.assertEqual(400, response.json['code'])
- self.assertEqual('invalid_uuid', response.json['type'])
+ self._assert_exception('invalid_uuid', 400, method, url_format % i)
+
+ def _assert_exception(self, expected_type, expected_status, obj,
+ *args, **kwargs):
+ """
+ Checks the response that a api call with a exception contains the
+ wanted data.
+ """
+ kwargs.setdefault('status', expected_status)
+
+ response = obj(*args, **kwargs) if not hasattr(obj, 'json') else obj
+
+ self.assertEqual(expected_status, response.json['code'])
+ self.assertEqual(expected_type, response.json['type'])
+
+ def _assert_invalid_paging(self, data, url, key):
+ """
+ Test that certain circumstances is invalid for paging in a given url.
+ """
+ self._assert_paging(data, url, key=key,
+ limit='invalid_limit',
+ expected_type='invalid_limit',
+ expected_status=400)
+
+ self._assert_paging(data, url, key=key,
+ sort_dir='invalid_sort_dir',
+ expected_type='invalid_sort_dir',
+ expected_status=400)
+
+ self._assert_paging(data, url, key=key,
+ sort_key='invalid_sort_key',
+ expected_type='invalid_sort_key',
+ expected_status=400)
+
+ self._assert_paging(data, url, key=key,
+ marker='invalid_marker',
+ expected_type='invalid_marker',
+ expected_status=400)
def _assert_paging(self, data, url, key=None, limit=5, sort_dir='asc',
- sort_key='created_at', marker=None, status=200):
+ sort_key='created_at', marker=None,
+ expected_type=None, expected_status=200):
+
def _page(marker=None):
params = {'limit': limit,
'sort_dir': sort_dir,
@@ -78,25 +118,31 @@ class ApiV2TestCase(ApiTestCase):
if marker is not None:
params['marker'] = marker
- r = self.client.get(url, params, status=status)
- if status != 200:
+ r = self.client.get(url, params, status=expected_status)
+ if expected_status != 200:
+ if expected_type:
+ self._assert_exception(expected_type, expected_status, r)
return r
else:
return r.json[key] if key in r.json else r.json
- page_items = _page(marker=marker)
- if status != 200:
- return page_items
+ response = _page(marker=marker)
+ if expected_status != 200:
+ if expected_type:
+ self._assert_exception(expected_type, expected_status,
+ response)
+
+ return response
x = 0
length = len(data)
for i in xrange(0, length):
- assert data[i]['id'] == page_items[x]['id']
+ assert data[i]['id'] == response[x]['id']
x += 1
# Don't bother getting a new page if we're at the last item
- if x == len(page_items) and i != length - 1:
+ if x == len(response) and i != length - 1:
x = 0
- page_items = _page(page_items[-1:][0]['id'])
+ response = _page(response[-1:][0]['id'])
- _page(marker=page_items[-1:][0]['id'])
+ _page(marker=response[-1:][0]['id'])
diff --git a/designate/tests/test_api/test_v2/test_floatingips.py b/designate/tests/test_api/test_v2/test_floatingips.py
index 232f4782..9b505868 100644
--- a/designate/tests/test_api/test_v2/test_floatingips.py
+++ b/designate/tests/test_api/test_v2/test_floatingips.py
@@ -74,19 +74,13 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
def test_get_floatingip_not_allocated(self):
url = '/reverse/floatingips/foo:04580c52-b253-4eb7-8791-fbb9de9f856f'
- response = self.client.get(url, status=404)
- self.assertIn('request_id', response.json)
- self.assertEqual(404, response.json['code'])
- self.assertEqual('not_found', response.json['type'])
+ self._assert_exception('not_found', 404, self.client.get, url)
def test_get_floatingip_invalid_key(self):
- response = self.client.get('/reverse/floatingips/foo:bar', status=400)
+ url = '/reverse/floatingips/foo:bar'
- self.assertIn('message', response.json)
- self.assertIn('request_id', response.json)
- self.assertEqual(400, response.json['code'])
- self.assertEqual('bad_request', response.json['type'])
+ self._assert_exception('bad_request', 400, self.client.get, url)
def test_list_floatingip_no_allocations(self):
response = self.client.get('/reverse/floatingips')
@@ -171,35 +165,23 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
fip = self.network_api.fake.allocate_floatingip('tenant')
self.network_api.fake.deallocate_floatingip(fip['id'])
- response = self.client.patch_json(
- '/reverse/floatingips/%s' % ":".join([fip['region'], fip['id']]),
- {"floatingip": fixture}, status=404)
+ url = '/reverse/floatingips/%s' % ":".join([fip['region'], fip['id']])
- self.assertIn('message', response.json)
- self.assertIn('request_id', response.json)
- self.assertEqual(404, response.json['code'])
- self.assertEqual('not_found', response.json['type'])
+ self._assert_exception('not_found', 404, self.client.patch_json, url,
+ {'floatingip': fixture})
def test_set_floatingip_invalid_ptrdname(self):
fip = self.network_api.fake.allocate_floatingip('tenant')
- response = self.client.patch_json(
- '/reverse/floatingips/%s' % ":".join([fip['region'], fip['id']]),
- {"floatingip": {'ptrxname': 'test'}}, status=400)
+ url = '/reverse/floatingips/%s' % ":".join([fip['region'], fip['id']])
- self.assertIn('message', response.json)
- self.assertIn('request_id', response.json)
- self.assertEqual(400, response.json['code'])
- self.assertEqual('invalid_object', response.json['type'])
+ self._assert_exception('invalid_object', 400, self.client.patch_json,
+ url, {'floatingip': {'ptrdname': 'test|'}})
def test_set_floatingip_invalid_key(self):
- response = self.client.patch_json(
- '/reverse/floatingips/%s' % 'foo:random', {}, status=400)
-
- self.assertIn('message', response.json)
- self.assertIn('request_id', response.json)
- self.assertEqual(400, response.json['code'])
- self.assertEqual('bad_request', response.json['type'])
+ url = '/reverse/floatingips/%s' % 'foo:random'
+ self._assert_exception('bad_request', 400, self.client.patch_json,
+ url, {})
def test_unset_floatingip(self):
self.create_server()
@@ -238,11 +220,7 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
self.network_api.fake.deallocate_floatingip(fip['id'])
- response = self.client.patch_json(
- '/reverse/floatingips/%s' % ":".join([fip['region'], fip['id']]),
- {"floatingip": {'ptrdname': None}}, status=404)
+ url = '/reverse/floatingips/%s' % ":".join([fip['region'], fip['id']])
- self.assertIn('message', response.json)
- self.assertIn('request_id', response.json)
- self.assertEqual(404, response.json['code'])
- self.assertEqual('not_found', response.json['type'])
+ self._assert_exception('not_found', 404, self.client.patch_json, url,
+ {"floatingip": {'ptrdname': None}})
diff --git a/designate/tests/test_api/test_v2/test_records.py b/designate/tests/test_api/test_v2/test_records.py
index a418c758..27bba16e 100644
--- a/designate/tests/test_api/test_v2/test_records.py
+++ b/designate/tests/test_api/test_v2/test_records.py
@@ -60,19 +60,16 @@ class ApiV2RecordsTest(ApiV2TestCase):
self.domain['id'], self.rrset['id'])
# Ensure it fails with a 400
- response = self.client.post_json(url, body, status=400)
-
- self.assertEqual(400, response.status_int)
+ self._assert_exception('invalid_object', 400, self.client.post_json,
+ url, body)
# Add a junk field to the body
fixture['junk'] = 'Junk Field'
body = {'record': fixture}
- url = '/zones/%s/recordsets/%s/records' % (
- self.domain['id'], self.rrset['id'])
-
# Ensure it fails with a 400
- response = self.client.post_json(url, body, status=400)
+ self._assert_exception('invalid_object', 400, self.client.post_json,
+ url, body)
@patch.object(central_service.Service, 'create_record',
side_effect=rpc_common.Timeout())
@@ -84,14 +81,12 @@ class ApiV2RecordsTest(ApiV2TestCase):
url = '/zones/%s/recordsets/%s/records' % (
self.domain['id'], self.rrset['id'])
- response = self.client.post_json(url, body, status=504)
- self.assertEqual(504, response.json['code'])
- self.assertEqual('timeout', response.json['type'])
+ self._assert_exception('timeout', 504, self.client.post_json, url,
+ body)
@patch.object(central_service.Service, 'create_record',
side_effect=exceptions.DuplicateRecord())
def test_create_record_duplicate(self, _):
-
fixture = self.get_record_fixture(self.rrset['type'], fixture=0)
body = {'record': fixture}
@@ -99,9 +94,8 @@ class ApiV2RecordsTest(ApiV2TestCase):
url = '/zones/%s/recordsets/%s/records' % (
self.domain['id'], self.rrset['id'])
- response = self.client.post_json(url, body, status=409)
- self.assertEqual(409, response.json['code'])
- self.assertEqual('duplicate_record', response.json['type'])
+ self._assert_exception('duplicate_record', 409, self.client.post_json,
+ url, body)
def test_create_record_invalid_domain(self):
fixture = self.get_record_fixture(self.rrset['type'], fixture=0)
@@ -110,9 +104,9 @@ class ApiV2RecordsTest(ApiV2TestCase):
url = '/zones/ba751950-6193-11e3-949a-0800200c9a66/recordsets/' \
'ba751950-6193-11e3-949a-0800200c9a66/records'
- response = self.client.post_json(url, body, status=404)
- self.assertEqual(404, response.json['code'])
- self.assertEqual('domain_not_found', response.json['type'])
+
+ self._assert_exception('domain_not_found', 404, self.client.post_json,
+ url, body)
def test_create_record_invalid_rrset(self):
fixture = self.get_record_fixture(self.rrset['type'], fixture=0)
@@ -121,9 +115,9 @@ class ApiV2RecordsTest(ApiV2TestCase):
url = '/zones/%s/recordsets/' \
'ba751950-6193-11e3-949a-0800200c9a66/records' % self.domain['id']
- response = self.client.post_json(url, body, status=404)
- self.assertEqual(404, response.json['code'])
- self.assertEqual('recordset_not_found', response.json['type'])
+
+ self._assert_exception('recordset_not_found', 404,
+ self.client.post_json, url, body)
def test_get_records(self):
url = '/zones/%s/recordsets/%s/records' % (
@@ -147,15 +141,15 @@ class ApiV2RecordsTest(ApiV2TestCase):
self._assert_paging(data, url, key='records')
+ self._assert_invalid_paging(data, url, key='records')
+
@patch.object(central_service.Service, 'find_records',
side_effect=rpc_common.Timeout())
def test_get_records_timeout(self, _):
url = '/zones/ba751950-6193-11e3-949a-0800200c9a66/recordsets/' \
'ba751950-6193-11e3-949a-0800200c9a66/records'
- response = self.client.get(url, status=504)
- self.assertEqual(504, response.json['code'])
- self.assertEqual('timeout', response.json['type'])
+ self._assert_exception('timeout', 504, self.client.get, url)
def test_get_record(self):
# Create a record
@@ -187,10 +181,9 @@ class ApiV2RecordsTest(ApiV2TestCase):
url = '/zones/%s/recordsets/%s/records/' \
'ba751950-6193-11e3-949a-0800200c9a66' % (
self.domain['id'], self.rrset['id'])
- response = self.client.get(url, headers={'Accept': 'application/json'},
- status=504)
- self.assertEqual(504, response.json['code'])
- self.assertEqual('timeout', response.json['type'])
+
+ self._assert_exception('timeout', 504, self.client.get, url,
+ headers={'Accept': 'application/json'})
@patch.object(central_service.Service, 'get_record',
side_effect=exceptions.RecordNotFound())
@@ -198,13 +191,13 @@ class ApiV2RecordsTest(ApiV2TestCase):
url = '/zones/%s/recordsets/%s/records/' \
'ba751950-6193-11e3-949a-0800200c9a66' % (
self.domain['id'], self.rrset['id'])
- response = self.client.get(url, headers={'Accept': 'application/json'},
- status=404)
- self.assertEqual(404, response.json['code'])
- self.assertEqual('record_not_found', response.json['type'])
+
+ self._assert_exception('record_not_found', 404, self.client.get, url,
+ headers={'Accept': 'application/json'})
def test_get_record_invalid_id(self):
url = '/zones/%s/recordsets/%s/records/%s'
+
self._assert_invalid_uuid(self.client.get, url)
def test_update_record(self):
@@ -245,13 +238,15 @@ class ApiV2RecordsTest(ApiV2TestCase):
body = {'record': {'description': 'Tester'}, 'junk': 'Junk Field'}
# Ensure it fails with a 400
- self.client.patch_json(url, body, status=400)
+ self._assert_exception('invalid_object', 400, self.client.patch_json,
+ url, body)
# Prepare an update body with junk in the body
body = {'record': {'description': 'Tester', 'junk': 'Junk Field'}}
# Ensure it fails with a 400
- self.client.patch_json(url, body, status=400)
+ self._assert_exception('invalid_object', 400, self.client.patch_json,
+ url, body)
@patch.object(central_service.Service, 'get_record',
side_effect=exceptions.DuplicateRecord())
@@ -264,9 +259,9 @@ class ApiV2RecordsTest(ApiV2TestCase):
body = {'record': {'description': 'Tester'}}
# Ensure it fails with a 409
- response = self.client.patch_json(url, body, status=409)
- self.assertEqual(409, response.json['code'])
- self.assertEqual('duplicate_record', response.json['type'])
+ self._assert_exception('duplicate_record', 409, self.client.patch_json,
+ url, body,
+ headers={'Accept': 'application/json'})
@patch.object(central_service.Service, 'get_record',
side_effect=rpc_common.Timeout())
@@ -279,9 +274,8 @@ class ApiV2RecordsTest(ApiV2TestCase):
body = {'record': {'description': 'Tester'}}
# Ensure it fails with a 504
- response = self.client.patch_json(url, body, status=504)
- self.assertEqual(504, response.json['code'])
- self.assertEqual('timeout', response.json['type'])
+ self._assert_exception('timeout', 504, self.client.patch_json,
+ url, body)
@patch.object(central_service.Service, 'get_record',
side_effect=exceptions.RecordNotFound())
@@ -294,9 +288,8 @@ class ApiV2RecordsTest(ApiV2TestCase):
body = {'record': {'description': 'Tester'}}
# Ensure it fails with a 404
- response = self.client.patch_json(url, body, status=404)
- self.assertEqual(404, response.json['code'])
- self.assertEqual('record_not_found', response.json['type'])
+ self._assert_exception('record_not_found', 404, self.client.patch_json,
+ url, body)
def test_update_record_invalid_id(self):
url = '/zones/%s/recordsets/%s/records/%s'
@@ -317,7 +310,7 @@ class ApiV2RecordsTest(ApiV2TestCase):
'ba751950-6193-11e3-949a-0800200c9a66' % (
self.domain['id'], self.rrset['id'])
- self.client.delete(url, status=504)
+ self._assert_exception('timeout', 504, self.client.delete, url)
@patch.object(central_service.Service, 'delete_record',
side_effect=exceptions.RecordNotFound())
@@ -325,8 +318,11 @@ class ApiV2RecordsTest(ApiV2TestCase):
url = '/zones/%s/recordsets/%s/records/' \
'ba751950-6193-11e3-949a-0800200c9a66' % (
self.domain['id'], self.rrset['id'])
- self.client.delete(url, status=404)
+
+ self._assert_exception('record_not_found', 404, self.client.delete,
+ url)
def test_delete_record_invalid_id(self):
url = '/zones/%s/recordsets/%s/records/%s'
+
self._assert_invalid_uuid(self.client.delete, url)
diff --git a/designate/tests/test_api/test_v2/test_recordsets.py b/designate/tests/test_api/test_v2/test_recordsets.py
index b3dad2e9..dd37c039 100644
--- a/designate/tests/test_api/test_v2/test_recordsets.py
+++ b/designate/tests/test_api/test_v2/test_recordsets.py
@@ -62,19 +62,19 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
# Add a junk field to the wrapper
body = {'recordset': fixture, 'junk': 'Junk Field'}
- # Ensure it fails with a 400
- response = self.client.post_json(
- '/zones/%s/recordsets' % self.domain['id'], body, status=400)
+ url = '/zones/%s/recordsets' % self.domain['id']
- self.assertEqual(400, response.status_int)
+ # Ensure it fails with a 400
+ self._assert_exception(
+ 'invalid_object', 400, self.client.post_json, url, body)
# Add a junk field to the body
fixture['junk'] = 'Junk Field'
body = {'recordset': fixture}
# Ensure it fails with a 400
- response = self.client.post_json(
- '/zones/%s/recordsets' % self.domain['id'], body, status=400)
+ self._assert_exception(
+ 'invalid_object', 400, self.client.post_json, url, body)
@patch.object(central_service.Service, 'create_recordset',
side_effect=rpc_common.Timeout())
@@ -82,28 +82,38 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
fixture = self.get_recordset_fixture(self.domain['name'], fixture=0)
body = {'recordset': fixture}
- self.client.post_json('/zones/%s/recordsets' % self.domain['id'], body,
- status=504)
+
+ url = '/zones/%s/recordsets' % self.domain['id']
+
+ self._assert_exception('timeout', 504, self.client.post_json, url,
+ body)
@patch.object(central_service.Service, 'create_recordset',
- side_effect=exceptions.DuplicateDomain())
+ side_effect=exceptions.DuplicateRecordSet())
def test_create_recordset_duplicate(self, _):
fixture = self.get_recordset_fixture(self.domain['name'], fixture=0)
body = {'recordset': fixture}
- self.client.post_json('/zones/%s/recordsets' % self.domain['id'], body,
- status=409)
+
+ url = '/zones/%s/recordsets' % self.domain['id']
+
+ self._assert_exception('duplicate_recordset', 409,
+ self.client.post_json, url, body)
def test_create_recordset_invalid_domain(self):
fixture = self.get_recordset_fixture(self.domain['name'], fixture=0)
body = {'recordset': fixture}
- self.client.post_json(
- '/zones/ba751950-6193-11e3-949a-0800200c9a66/recordsets', body,
- status=404)
+
+ url = '/zones/ba751950-6193-11e3-949a-0800200c9a66/recordsets'
+
+ self._assert_exception('domain_not_found', 404, self.client.post_json,
+ url, body)
def test_get_recordsets(self):
- response = self.client.get('/zones/%s/recordsets' % self.domain['id'])
+ url = '/zones/%s/recordsets' % self.domain['id']
+
+ response = self.client.get(url)
# Check the headers are what we expect
self.assertEqual(200, response.status_int)
@@ -121,18 +131,19 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
name='x-%s.%s' % (i, self.domain['name']))
for i in xrange(0, 10)]
- url = '/zones/%s/recordsets' % self.domain['id']
self._assert_paging(data, url, key='recordsets')
+ self._assert_invalid_paging(data, url, key='recordsets')
+
def test_get_recordsets_invalid_id(self):
self._assert_invalid_uuid(self.client.get, '/zones/%s/recordsets')
@patch.object(central_service.Service, 'find_recordsets',
side_effect=rpc_common.Timeout())
def test_get_recordsets_timeout(self, _):
- self.client.get(
- '/zones/ba751950-6193-11e3-949a-0800200c9a66/recordsets',
- status=504)
+ url = '/zones/ba751950-6193-11e3-949a-0800200c9a66/recordsets'
+
+ self._assert_exception('timeout', 504, self.client.get, url)
def test_get_recordset(self):
# Create a recordset
@@ -163,18 +174,21 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
@patch.object(central_service.Service, 'get_recordset',
side_effect=rpc_common.Timeout())
def test_get_recordset_timeout(self, _):
- self.client.get('/zones/%s/recordsets/ba751950-6193-11e3-949a-0800200c'
- '9a66' % self.domain['id'],
- headers={'Accept': 'application/json'},
- status=504)
+ url = '/zones/%s/recordsets/ba751950-6193-11e3-949a-0800200c9a66' % (
+ self.domain['id'])
+
+ self._assert_exception('timeout', 504, self.client.get, url,
+ headers={'Accept': 'application/json'})
@patch.object(central_service.Service, 'get_recordset',
side_effect=exceptions.RecordSetNotFound())
def test_get_recordset_missing(self, _):
- self.client.get('/zones/%s/recordsets/ba751950-6193-11e3-949a-0800200c'
- '9a66' % self.domain['id'],
- headers={'Accept': 'application/json'},
- status=404)
+ url = '/zones/%s/recordsets/ba751950-6193-11e3-949a-0800200c9a66' % (
+ self.domain['id'])
+
+ self._assert_exception('recordset_not_found', 404,
+ self.client.get, url,
+ headers={'Accept': 'application/json'})
def test_update_recordset(self):
# Create a recordset
@@ -217,15 +231,16 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
# Ensure it fails with a 400
url = '/zones/%s/recordsets/%s' % (recordset['domain_id'],
recordset['id'])
- self.client.patch_json(url, body, status=400)
+
+ self._assert_exception('invalid_object', 400, self.client.patch_json,
+ url, body)
# Prepare an update body with junk in the body
body = {'recordset': {'description': 'Tester', 'junk': 'Junk Field'}}
# Ensure it fails with a 400
- url = '/zones/%s/recordsets/%s' % (recordset['domain_id'],
- recordset['id'])
- self.client.patch_json(url, body, status=400)
+ self._assert_exception('invalid_object', 400, self.client.patch_json,
+ url, body)
@patch.object(central_service.Service, 'get_recordset',
side_effect=exceptions.DuplicateRecordSet())
@@ -236,7 +251,9 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
# Ensure it fails with a 409
url = ('/zones/%s/recordsets/ba751950-6193-11e3-949a-0800200c9a66'
% (self.domain['id']))
- self.client.patch_json(url, body, status=409)
+
+ self._assert_exception('duplicate_recordset', 409,
+ self.client.patch_json, url, body)
@patch.object(central_service.Service, 'get_recordset',
side_effect=rpc_common.Timeout())
@@ -247,7 +264,9 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
# Ensure it fails with a 504
url = ('/zones/%s/recordsets/ba751950-6193-11e3-949a-0800200c9a66'
% (self.domain['id']))
- self.client.patch_json(url, body, status=504)
+
+ self._assert_exception('timeout', 504, self.client.patch_json, url,
+ body)
@patch.object(central_service.Service, 'get_recordset',
side_effect=exceptions.RecordSetNotFound())
@@ -258,7 +277,9 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
# Ensure it fails with a 404
url = ('/zones/%s/recordsets/ba751950-6193-11e3-949a-0800200c9a66'
% (self.domain['id']))
- self.client.patch_json(url, body, status=404)
+
+ self._assert_exception('recordset_not_found', 404,
+ self.client.patch_json, url, body)
def test_delete_recordset(self):
recordset = self.create_recordset(self.domain)
@@ -273,14 +294,16 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
url = ('/zones/%s/recordsets/ba751950-6193-11e3-949a-0800200c9a66'
% (self.domain['id']))
- self.client.delete(url, status=504)
+ self._assert_exception('timeout', 504, self.client.delete, url)
@patch.object(central_service.Service, 'delete_recordset',
side_effect=exceptions.RecordSetNotFound())
def test_delete_recordset_missing(self, _):
url = ('/zones/%s/recordsets/ba751950-6193-11e3-949a-0800200c9a66'
% (self.domain['id']))
- self.client.delete(url, status=404)
+
+ self._assert_exception('recordset_not_found', 404,
+ self.client.delete, url)
def test_delete_recordset_invalid_id(self):
self._assert_invalid_uuid(
diff --git a/designate/tests/test_api/test_v2/test_tlds.py b/designate/tests/test_api/test_v2/test_tlds.py
index c0e8fbe2..ff236ba4 100644
--- a/designate/tests/test_api/test_v2/test_tlds.py
+++ b/designate/tests/test_api/test_v2/test_tlds.py
@@ -44,9 +44,8 @@ class ApiV2TldsTest(ApiV2TestCase):
invalid_fixture = self.get_tld_fixture(-1)
# Ensure it fails with a 400
- response = self.client.post_json('/tlds/', {'tld': invalid_fixture},
- status=400)
- self.assertEqual(400, response.status_int)
+ self._assert_exception('invalid_object', 400, self.client.post_json,
+ '/tlds', {'tld': invalid_fixture})
def test_get_tlds(self):
self.policy({'find_tlds': '@'})
diff --git a/designate/tests/test_api/test_v2/test_zones.py b/designate/tests/test_api/test_v2/test_zones.py
index 0c951989..fc5260e5 100644
--- a/designate/tests/test_api/test_v2/test_zones.py
+++ b/designate/tests/test_api/test_v2/test_zones.py
@@ -31,20 +31,6 @@ class ApiV2ZonesTest(ApiV2TestCase):
# Create the default TLDs
self.create_default_tlds()
- def test_missing_accept(self):
- self.client.get('/zones/123', status=400)
-
- def test_bad_accept(self):
- self.client.get('/zones/123', headers={'Accept': 'test/goat'},
- status=406)
-
- def test_missing_content_type(self):
- self.client.post('/zones', status=415)
-
- def test_bad_content_type(self):
- self.client.post('/zones', headers={'Content-type': 'test/goat'},
- status=415)
-
def test_create_zone(self):
# Create a zone
fixture = self.get_domain_fixture(0)
@@ -78,25 +64,25 @@ class ApiV2ZonesTest(ApiV2TestCase):
body = {'zone': fixture, 'junk': 'Junk Field'}
# Ensure it fails with a 400
- response = self.client.post_json('/zones/', body, status=400)
- self.assertEqual(400, response.status_int)
+ self._assert_exception('invalid_object', 400, self.client.post_json,
+ '/zones', body)
# Add a junk field to the body
fixture['junk'] = 'Junk Field'
# Ensure it fails with a 400
body = {'zone': fixture}
- self.client.post_json('/zones/', body, status=400)
+
+ self._assert_exception('invalid_object', 400, self.client.post_json,
+ '/zones', body)
def test_create_zone_invalid_name(self):
# Try to create a zone with an invalid name
fixture = self.get_domain_fixture(-1)
- response = self.client.post_json('/zones/',
- {'zone': fixture},
- status=400)
# Ensure it fails with a 400
- self.assertEqual(400, response.status_int)
+ self._assert_exception('invalid_object', 400, self.client.post_json,
+ '/zones', {'zone': fixture})
@patch.object(central_service.Service, 'create_domain',
side_effect=rpc_common.Timeout())
@@ -104,7 +90,9 @@ class ApiV2ZonesTest(ApiV2TestCase):
fixture = self.get_domain_fixture(0)
body = {'zone': fixture}
- self.client.post_json('/zones/', body, status=504)
+
+ self._assert_exception('timeout', 504, self.client.post_json,
+ '/zones/', body)
@patch.object(central_service.Service, 'create_domain',
side_effect=exceptions.DuplicateDomain())
@@ -112,7 +100,18 @@ class ApiV2ZonesTest(ApiV2TestCase):
fixture = self.get_domain_fixture(0)
body = {'zone': fixture}
- self.client.post_json('/zones/', body, status=409)
+
+ self._assert_exception('duplicate_domain', 409, self.client.post_json,
+ '/zones/', body)
+
+ def test_create_zone_missing_content_type(self):
+ self._assert_exception('unsupported_content_type', 415,
+ self.client.post, '/zones')
+
+ def test_create_zone_bad_content_type(self):
+ self._assert_exception(
+ 'unsupported_content_type', 415, self.client.post, '/zones',
+ headers={'Content-type': 'test/goat'})
def test_get_zones(self):
response = self.client.get('/zones/')
@@ -136,31 +135,12 @@ class ApiV2ZonesTest(ApiV2TestCase):
for i in 'abcdefghij']
self._assert_paging(data, '/zones', key='zones')
- # Check for invalid limits, sort_dir, sort_key, marker
- response = self._assert_paging(data, '/zones', key='zones',
- limit='invalid_limit', status=400)
- self.assertEqual(400, response.status_int)
- self.assertEqual('invalid_limit', response.json['type'])
-
- response = self._assert_paging(data, '/zones', key='zones',
- sort_dir='invalid_sort_dir', status=400)
- self.assertEqual(400, response.status_int)
- self.assertEqual('invalid_sort_dir', response.json['type'])
-
- response = self._assert_paging(data, '/zones', key='zones',
- sort_key='invalid_sort_key', status=400)
- self.assertEqual(400, response.status_int)
- self.assertEqual('invalid_sort_key', response.json['type'])
-
- response = self._assert_paging(data, '/zones', key='zones',
- marker='invalid_marker', status=400)
- self.assertEqual(400, response.status_int)
- self.assertEqual('invalid_marker', response.json['type'])
+ self._assert_invalid_paging(data, '/zones', key='zones')
@patch.object(central_service.Service, 'find_domains',
side_effect=rpc_common.Timeout())
def test_get_zones_timeout(self, _):
- self.client.get('/zones/', status=504)
+ self._assert_exception('timeout', 504, self.client.get, '/zones/')
def test_get_zone(self):
# Create a zone
@@ -192,16 +172,26 @@ class ApiV2ZonesTest(ApiV2TestCase):
@patch.object(central_service.Service, 'get_domain',
side_effect=rpc_common.Timeout())
def test_get_zone_timeout(self, _):
- self.client.get('/zones/2fdadfb1-cf96-4259-ac6b-bb7b6d2ff980',
- headers={'Accept': 'application/json'},
- status=504)
+ url = '/zones/2fdadfb1-cf96-4259-ac6b-bb7b6d2ff980'
+ self._assert_exception('timeout', 504, self.client.get, url,
+ headers={'Accept': 'application/json'})
@patch.object(central_service.Service, 'get_domain',
side_effect=exceptions.DomainNotFound())
def test_get_zone_missing(self, _):
- self.client.get('/zones/2fdadfb1-cf96-4259-ac6b-bb7b6d2ff980',
- headers={'Accept': 'application/json'},
- status=404)
+ url = '/zones/2fdadfb1-cf96-4259-ac6b-bb7b6d2ff980'
+ self._assert_exception('domain_not_found', 404, self.client.get, url,
+ headers={'Accept': 'application/json'})
+
+ def test_get_zone_missing_accept(self):
+ url = '/zones/6e2146f3-87bc-4f47-adc5-4df0a5c78218'
+
+ self._assert_exception('bad_request', 400, self.client.get, url)
+
+ def test_get_zone_bad_accept(self):
+ url = '/zones/6e2146f3-87bc-4f47-adc5-4df0a5c78218'
+
+ self.client.get(url, headers={'Accept': 'test/goat'}, status=406)
def test_update_zone(self):
# Create a zone
@@ -242,15 +232,19 @@ class ApiV2ZonesTest(ApiV2TestCase):
body = {'zone': {'email': 'prefix-%s' % zone['email']},
'junk': 'Junk Field'}
+ url = '/zones/%s' % zone['id']
+
# Ensure it fails with a 400
- self.client.patch_json('/zones/%s' % zone['id'], body, status=400)
+ self._assert_exception('invalid_object', 400, self.client.patch_json,
+ url, body)
# Prepare an update body with junk in the body
body = {'zone': {'email': 'prefix-%s' % zone['email'],
'junk': 'Junk Field'}}
# Ensure it fails with a 400
- self.client.patch_json('/zones/%s' % zone['id'], body, status=400)
+ self._assert_exception('invalid_object', 400, self.client.patch_json,
+ url, body)
@patch.object(central_service.Service, 'get_domain',
side_effect=exceptions.DuplicateDomain())
@@ -258,9 +252,11 @@ class ApiV2ZonesTest(ApiV2TestCase):
# Prepare an update body
body = {'zone': {'email': 'example@example.org'}}
+ url = '/zones/2fdadfb1-cf96-4259-ac6b-bb7b6d2ff980'
+
# Ensure it fails with a 409
- self.client.patch_json('/zones/2fdadfb1-cf96-4259-ac6b-bb7b6d2ff980',
- body, status=409)
+ self._assert_exception('duplicate_domain', 409, self.client.patch_json,
+ url, body)
@patch.object(central_service.Service, 'get_domain',
side_effect=rpc_common.Timeout())
@@ -268,9 +264,11 @@ class ApiV2ZonesTest(ApiV2TestCase):
# Prepare an update body
body = {'zone': {'email': 'example@example.org'}}
+ url = '/zones/2fdadfb1-cf96-4259-ac6b-bb7b6d2ff980'
+
# Ensure it fails with a 504
- self.client.patch_json('/zones/2fdadfb1-cf96-4259-ac6b-bb7b6d2ff980',
- body, status=504)
+ self._assert_exception('timeout', 504, self.client.patch_json,
+ url, body)
@patch.object(central_service.Service, 'get_domain',
side_effect=exceptions.DomainNotFound())
@@ -278,9 +276,11 @@ class ApiV2ZonesTest(ApiV2TestCase):
# Prepare an update body
body = {'zone': {'email': 'example@example.org'}}
+ url = '/zones/2fdadfb1-cf96-4259-ac6b-bb7b6d2ff980'
+
# Ensure it fails with a 404
- self.client.patch_json('/zones/2fdadfb1-cf96-4259-ac6b-bb7b6d2ff980',
- body, status=404)
+ self._assert_exception('domain_not_found', 404, self.client.patch_json,
+ url, body)
def test_delete_zone(self):
zone = self.create_domain()
@@ -293,30 +293,36 @@ class ApiV2ZonesTest(ApiV2TestCase):
@patch.object(central_service.Service, 'delete_domain',
side_effect=rpc_common.Timeout())
def test_delete_zone_timeout(self, _):
- self.client.delete('/zones/2fdadfb1-cf96-4259-ac6b-bb7b6d2ff980',
- status=504)
+ url = '/zones/2fdadfb1-cf96-4259-ac6b-bb7b6d2ff980'
+
+ self._assert_exception('timeout', 504, self.client.delete, url)
@patch.object(central_service.Service, 'delete_domain',
side_effect=exceptions.DomainNotFound())
def test_delete_zone_missing(self, _):
- self.client.delete('/zones/2fdadfb1-cf96-4259-ac6b-bb7b6d2ff980',
- status=404)
+ url = '/zones/2fdadfb1-cf96-4259-ac6b-bb7b6d2ff980'
+
+ self._assert_exception('domain_not_found', 404, self.client.delete,
+ url)
# Zone import/export
def test_missing_origin(self):
- self.client.post('/zones',
- self.get_zonefile_fixture(variant='noorigin'),
- headers={'Content-type': 'text/dns'}, status=400)
+ fixture = self.get_zonefile_fixture(variant='noorigin')
+
+ self._assert_exception('bad_request', 400, self.client.post, '/zones',
+ fixture, headers={'Content-type': 'text/dns'})
def test_missing_soa(self):
- self.client.post('/zones',
- self.get_zonefile_fixture(variant='nosoa'),
- headers={'Content-type': 'text/dns'}, status=400)
+ fixture = self.get_zonefile_fixture(variant='nosoa')
+
+ self._assert_exception('bad_request', 400, self.client.post, '/zones',
+ fixture, headers={'Content-type': 'text/dns'})
def test_malformed_zonefile(self):
- self.client.post('/zones',
- self.get_zonefile_fixture(variant='malformed'),
- headers={'Content-type': 'text/dns'}, status=400)
+ fixture = self.get_zonefile_fixture(variant='malformed')
+
+ self._assert_exception('bad_request', 400, self.client.post, '/zones',
+ fixture, headers={'Content-type': 'text/dns'})
def test_import_export(self):
# Since v2 doesn't support getting records, import and export the