deb-designate/designate/tests/test_quota/test_storage.py
Kiall Mac Innes c03a1406d0 Remove the StorageAPI class
The StorageAPI class's core functionality has been replaced with a small
decorator which handles TX's, removing the original need for the
StorageAPI class

Change-Id: I6fcf547bd977e4db085af9183d1c3f33f912488f
Partially-Implements: blueprint expose-soa-ns
2014-06-20 12:10:04 +01:00

94 lines
3.1 KiB
Python

# Copyright 2013 Hewlett-Packard Development Company, L.P.
#
# Author: Kiall Mac Innes <kiall@hp.com>
#
# 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 designate import quota
from designate import tests
from designate.openstack.common import log as logging
LOG = logging.getLogger(__name__)
class StorageQuotaTest(tests.TestCase):
def setUp(self):
super(StorageQuotaTest, self).setUp()
self.config(quota_driver='storage')
self.quota = quota.get_quota()
def test_set_quota_create(self):
context = self.get_admin_context()
context.all_tenants = True
quota = self.quota.set_quota(context, 'tenant_id', 'domains', 1500)
self.assertEqual(quota, {'domains': 1500})
# Drop into the storage layer directly to ensure the quota was created
# successfully
criterion = {
'tenant_id': 'tenant_id',
'resource': 'domains'
}
quota = self.quota.storage.find_quota(context, criterion)
self.assertEqual(quota['tenant_id'], 'tenant_id')
self.assertEqual(quota['resource'], 'domains')
self.assertEqual(quota['hard_limit'], 1500)
def test_set_quota_update(self):
context = self.get_admin_context()
context.all_tenants = True
# First up, Create the quota
self.quota.set_quota(context, 'tenant_id', 'domains', 1500)
# Next, update the quota
self.quota.set_quota(context, 'tenant_id', 'domains', 1234)
# Drop into the storage layer directly to ensure the quota was updated
# successfully
criterion = {
'tenant_id': 'tenant_id',
'resource': 'domains'
}
quota = self.quota.storage.find_quota(context, criterion)
self.assertEqual(quota['tenant_id'], 'tenant_id')
self.assertEqual(quota['resource'], 'domains')
self.assertEqual(quota['hard_limit'], 1234)
def test_reset_quotas(self):
context = self.get_admin_context()
context.all_tenants = True
# First up, Create a domains quota
self.quota.set_quota(context, 'tenant_id', 'domains', 1500)
# Then, Create a domain_records quota
self.quota.set_quota(context, 'tenant_id', 'domain_records', 800)
# Now, Reset the tenants quota
self.quota.reset_quotas(context, 'tenant_id')
# Drop into the storage layer directly to ensure the tenant has no
# specific quotas registed.
criterion = {
'tenant_id': 'tenant_id'
}
quotas = self.quota.storage.find_quotas(context, criterion)
self.assertEqual(0, len(quotas))