Improved admin api coverage

Change-Id: Ia94ae347318fa12b94c11276923877aff480cd0a
This commit is contained in:
Erik Olof Gunnar Andersson 2023-11-08 06:12:34 -08:00
parent 4e185d4e26
commit c83b097e66
3 changed files with 92 additions and 0 deletions

View File

@ -48,6 +48,30 @@ class AdminApiQuotasTest(AdminApiTestCase):
self.assertEqual(CONF.quota_zones, max_zones)
self.assertEqual(CONF.quota_zone_records, max_zone_records)
def test_get_quotas_detailed(self):
self.policy({'get_quotas': '@'})
context = self.get_admin_context()
response = self.client.get(
'/quotas/%s?detail=yes' % context.project_id,
headers={'X-Test-Tenant-Id': context.project_id}
)
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn('quota', response.json)
self.assertIn('zones', response.json['quota'])
self.assertIn('api_export_size', response.json['quota'])
self.assertIn('zone_records', response.json['quota'])
self.assertIn('zone_recordsets', response.json['quota'])
self.assertIn('recordset_records', response.json['quota'])
max_zones = response.json['quota']['zones']
max_zone_records = response.json['quota']['zone_records']
self.assertEqual(CONF.quota_zones, max_zones)
self.assertEqual(CONF.quota_zone_records, max_zone_records)
def test_patch_quotas(self):
self.policy({'set_quotas': '@'})
context = self.get_context(project_id='a', is_admin=True)

View File

@ -145,6 +145,21 @@ class AdminApiReportsTest(AdminApiTestCase):
self.assertEqual(1, response.json['tenants'][0]['zone_count'])
def test_get_tenants_detailed(self):
self.policy({'find_tenants': '@'})
self.create_zone(fixture=0)
self.create_zone(fixture=1)
response = self.client.get('/reports/tenants?detail=yes')
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn('tenants', response.json)
self.assertIn('zones_count', response.json['tenants'][0])
self.assertEqual(2, response.json['tenants'][0]['zones_count'])
def test_get_tenant(self):
self.policy({'find_tenants': '@'})
zone = self.create_zone()

View File

@ -17,6 +17,7 @@ from unittest import mock
from designate.api.admin.views import base
from designate import exceptions
from designate import objects
import designate.tests
@ -30,6 +31,58 @@ class TestAdminAPI(designate.tests.TestCase):
def setUp(self):
super().setUp()
def test_show_basic(self):
zone_list = objects.ZoneList(objects=[objects.Zone()])
base_view = base.BaseView()
self.assertRaises(
NotImplementedError,
base_view.list,
mock.Mock(),
MockRequest(GET=dict(limit='1')),
zone_list
)
def test_show_detailed(self):
zone_list = objects.ZoneList(objects=[objects.Zone()])
base_view = base.BaseView()
self.assertRaises(
NotImplementedError,
base_view.list,
mock.Mock(),
MockRequest(GET=dict(limit='1', detail='yes')),
zone_list
)
def test_load_invalid_keys(self):
body = {'zone': {'one': 1, 'four': 4}}
valid_keys = ('one', 'two', 'three',)
base_view = base.BaseView()
base_view._resource_name = 'zone'
self.assertRaisesRegex(
exceptions.InvalidObject,
'Provided object does not match schema.',
base_view._load, None, None, body, valid_keys
)
@mock.patch.object(base.BaseView, 'show_detail')
def test_paged_list(self, mock_show_detail):
zone_list = objects.ZoneList(objects=[objects.Zone()], total_count=1)
base_view = base.BaseView()
result = base_view.list(
mock.Mock(),
MockRequest(GET=dict(limit='1', detail='yes')),
zone_list
)
self.assertEqual(1, result['metadata']['total_count'])
@mock.patch.object(base.BaseView, '_get_collection_href')
@mock.patch.object(base.BaseView, '_get_next_href')
def test_limit_max(self, mock_coll_href, mock_next_href):