示例#1
0
 def test_get_one_not_authorized(self):
     obj_utils.create_test_quota(self.context)
     response = self.get_json('/quotas/invalid_proj/invalid_res',
                              expect_errors=True)
     self.assertEqual(403, response.status_int)
     self.assertEqual('application/json', response.content_type)
     self.assertTrue(response.json['errors'])
示例#2
0
 def test_get_one_not_authorized(self):
     obj_utils.create_test_quota(self.context)
     response = self.get_json(
         '/quotas/invalid_proj/invalid_res',
         expect_errors=True)
     self.assertEqual(403, response.status_int)
     self.assertEqual('application/json', response.content_type)
     self.assertTrue(response.json['errors'])
示例#3
0
 def test_get_one(self, mock_policy):
     mock_policy.return_value = True
     quota = obj_utils.create_test_quota(self.context)
     response = self.get_json('/quotas/%s/%s' %
                              (quota['project_id'], quota['resource']))
     self.assertEqual(quota.project_id, response['project_id'])
     self.assertEqual(quota.resource, response['resource'])
示例#4
0
 def test_get_one(self, mock_policy):
     mock_policy.return_value = True
     quota = obj_utils.create_test_quota(self.context)
     response = self.get_json('/quotas/%s/%s' % (quota['project_id'],
                                                 quota['resource']))
     self.assertEqual(quota.project_id, response['project_id'])
     self.assertEqual(quota.resource, response['resource'])
示例#5
0
    def test_get_all_with_non_admin_context(self, mock_context, mock_policy):
        mock_context.return_value = self.context
        quota_list = []
        for i in range(4):
            quota = obj_utils.create_test_quota(self.context,
                                                project_id="proj-id-" + str(i))
            quota_list.append(quota)

        self.context.is_admin = False
        response = self.get_json('/quotas?all_tenants=True')
        self.assertEqual(0, len(response['quotas']))
示例#6
0
    def test_get_all_non_admin(self):
        quota_list = []
        for i in range(4):
            quota = obj_utils.create_test_quota(self.context,
                                                project_id="proj-id-"+str(i))
            quota_list.append(quota)

        headers = {'X-Project-Id': 'proj-id-2'}
        response = self.get_json('/quotas', headers=headers)
        self.assertEqual(1, len(response['quotas']))
        self.assertEqual('proj-id-2', response['quotas'][0]['project_id'])
示例#7
0
    def test_get_all_non_admin(self):
        quota_list = []
        for i in range(4):
            quota = obj_utils.create_test_quota(self.context,
                                                project_id="proj-id-"+str(i))
            quota_list.append(quota)

        headers = {'X-Project-Id': 'proj-id-2'}
        response = self.get_json('/quotas', headers=headers)
        self.assertEqual(1, len(response['quotas']))
        self.assertEqual('proj-id-2', response['quotas'][0]['project_id'])
示例#8
0
    def test_get_all_with_non_admin_context(self, mock_context, mock_policy):
        mock_context.return_value = self.context
        quota_list = []
        for i in range(4):
            quota = obj_utils.create_test_quota(self.context,
                                                project_id="proj-id-"+str(i))
            quota_list.append(quota)

        self.context.is_admin = False
        response = self.get_json('/quotas?all_tenants=True')
        self.assertEqual(0, len(response['quotas']))
示例#9
0
    def test_get_all_admin_not_all_tenants(self, mock_context, mock_policy):
        mock_context.return_value = self.context
        quota_list = []
        for i in range(4):
            quota = obj_utils.create_test_quota(self.context,
                                                project_id="proj-id-"+str(i))
            quota_list.append(quota)

        self.context.is_admin = True
        self.context.project_id = 'proj-id-1'
        response = self.get_json('/quotas')
        self.assertEqual(1, len(response['quotas']))
        self.assertEqual('proj-id-1', response['quotas'][0]['project_id'])
示例#10
0
    def test_get_all_admin_not_all_tenants(self, mock_context, mock_policy):
        mock_context.return_value = self.context
        quota_list = []
        for i in range(4):
            quota = obj_utils.create_test_quota(self.context,
                                                project_id="proj-id-"+str(i))
            quota_list.append(quota)

        self.context.is_admin = True
        self.context.project_id = 'proj-id-1'
        response = self.get_json('/quotas')
        self.assertEqual(1, len(response['quotas']))
        self.assertEqual('proj-id-1', response['quotas'][0]['project_id'])
示例#11
0
    def test_get_all_admin_all_tenants(self, mock_context, mock_policy):
        mock_context.return_value = self.context
        quota_list = []
        for i in range(4):
            quota = obj_utils.create_test_quota(self.context,
                                                project_id="proj-id-"+str(i))
            quota_list.append(quota)

        self.context.is_admin = True
        response = self.get_json('/quotas?all_tenants=True')
        self.assertEqual(4, len(response['quotas']))
        expected = [r.project_id for r in quota_list]
        res_proj_ids = [r['project_id'] for r in response['quotas']]
        self.assertEqual(sorted(expected), sorted(res_proj_ids))
示例#12
0
    def test_get_all_admin_all_tenants(self, mock_context, mock_policy):
        mock_context.return_value = self.context
        quota_list = []
        for i in range(4):
            quota = obj_utils.create_test_quota(self.context,
                                                project_id="proj-id-"+str(i))
            quota_list.append(quota)

        self.context.is_admin = True
        response = self.get_json('/quotas?all_tenants=True')
        self.assertEqual(4, len(response['quotas']))
        expected = [r.project_id for r in quota_list]
        res_proj_ids = [r['project_id'] for r in response['quotas']]
        self.assertEqual(sorted(expected), sorted(res_proj_ids))
示例#13
0
    def test_get_all_admin_all_with_pagination_marker(self, mock_context,
                                                      mock_policy):
        mock_context.return_value = self.context
        quota_list = []
        for i in range(4):
            quota = obj_utils.create_test_quota(self.context,
                                                project_id="proj-id-"+str(i))
            quota_list.append(quota)

        self.context.is_admin = True
        response = self.get_json('/quotas?limit=3&marker=%s&all_tenants=True'
                                 % quota_list[2].id)
        self.assertEqual(1, len(response['quotas']))
        self.assertEqual(quota_list[-1].project_id,
                         response['quotas'][0]['project_id'])
示例#14
0
    def test_get_all_admin_all_with_pagination_marker(self, mock_context,
                                                      mock_policy):
        mock_context.return_value = self.context
        quota_list = []
        for i in range(4):
            quota = obj_utils.create_test_quota(self.context,
                                                project_id="proj-id-"+str(i))
            quota_list.append(quota)

        self.context.is_admin = True
        response = self.get_json('/quotas?limit=3&marker=%s&all_tenants=True'
                                 % quota_list[2].id)
        self.assertEqual(1, len(response['quotas']))
        self.assertEqual(quota_list[-1].project_id,
                         response['quotas'][0]['project_id'])
示例#15
0
    def test_get_all_with_pagination_limit(self, mock_context, mock_policy):
        mock_context.return_value = self.context
        quota_list = []
        for i in range(4):
            quota = obj_utils.create_test_quota(self.context,
                                                project_id="proj-id-" + str(i))
            quota_list.append(quota)

        self.context.is_admin = True
        response = self.get_json('/quotas?limit=2&all_tenants=True')
        self.assertEqual(2, len(response['quotas']))
        expected = [r.project_id for r in quota_list[:2]]
        res_proj_ids = [r['project_id'] for r in response['quotas']]
        self.assertEqual(sorted(expected), sorted(res_proj_ids))
        self.assertTrue('http://localhost/v1/quotas?' in response['next'])
        self.assertTrue('sort_key=id' in response['next'])
        self.assertTrue('sort_dir=asc' in response['next'])
        self.assertTrue('limit=2' in response['next'])
        self.assertTrue('marker=%s' % quota_list[1].id in response['next'])
示例#16
0
    def test_get_all_with_pagination_limit(self, mock_context,
                                           mock_policy):
        mock_context.return_value = self.context
        quota_list = []
        for i in range(4):
            quota = obj_utils.create_test_quota(self.context,
                                                project_id="proj-id-"+str(i))
            quota_list.append(quota)

        self.context.is_admin = True
        response = self.get_json('/quotas?limit=2&all_tenants=True')
        self.assertEqual(2, len(response['quotas']))
        expected = [r.project_id for r in quota_list[:2]]
        res_proj_ids = [r['project_id'] for r in response['quotas']]
        self.assertEqual(sorted(expected), sorted(res_proj_ids))
        self.assertTrue('http://localhost/v1/quotas?' in response['next'])
        self.assertTrue('sort_key=id' in response['next'])
        self.assertTrue('sort_dir=asc' in response['next'])
        self.assertTrue('limit=2' in response['next'])
        self.assertTrue('marker=%s' % quota_list[1].id in response['next'])
示例#17
0
 def test_get_one(self):
     quota = obj_utils.create_test_quota(self.context)
     response = self.get_json('/quotas/%s/%s' % (quota['project_id'],
                                                 quota['resource']))
     self.assertEqual(quota.project_id, response['project_id'])
     self.assertEqual(quota.resource, response['resource'])
示例#18
0
 def test_one(self):
     quota = obj_utils.create_test_quota(self.context)
     response = self.get_json('/quotas')
     self.assertEqual(quota.project_id, response['quotas'][0]["project_id"])
     self._verify_attrs(self._quota_attrs, response['quotas'][0])
示例#19
0
 def test_get_one(self):
     quota = obj_utils.create_test_quota(self.context)
     response = self.get_json('/quotas/%s/%s' % (quota['project_id'],
                                                 quota['resource']))
     self.assertEqual(quota.project_id, response['project_id'])
     self.assertEqual(quota.resource, response['resource'])
示例#20
0
 def test_one(self, mock_policy):
     mock_policy.return_value = True
     quota = obj_utils.create_test_quota(self.context)
     response = self.get_json('/quotas')
     self.assertEqual(quota.project_id, response['quotas'][0]["project_id"])
     self._verify_attrs(self._quota_attrs, response['quotas'][0])
示例#21
0
 def test_one(self):
     quota = obj_utils.create_test_quota(self.context)
     response = self.get_json('/quotas')
     self.assertEqual(quota.project_id, response['quotas'][0]["project_id"])
     self._verify_attrs(self._quota_attrs, response['quotas'][0])
示例#22
0
 def test_one(self, mock_policy):
     mock_policy.return_value = True
     quota = obj_utils.create_test_quota(self.context)
     response = self.get_json('/quotas')
     self.assertEqual(quota.project_id, response['quotas'][0]["project_id"])
     self._verify_attrs(self._quota_attrs, response['quotas'][0])