Refactor internal context testcases with ddt
Use ddt to wrap internal context testcases. Change-Id: I44ad096065d40d31929ee6aad4ca12ddaf6fe80d
This commit is contained in:
parent
9da1945871
commit
b6fd13d217
@ -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,43 +100,23 @@ 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()
|
||||
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)
|
||||
|
||||
@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):
|
||||
ctxt = context.RequestContext('111',
|
||||
'222')
|
||||
|
Loading…
Reference in New Issue
Block a user