"Fossies" - the Fresh Open Source Software Archive

Member "zun-4.0.0/zun/tests/unit/db/test_quota_classes.py" (16 Oct 2019, 4712 Bytes) of package /linux/misc/openstack/zun-4.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "test_quota_classes.py": 2.1.0_vs_3.0.0.

    1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    2 #    not use this file except in compliance with the License. You may obtain
    3 #    a copy of the License at
    4 #
    5 #         http://www.apache.org/licenses/LICENSE-2.0
    6 #
    7 #    Unless required by applicable law or agreed to in writing, software
    8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   10 #    License for the specific language governing permissions and limitations
   11 #    under the License.
   12 
   13 """Tests for manipulating Quota via the DB API"""
   14 
   15 from zun.common import consts
   16 from zun.common import context
   17 import zun.conf
   18 from zun.db import api as dbapi
   19 from zun.tests.unit.db import base
   20 from zun.tests.unit.db import utils
   21 
   22 CONF = zun.conf.CONF
   23 
   24 
   25 class DBQuotaClassesTestCase(base.DbTestCase):
   26 
   27     def setUp(self):
   28         super(DBQuotaClassesTestCase, self).setUp()
   29         self.ctx = context.get_admin_context()
   30         self.class_name = 'default'
   31         self.resource = 'containers'
   32         self.limit = 100
   33 
   34     def test_create_quota_class(self):
   35         quota_class = utils.create_test_quota_class(context=self.ctx,
   36                                                     class_name=self.class_name,
   37                                                     resource=self.resource,
   38                                                     limit=self.limit)
   39         self.assertEqual(quota_class.class_name, self.class_name)
   40         self.assertEqual(quota_class.resource, self.resource)
   41         self.assertEqual(quota_class.hard_limit, self.limit)
   42 
   43     def test_get_quota_class(self):
   44         quota_class = utils.create_test_quota_class(context=self.ctx,
   45                                                     class_name=self.class_name,
   46                                                     resource=self.resource,
   47                                                     limit=self.limit)
   48         res = dbapi.quota_class_get(context=self.ctx,
   49                                     class_name=quota_class.class_name,
   50                                     resource=quota_class.resource)
   51         self.assertEqual(quota_class.class_name, res.class_name)
   52         self.assertEqual(quota_class.resource, res.resource)
   53         self.assertEqual(quota_class.hard_limit, res.hard_limit)
   54 
   55     def test_get_default_quota_class(self):
   56         default_quota_class_resource_1 = utils.create_test_quota_class(
   57             context=self.ctx,
   58             class_name=consts.DEFAULT_QUOTA_CLASS_NAME,
   59             resource='resource_1',
   60             limit=10)
   61 
   62         default_quota_class_resource_2 = utils.create_test_quota_class(
   63             context=self.ctx,
   64             class_name=consts.DEFAULT_QUOTA_CLASS_NAME,
   65             resource='resource_2',
   66             limit=20)
   67 
   68         res = dbapi.quota_class_get_default(self.ctx)
   69         self.assertEqual(res['class_name'],
   70                          consts.DEFAULT_QUOTA_CLASS_NAME)
   71         self.assertEqual(res[default_quota_class_resource_1.resource],
   72                          default_quota_class_resource_1.hard_limit)
   73         self.assertEqual(res[default_quota_class_resource_2.resource],
   74                          default_quota_class_resource_2.hard_limit)
   75 
   76     def test_get_all_by_name_quota_class(self):
   77         quota_class_resource_1 = utils.create_test_quota_class(
   78             context=self.ctx,
   79             class_name='class_1',
   80             resource='resource_1',
   81             limit=10)
   82 
   83         quota_class_resource_2 = utils.create_test_quota_class(
   84             context=self.ctx,
   85             class_name='class_1',
   86             resource='resource_2',
   87             limit=20)
   88 
   89         res = dbapi.quota_class_get_all_by_name(self.ctx, 'class_1')
   90         self.assertEqual(res['class_name'],
   91                          'class_1')
   92         self.assertEqual(res[quota_class_resource_1.resource],
   93                          quota_class_resource_1.hard_limit)
   94         self.assertEqual(res[quota_class_resource_2.resource],
   95                          quota_class_resource_2.hard_limit)
   96 
   97     def test_update_quota_class(self):
   98         quota_class = utils.create_test_quota_class(context=self.ctx,
   99                                                     class_name=self.class_name,
  100                                                     resource=self.resource,
  101                                                     limit=self.limit)
  102         dbapi.quota_class_update(
  103             self.ctx, quota_class.class_name,
  104             quota_class.resource, 200)
  105         updated_quota_class = dbapi.quota_class_get(
  106             self.ctx, quota_class.class_name,
  107             quota_class.resource)
  108         self.assertEqual(updated_quota_class.hard_limit, 200)