"Fossies" - the Fresh Open Source Software Archive

Member "karbor-1.3.0/karbor/tests/unit/api/v1/test_quotas.py" (26 Mar 2019, 4032 Bytes) of package /linux/misc/openstack/karbor-1.3.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 latest Fossies "Diffs" side-by-side code changes report for "test_quotas.py": 1.1.0_vs_1.3.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 
   14 import mock
   15 from oslo_config import cfg
   16 from webob import exc
   17 
   18 from karbor.api.v1 import quotas
   19 from karbor import context
   20 from karbor.tests import base
   21 from karbor.tests.unit.api import fakes
   22 
   23 CONF = cfg.CONF
   24 
   25 
   26 class QuotaApiTest(base.TestCase):
   27     def setUp(self):
   28         super(QuotaApiTest, self).setUp()
   29         self.controller = quotas.QuotasController()
   30         self.ctxt = context.RequestContext('demo', 'fakeproject', True)
   31 
   32     @mock.patch(
   33         'karbor.db.sqlalchemy.api.quota_update')
   34     def test_quota_update(self, mock_quota_update):
   35         quota = self._quota_in_request_body()
   36         body = {"quota": quota}
   37         req = fakes.HTTPRequest.blank(
   38             '/v1/quotas/73f74f90a1754bd7ad658afb3272323f',
   39             use_admin_context=True)
   40         self.controller.update(
   41             req, '73f74f90a1754bd7ad658afb3272323f', body=body)
   42         self.assertTrue(mock_quota_update.called)
   43 
   44     def test_quota_update_invalid_project_id(self):
   45         quota = self._quota_in_request_body()
   46         body = {"quota": quota}
   47         req = fakes.HTTPRequest.blank(
   48             '/v1/quotas/111', use_admin_context=True)
   49         self.assertRaises(exc.HTTPBadRequest, self.controller.update,
   50                           req, '111', body=body)
   51 
   52     @mock.patch(
   53         'karbor.quota.DbQuotaDriver.get_defaults')
   54     def test_quota_defaults(self, mock_quota_get):
   55         req = fakes.HTTPRequest.blank(
   56             'v1/quotas/73f74f90a1754bd7ad658afb3272323f',
   57             use_admin_context=True)
   58         self.controller.defaults(
   59             req, '73f74f90a1754bd7ad658afb3272323f')
   60         self.assertTrue(mock_quota_get.called)
   61 
   62     @mock.patch(
   63         'karbor.quota.DbQuotaDriver.get_project_quotas')
   64     def test_quota_detail(self, mock_quota_get):
   65         req = fakes.HTTPRequest.blank(
   66             '/v1/quotas/73f74f90a1754bd7ad658afb3272323f',
   67             use_admin_context=True)
   68         self.controller.detail(
   69             req, '73f74f90a1754bd7ad658afb3272323f')
   70         self.assertTrue(mock_quota_get.called)
   71 
   72     @mock.patch(
   73         'karbor.quota.DbQuotaDriver.get_project_quotas')
   74     def test_quota_show(self, moak_quota_get):
   75         req = fakes.HTTPRequest.blank(
   76             '/v1/quotas/73f74f90a1754bd7ad658afb3272323f',
   77             use_admin_context=True)
   78         self.controller.show(
   79             req, '73f74f90a1754bd7ad658afb3272323f')
   80         self.assertTrue(moak_quota_get.called)
   81 
   82     def test_quota_show_invalid(self):
   83         req = fakes.HTTPRequest.blank('/v1/quotas/1',
   84                                       use_admin_context=True)
   85         self.assertRaises(
   86             exc.HTTPBadRequest, self.controller.show,
   87             req, "1")
   88 
   89     @mock.patch(
   90         'karbor.quota.DbQuotaDriver.destroy_all_by_project')
   91     def test_quota_delete(self, moak_restore_get):
   92         req = fakes.HTTPRequest.blank(
   93             '/v1/quotas/73f74f90a1754bd7ad658afb3272323f',
   94             use_admin_context=True)
   95         self.controller.delete(
   96             req, '73f74f90a1754bd7ad658afb3272323f')
   97         self.assertTrue(moak_restore_get.called)
   98 
   99     def test_quota_delete_invalid(self):
  100         req = fakes.HTTPRequest.blank('/v1/quotas/1',
  101                                       use_admin_context=True)
  102         self.assertRaises(
  103             exc.HTTPBadRequest, self.controller.delete,
  104             req, "1")
  105 
  106     def _quota_in_request_body(self):
  107         quota_req = {
  108             "plans": 20,
  109         }
  110         return quota_req