Add functional testing for the v2 API quotas endpoint

This is disabled by default, I7a0b828824ad6f274d922748f5f9a68157cd939a
will enable it.

Change-Id: I06180a7402fc45940d4b312666cf2dfd33af1305
diff --git a/designate_tempest_plugin/tests/api/admin/test_quotas.py b/designate_tempest_plugin/tests/api/admin/test_quotas.py
index 762f817..ae49460 100644
--- a/designate_tempest_plugin/tests/api/admin/test_quotas.py
+++ b/designate_tempest_plugin/tests/api/admin/test_quotas.py
@@ -12,17 +12,24 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 from oslo_log import log as logging
+from tempest import config
 from tempest.lib import decorators
 
 from designate_tempest_plugin.tests import base
 from designate_tempest_plugin import data_utils as dns_data_utils
 
 LOG = logging.getLogger(__name__)
+CONF = config.CONF
 
 
 class BaseQuotasTest(base.BaseDnsAdminTest):
-    # see: https://bugs.launchpad.net/designate/+bug/1573141
-    excluded_keys = ['api_expected_size']
+
+    excluded_keys = []
+
+    def setUp(self):
+        if CONF.dns_feature_enabled.bug_1573141_fixed:
+            self.excluded_keys = ['api_export_size']
+        super(BaseQuotasTest, self).setUp()
 
 
 class QuotasAdminTest(BaseQuotasTest):
@@ -39,14 +46,14 @@
     def test_show_quotas(self):
         LOG.info("Updating quotas")
         quotas = dns_data_utils.rand_quotas()
-        _, body = self.admin_client.update_quotas(**quotas['quota'])
+        _, body = self.admin_client.update_quotas(**quotas)
         self.addCleanup(self.admin_client.delete_quotas)
 
         LOG.info("Fetching quotas")
         _, body = self.admin_client.show_quotas()
 
         LOG.info("Ensuring the response has all quota types")
-        self.assertExpected(quotas['quota'], body['quota'], self.excluded_keys)
+        self.assertExpected(quotas, body['quota'], self.excluded_keys)
 
     @decorators.idempotent_id('33e0affb-5d66-4216-881c-f101a779851a')
     def test_delete_quotas(self):
@@ -60,8 +67,8 @@
     def test_update_quotas(self):
         LOG.info("Updating quotas")
         quotas = dns_data_utils.rand_quotas()
-        _, body = self.admin_client.update_quotas(**quotas['quota'])
+        _, body = self.admin_client.update_quotas(**quotas)
         self.addCleanup(self.admin_client.delete_quotas)
 
         LOG.info("Ensuring the response has all quota types")
-        self.assertExpected(quotas['quota'], body['quota'], self.excluded_keys)
+        self.assertExpected(quotas, body['quota'], self.excluded_keys)
diff --git a/designate_tempest_plugin/tests/api/v2/test_quotas.py b/designate_tempest_plugin/tests/api/v2/test_quotas.py
new file mode 100644
index 0000000..9411270
--- /dev/null
+++ b/designate_tempest_plugin/tests/api/v2/test_quotas.py
@@ -0,0 +1,124 @@
+# Copyright 2016 Rackspace
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+from oslo_log import log as logging
+from tempest import config
+from tempest.lib import decorators
+
+from designate_tempest_plugin.tests import base
+from designate_tempest_plugin import data_utils as dns_data_utils
+
+LOG = logging.getLogger(__name__)
+
+
+CONF = config.CONF
+
+
+class QuotasV2Test(base.BaseDnsV2Test):
+
+    credentials = ['primary', 'admin']
+
+    @classmethod
+    def skip_checks(cls):
+        super(QuotasV2Test, cls).skip_checks()
+
+        if not CONF.dns_feature_enabled.api_v2_quotas:
+            skip_msg = ("%s skipped as designate V2 Quotas API is not "
+                        "available" % cls.__name__)
+            raise cls.skipException(skip_msg)
+
+    @classmethod
+    def setup_clients(cls):
+        super(QuotasV2Test, cls).setup_clients()
+
+        cls.quotas_client = cls.os.quotas_client
+        cls.admin_client = cls.os_adm.quotas_client
+
+    @decorators.idempotent_id('1dac991a-9e2e-452c-a47a-26ac37381ec5')
+    def test_show_quotas(self):
+        LOG.info("Updating quotas")
+        quotas = dns_data_utils.rand_quotas()
+        _, body = self.admin_client.update_quotas(**quotas)
+        self.addCleanup(self.admin_client.delete_quotas)
+
+        LOG.info("Fetching quotas")
+        _, body = self.admin_client.show_quotas()
+
+        LOG.info("Ensuring the response has all quota types")
+        self.assertExpected(quotas, body, [])
+
+    @decorators.idempotent_id('0448b089-5803-4ce3-8a6c-5c15ff75a2cc')
+    def test_delete_quotas(self):
+        LOG.info("Deleting quotas")
+        _, body = self.admin_client.delete_quotas()
+
+        LOG.info("Ensuring an empty response body")
+        self.assertEqual(body.strip(), "")
+
+    @decorators.idempotent_id('76d24c87-1b39-4e19-947c-c08e1380dc61')
+    def test_update_quotas(self):
+        LOG.info("Updating quotas")
+        quotas = dns_data_utils.rand_quotas()
+        _, body = self.admin_client.update_quotas(**quotas)
+        self.addCleanup(self.admin_client.delete_quotas)
+
+        LOG.info("Ensuring the response has all quota types")
+        self.assertExpected(quotas, body, [])
+
+    @decorators.idempotent_id('76d24c87-1b39-4e19-947c-c08e1380dc61')
+    def test_update_quotas_other_project(self):
+
+        project_id = self.quotas_client.tenant_id
+
+        LOG.info("Updating quotas for %s ", project_id)
+
+        quotas = dns_data_utils.rand_quotas()
+        request = quotas.copy()
+        request['project_id'] = project_id
+        request['headers'] = {'X-Auth-All-Projects': True}
+        _, body = self.admin_client.update_quotas(**request)
+        self.addCleanup(self.admin_client.delete_quotas, project_id=project_id)
+
+        LOG.info("Ensuring the response has all quota types")
+        self.assertExpected(quotas, body, [])
+
+        _, client_body = self.quotas_client.show_quotas()
+
+        self.assertExpected(quotas, client_body, [])
+
+    @decorators.idempotent_id('21e45d30-dbc1-4173-9d6b-9b6813ef514b')
+    def test_reset_quotas_other_project(self):
+
+        # Use a fake project for this
+        project_id = '21e45d30-dbc1-4173-9d6b-9b6813ef514b'
+
+        _, original_quotas = self.admin_client.show_quotas(
+            project_id=project_id, headers={'X-Auth-All-Projects': True})
+
+        LOG.info("Updating quotas for %s ", project_id)
+
+        quotas = dns_data_utils.rand_quotas()
+        request = quotas.copy()
+        request['project_id'] = project_id
+        request['headers'] = {'X-Auth-All-Projects': True}
+        _, body = self.admin_client.update_quotas(**request)
+        self.addCleanup(self.admin_client.delete_quotas, project_id=project_id)
+
+        self.admin_client.delete_quotas(
+            project_id=project_id,
+            headers={'X-Auth-All-Projects': True})
+
+        _, final_quotas = self.admin_client.show_quotas(
+            project_id=project_id, headers={'X-Auth-All-Projects': True})
+
+        self.assertExpected(original_quotas, final_quotas, [])
diff --git a/designate_tempest_plugin/tests/base.py b/designate_tempest_plugin/tests/base.py
index 9f24d62..c86b38a 100644
--- a/designate_tempest_plugin/tests/base.py
+++ b/designate_tempest_plugin/tests/base.py
@@ -85,8 +85,8 @@
 class BaseDnsAdminTest(BaseDnsTest):
     """Base class for DNS Admin API tests."""
 
-    # Use the Designate V2 Client Manager
-    client_manager = clients.ManagerV2
+    # Use the Designate Admin Client Manager
+    client_manager = clients.ManagerAdmin
 
     @classmethod
     def skip_checks(cls):