Improve API Controllers coverage

- Removed unnecessary error handling.

Change-Id: I669b3081bc724d7d30df3cc8ad5e82dcad81889b
This commit is contained in:
Erik Olof Gunnar Andersson 2023-12-08 12:00:34 -08:00
parent f424245d56
commit 41b4903b18
11 changed files with 60 additions and 16 deletions

View File

@ -201,7 +201,8 @@ class TestContextMiddleware(ContextMiddleware):
headers = request.headers
all_tenants = strutils.bool_from_string(
headers.get('X-Test-All-Tenants', 'False'))
headers.get('X-Test-All-Tenants', 'False')
)
role_header = headers.get('X-Test-Role', None)
role_header = role_header.lower() if role_header else None

View File

@ -46,7 +46,7 @@ class FloatingIPController(rest.RestController):
fips = self.central_api.list_floatingips(context)
LOG.info("Retrieved %(fips)s", {'fips': fips})
LOG.info('Retrieved %(fips)s', {'fips': fips})
return DesignateAdapter.render('API_v2', fips, request=request)
@ -59,14 +59,7 @@ class FloatingIPController(rest.RestController):
response = pecan.response
context = request.environ['context']
try:
body = request.body_dict
except Exception as e:
if str(e) != 'TODO: Unsupported Content Type':
raise
else:
# Got a blank body
body = dict()
body = request.body_dict
region, id_ = fip_key_to_data(fip_key)
@ -74,7 +67,7 @@ class FloatingIPController(rest.RestController):
fip.validate()
LOG.info("Updated %(fip)s", {'fip': fip})
LOG.info('Updated %(fip)s', {'fip': fip})
fip = self.central_api.update_floatingip(context, region, id_, fip)
@ -95,6 +88,6 @@ class FloatingIPController(rest.RestController):
fip = self.central_api.get_floatingip(context, region, id_)
LOG.info("Retrieved %(fip)s", {'fip': fip})
LOG.info('Retrieved %(fip)s', {'fip': fip})
return DesignateAdapter.render('API_v2', fip, request=request)

View File

@ -73,7 +73,8 @@ class QuotasController(rest.RestController):
if context.project_id is None and not context.all_tenants:
raise exceptions.MissingProjectID(
"The all-projects flag must be used when using non-project "
"scoped tokens.")
"scoped tokens."
)
for quota in quotas:
self.central_api.set_quota(context, project_id, quota.resource,

View File

@ -38,7 +38,7 @@ class AbandonController(rest.RestController):
zone = self.central_api.delete_zone(context, zone_id)
if zone.deleted_at:
response.status_int = 204
LOG.info("Abandoned %(zone)s", {'zone': zone})
LOG.info('Abandoned %(zone)s', {'zone': zone})
else:
response.status_int = 500

View File

@ -74,7 +74,8 @@ class ZoneImportController(rest.RestController):
if request.content_type != 'text/dns':
raise exceptions.UnsupportedContentType(
'Content-type must be text/dns')
'Content-type must be text/dns'
)
# Create the zone_import
zone_import = self.central_api.create_zone_import(

View File

@ -126,7 +126,15 @@ class ApiV2BlacklistsTest(ApiV2TestCase):
self.assertEqual('prefix-%s' % blacklist['description'],
response.json['description'])
def test_update_bkaclist_invalid_id(self):
def test_update_blacklist_json_patch_not_implemented(self):
self._assert_exception(
'unknown', 500, self.client.patch_json,
'/blacklists/04955322-1d35-4761-949c-89fcec220de6',
{'description': 'Tester'},
content_type='application/json-patch+json'
)
def test_update_blacklist_invalid_id(self):
self._assert_invalid_uuid(self.client.patch_json, '/blacklists/%s')
def test_get_blacklists_filter(self):

View File

@ -130,6 +130,13 @@ class APIV2ZoneImportExportTest(ApiV2TestCase):
exported.delete_rdataset(exported.origin, 'NS')
self.assertEqual(imported, exported)
def test_import_method_not_allowed(self):
self._assert_exception(
'unsupported_content_type', 415, self.client.post,
'/zones/tasks/imports', {},
content_type='application/json'
)
def test_delete_import(self):
post_response = self.client.post('/zones/tasks/imports',
self.get_zonefile_fixture(),

View File

@ -280,6 +280,14 @@ class ApiV2PoolsTest(ApiV2TestCase):
[n.hostname for n in pool['ns_records']],
[n['hostname'] for n in response.json['ns_records']])
def test_update_pool_json_patch_not_implemented(self):
self._assert_exception(
'unknown', 500, self.client.patch_json,
'/pools/c82bab73-3d63-44df-af85-374be67de38b',
{'description': 'Tester'},
content_type='application/json-patch+json'
)
def test_update_pool_ns_records(self):
# Create a pool
pool = self.create_pool()

View File

@ -145,6 +145,14 @@ class ApiV2TldsTest(ApiV2TestCase):
self.assertEqual('prefix-%s' % tld['description'],
response.json['description'])
def test_update_tld_json_patch_not_implemented(self):
self._assert_exception(
'unknown', 500, self.client.patch_json,
'/tlds/f8efb6cb-68c2-4dfb-954c-c6792369d553',
{'description': 'Tester'},
content_type='application/json-patch+json'
)
def test_update_tld_description_too_long(self):
tld = self.create_tld(fixture=0)
self.policy({'update_tld': '@'})

View File

@ -242,6 +242,14 @@ class ApiV2TsigKeysTest(ApiV2TestCase):
self.assertEqual('prefix-%s' % tsigkey['secret'],
response.json['secret'])
def test_update_tsigkey_json_patch_not_implemented(self):
self._assert_exception(
'unknown', 500, self.client.patch_json,
'/tsigkeys/b0f331f1-7683-4444-aa68-b1d29e40924b',
{'secret': 'secret'},
content_type='application/json-patch+json'
)
def test_update_tsigkey_invalid_id(self):
self._assert_invalid_uuid(self.client.patch_json, '/tsigkeys/%s')

View File

@ -166,6 +166,15 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
'TEST', response.json['description'])
self.assertIn('updated_at', response.json)
def test_update_zone_transfer_request_json_patch_not_implemented(self):
self._assert_exception(
'unknown', 500, self.client.patch_json,
'/zones/tasks/transfer_requests/'
'5c0614e6-1a04-487d-818a-441c3971d401',
{'description': 'Tester'},
content_type='application/json-patch+json'
)
def test_delete_zone_transfer_request(self):
initial = self.client.post_json(
'/zones/%s/tasks/transfer_requests' % self.zone.id,