Merge "Refactor internal context testcases with ddt"
This commit is contained in:
commit
120980bb16
@ -13,12 +13,14 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import ddt
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from cinder import context
|
from cinder import context
|
||||||
from cinder import test
|
from cinder import test
|
||||||
|
|
||||||
|
|
||||||
|
@ddt.ddt
|
||||||
class ContextTestCase(test.TestCase):
|
class ContextTestCase(test.TestCase):
|
||||||
|
|
||||||
def test_request_context_sets_is_admin(self):
|
def test_request_context_sets_is_admin(self):
|
||||||
@ -98,43 +100,23 @@ class ContextTestCase(test.TestCase):
|
|||||||
self.assertEqual('user tenant domain user-domain project-domain',
|
self.assertEqual('user tenant domain user-domain project-domain',
|
||||||
ctx.to_dict()["user_identity"])
|
ctx.to_dict()["user_identity"])
|
||||||
|
|
||||||
|
@ddt.data(('ec729e9946bc43c39ece6dfa7de70eea',
|
||||||
|
'c466a48309794261b64a4f02cfcc3d64'),
|
||||||
|
('ec729e9946bc43c39ece6dfa7de70eea', None),
|
||||||
|
(None, 'c466a48309794261b64a4f02cfcc3d64'),
|
||||||
|
(None, None))
|
||||||
|
@ddt.unpack
|
||||||
@mock.patch('cinder.context.CONF')
|
@mock.patch('cinder.context.CONF')
|
||||||
def test_cinder_internal_context(self, mock_conf):
|
def test_cinder_internal_context(self, project_id, user_id, mock_conf):
|
||||||
project_id = 'ec729e9946bc43c39ece6dfa7de70eea'
|
|
||||||
user_id = 'c466a48309794261b64a4f02cfcc3d64'
|
|
||||||
mock_conf.cinder_internal_tenant_project_id = project_id
|
mock_conf.cinder_internal_tenant_project_id = project_id
|
||||||
mock_conf.cinder_internal_tenant_user_id = user_id
|
mock_conf.cinder_internal_tenant_user_id = user_id
|
||||||
ctx = context.get_internal_tenant_context()
|
ctx = context.get_internal_tenant_context()
|
||||||
|
if project_id is None or user_id is None:
|
||||||
|
self.assertIsNone(ctx)
|
||||||
|
else:
|
||||||
self.assertEqual(user_id, ctx.user_id)
|
self.assertEqual(user_id, ctx.user_id)
|
||||||
self.assertEqual(project_id, ctx.project_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)
|
|
||||||
|
|
||||||
def test_request_context_no_roles(self):
|
def test_request_context_no_roles(self):
|
||||||
ctxt = context.RequestContext('111',
|
ctxt = context.RequestContext('111',
|
||||||
'222')
|
'222')
|
||||||
|
Loading…
Reference in New Issue
Block a user