Merge "Refactor internal context testcases with ddt"

This commit is contained in:
Jenkins 2017-05-12 14:35:43 +00:00 committed by Gerrit Code Review
commit 120980bb16

View File

@ -13,12 +13,14 @@
# License for the specific language governing permissions and limitations
# under the License.
import ddt
import mock
from cinder import context
from cinder import test
@ddt.ddt
class ContextTestCase(test.TestCase):
def test_request_context_sets_is_admin(self):
@ -98,42 +100,22 @@ class ContextTestCase(test.TestCase):
self.assertEqual('user tenant domain user-domain project-domain',
ctx.to_dict()["user_identity"])
@ddt.data(('ec729e9946bc43c39ece6dfa7de70eea',
'c466a48309794261b64a4f02cfcc3d64'),
('ec729e9946bc43c39ece6dfa7de70eea', None),
(None, 'c466a48309794261b64a4f02cfcc3d64'),
(None, None))
@ddt.unpack
@mock.patch('cinder.context.CONF')
def test_cinder_internal_context(self, mock_conf):
project_id = 'ec729e9946bc43c39ece6dfa7de70eea'
user_id = 'c466a48309794261b64a4f02cfcc3d64'
def test_cinder_internal_context(self, project_id, user_id, mock_conf):
mock_conf.cinder_internal_tenant_project_id = project_id
mock_conf.cinder_internal_tenant_user_id = user_id
ctx = context.get_internal_tenant_context()
self.assertEqual(user_id, ctx.user_id)
self.assertEqual(project_id, ctx.project_id)
@mock.patch('cinder.context.CONF')
def test_cinder_internal_context_missing_user(self, mock_conf):
project_id = 'ec729e9946bc43c39ece6dfa7de70eea'
user_id = None
mock_conf.cinder_internal_tenant_project_id = project_id
mock_conf.cinder_internal_tenant_user_id = user_id
ctx = context.get_internal_tenant_context()
self.assertIsNone(ctx)
@mock.patch('cinder.context.CONF')
def test_cinder_internal_context_missing_project(self, mock_conf):
project_id = None
user_id = 'c466a48309794261b64a4f02cfcc3d64'
mock_conf.cinder_internal_tenant_project_id = project_id
mock_conf.cinder_internal_tenant_user_id = user_id
ctx = context.get_internal_tenant_context()
self.assertIsNone(ctx)
@mock.patch('cinder.context.CONF')
def test_cinder_internal_context_missing_all(self, mock_conf):
project_id = None
user_id = None
mock_conf.cinder_internal_tenant_project_id = project_id
mock_conf.cinder_internal_tenant_user_id = user_id
ctx = context.get_internal_tenant_context()
self.assertIsNone(ctx)
if project_id is None or user_id is None:
self.assertIsNone(ctx)
else:
self.assertEqual(user_id, ctx.user_id)
self.assertEqual(project_id, ctx.project_id)
def test_request_context_no_roles(self):
ctxt = context.RequestContext('111',