def get_all(cls, context, class_name=None): """Find quota based on class_name :param context: security context. :param class_name: the class name. :returns: a dict """ if class_name is None: res = dbapi.quota_class_get_default(context) else: res = dbapi.quota_class_get_all_by_name(context, class_name) return res
def test_get_quota_class_by_default(self, mock_db_inst, mock_write, mock_read): mock_db_inst.return_value = etcdapi.get_backend() mock_read.side_effect = etcd.EtcdKeyNotFound quota_class_1 = utils.create_test_quota_class( context=self.context, resource='fake_resource_1', hard_limit=10) quota_class_2 = utils.create_test_quota_class( context=self.context, resource='fake_resource_2', hard_limit=10) quota_classes = [quota_class_1, quota_class_2] mock_read.side_effect = lambda *args: utils.FakeEtcdMultipleResult( [quota_class_1.as_dict(), quota_class_2.as_dict()]) res = dbapi.quota_class_get_default(self.context) self.assertEqual([qc.resource for qc in res], [qc.resource for qc in quota_classes]) self.assertEqual([q.hard_limit for q in res], [q.hard_limit for q in quota_classes])
def test_get_default_quota_class(self): default_quota_class_resource_1 = utils.create_test_quota_class( context=self.ctx, class_name=consts.DEFAULT_QUOTA_CLASS_NAME, resource='resource_1', limit=10) default_quota_class_resource_2 = utils.create_test_quota_class( context=self.ctx, class_name=consts.DEFAULT_QUOTA_CLASS_NAME, resource='resource_2', limit=20) res = dbapi.quota_class_get_default(self.ctx) self.assertEqual(res['class_name'], consts.DEFAULT_QUOTA_CLASS_NAME) self.assertEqual(res[default_quota_class_resource_1.resource], default_quota_class_resource_1.hard_limit) self.assertEqual(res[default_quota_class_resource_2.resource], default_quota_class_resource_2.hard_limit)