From c83b097e66bd9a73f18fbb12d1711a57c8aa7901 Mon Sep 17 00:00:00 2001 From: Erik Olof Gunnar Andersson Date: Wed, 8 Nov 2023 06:12:34 -0800 Subject: [PATCH] Improved admin api coverage Change-Id: Ia94ae347318fa12b94c11276923877aff480cd0a --- .../test_admin/extensions/test_quotas.py | 24 +++++++++ .../test_admin/extensions/test_reports.py | 15 ++++++ designate/tests/unit/api/test_admin_api.py | 53 +++++++++++++++++++ 3 files changed, 92 insertions(+) diff --git a/designate/tests/test_api/test_admin/extensions/test_quotas.py b/designate/tests/test_api/test_admin/extensions/test_quotas.py index d3bd1725a..f1f8d7acd 100644 --- a/designate/tests/test_api/test_admin/extensions/test_quotas.py +++ b/designate/tests/test_api/test_admin/extensions/test_quotas.py @@ -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) diff --git a/designate/tests/test_api/test_admin/extensions/test_reports.py b/designate/tests/test_api/test_admin/extensions/test_reports.py index 198907391..26d1db137 100644 --- a/designate/tests/test_api/test_admin/extensions/test_reports.py +++ b/designate/tests/test_api/test_admin/extensions/test_reports.py @@ -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() diff --git a/designate/tests/unit/api/test_admin_api.py b/designate/tests/unit/api/test_admin_api.py index dcebbe30e..a3a3c6345 100644 --- a/designate/tests/unit/api/test_admin_api.py +++ b/designate/tests/unit/api/test_admin_api.py @@ -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):