Browse Source

Add unit tests for quota_class_update api

Change-Id: I7a8a374f3978bc08a47c11b657252946339dd6b8
changes/95/693795/7
minruigao 1 year ago
committed by Jiao Pengju
parent
commit
5cbb6dcbc9
1 changed files with 54 additions and 0 deletions
  1. +54
    -0
      karbor/tests/unit/api/v1/test_quota_classes.py

+ 54
- 0
karbor/tests/unit/api/v1/test_quota_classes.py View File

@ -13,9 +13,11 @@
import mock
from oslo_config import cfg
from webob import exc
from karbor.api.v1 import quota_classes
from karbor import context
from karbor import exception
from karbor.tests import base
from karbor.tests.unit.api import fakes
@ -40,6 +42,50 @@ class QuotaClassApiTest(base.TestCase):
req, '73f74f90a1754bd7ad658afb3272323f', body=body)
self.assertTrue(mock_quota_update.called)
@mock.patch(
'karbor.db.sqlalchemy.api.quota_class_create')
@mock.patch(
'karbor.db.sqlalchemy.api.quota_class_update')
def test_quota_update_with_quota_not_found(self,
mock_quota_class_update,
mock_quota_class_create):
body = {"quota_class": {"plans": 20}}
req = fakes.HTTPRequest.blank(
'/v1/quotas_classes/73f74f90a1754bd7ad658afb3272323f',
use_admin_context=True)
mock_quota_class_update.side_effect = exception.QuotaClassNotFound
self.controller.update(
req, '73f74f90a1754bd7ad658afb3272323f', body=body)
self.assertTrue(mock_quota_class_create.called)
def test_quota_update_with_invalid_type_value(self):
body = {"quota_class": {"plans": "fakevalue"}}
req = fakes.HTTPRequest.blank(
'/v1/quota_classes/73f74f90a1754bd7ad658afb3272323f',
use_admin_context=True)
self.assertRaises(exc.HTTPBadRequest, self.controller.update,
req, "73f74f90a1754bd7ad658afb3272323f", body=body)
def test_quota_update_with_invalid_num_value(self):
body = {"quota_class": {"plans": -2}}
req = fakes.HTTPRequest.blank(
'/v1/quota_classes/73f74f90a1754bd7ad658afb3272323f',
use_admin_context=True)
self.assertRaises(exc.HTTPBadRequest, self.controller.update,
req, "73f74f90a1754bd7ad658afb3272323f", body=body)
@mock.patch(
'karbor.db.sqlalchemy.api.quota_class_update')
def test_quota_update_with_invalid_key(self, mock_quota_class_update):
body = {"quota_class": {"fakekey": 20}}
req = fakes.HTTPRequest.blank(
'/v1/quota_classes/73f74f90a1754bd7ad658afb3272323f',
use_admin_context=True)
self.controller.update(
req, '73f74f90a1754bd7ad658afb3272323f', body=body)
self.assertEqual(0,
len(mock_quota_class_update.mock_calls))
@mock.patch(
'karbor.quota.DbQuotaDriver.get_class_quotas')
def test_quota_show(self, mock_quota_get):
@ -50,6 +96,14 @@ class QuotaClassApiTest(base.TestCase):
req, '73f74f90a1754bd7ad658afb3272323f')
self.assertTrue(mock_quota_get.called)
def test_quota_show_with_project_authorize_failed(self):
req = fakes.HTTPRequest.blank(
'/v1/quota_classes/73f74f90a1754bd7ad658afb3272323f',
use_admin_context=False)
self.assertRaises(
exc.HTTPForbidden, self.controller.show,
req, '73f74f90a1754bd7ad658afb3272323f')
def _quota_in_request_body(self):
quota_req = {
"plans": 20,


Loading…
Cancel
Save