def test_update_quota(self): quota = utils.create_test_quota(context=self.ctx, project_id=self.project_id, resource=self.resource, limit=self.limit) dbapi.quota_update(self.ctx, quota.project_id, quota.resource, 200) updated_quota = dbapi.quota_get(self.ctx, quota.project_id, quota.resource) self.assertEqual(updated_quota.hard_limit, 200)
def test_get_quota(self, mock_db_inst, mock_write, mock_read): mock_db_inst.return_value = etcdapi.get_backend() mock_read.side_effect = etcd.EtcdKeyNotFound quota = utils.create_test_quota(context=self.context) mock_read.side_effect = lambda *args: utils.FakeEtcdResult( quota.as_dict()) res = dbapi.quota_get(self.context, quota.project_id, quota.resource) self.assertEqual(quota.hard_limit, res.hard_limit)
def get(cls, context, project_id, resource): """Find a quota based on project_id and resource :param project_id: the project id. :param context: security context. :param resource: the name of resource. :returns: a :class:`Quota` object. """ db_quota = dbapi.quota_get(context, project_id, resource) quota = Quota._from_db_object(cls(context), db_quota) return quota
def test_get_quota(self): quota = utils.create_test_quota(context=self.ctx, project_id=self.project_id, resource=self.resource, limit=self.limit) res = dbapi.quota_get(context=self.ctx, project_id=quota.project_id, resource=quota.resource) self.assertEqual(quota.project_id, res.project_id) self.assertEqual(quota.resource, res.resource) self.assertEqual(quota.hard_limit, res.hard_limit)