58 lines
2.3 KiB
Python
58 lines
2.3 KiB
Python
#
|
|
# Copyright 2017 Intel
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
from six.moves import http_client
|
|
|
|
from mogan.tests.functional.api import v1 as v1_test
|
|
from mogan.tests.unit.db import utils
|
|
|
|
|
|
class TestFlavorAuthorization(v1_test.APITestV1):
|
|
|
|
def setUp(self):
|
|
super(TestFlavorAuthorization, self).setUp()
|
|
self.flavor = utils.create_test_flavor(name="test_flavor")
|
|
|
|
def test_flavor_get_one_by_no_admin(self):
|
|
# role is not admin, he can't get schedule info
|
|
headers = self.gen_headers(self.context, roles="no-admin")
|
|
resp = self.get_json('/flavors/%s' % self.flavor.uuid,
|
|
headers=headers)
|
|
self.assertIn('name', resp)
|
|
self.assertIn('uuid', resp)
|
|
self.assertIn('is_public', resp)
|
|
self.assertIn('description', resp)
|
|
self.assertIn('links', resp)
|
|
self.assertNotIn('resources', resp)
|
|
|
|
def test_flavor_get_one_by_admin(self):
|
|
# role is admin, he can get everything.
|
|
headers = self.gen_headers(self.context, roles="admin")
|
|
resp = self.get_json('/flavors/%s' % self.flavor.uuid,
|
|
headers=headers)
|
|
self.assertIn('name', resp)
|
|
self.assertIn('uuid', resp)
|
|
self.assertIn('is_public', resp)
|
|
self.assertIn('description', resp)
|
|
self.assertIn('links', resp)
|
|
self.assertIn('resources', resp)
|
|
|
|
def test_flavor_get_one_that_does_not_exist(self):
|
|
headers = self.gen_headers(self.context, roles="admin")
|
|
invalid_id = '00000000-0000-0000-0000-000000000000'
|
|
resp = self.get_json('/flavors/%s' % invalid_id, expect_errors=True,
|
|
headers=headers)
|
|
self.assertEqual(http_client.NOT_FOUND, resp.status_int)
|
|
self.assertTrue(resp.json['error_message'])
|