Use glance.context.RequestContext in tests
There were some recent changes to oslo.policy that include specific type checks of the ``creds`` parameter passed to the ``enforce()`` method: https://review.openstack.org/#/c/578995/ The above change allows consuming projects to pass instances of oslo_context.context.RequestContext to the policy enforcer, as opposed to building a dictionary instance from scratch multiple different ways across projects. The glance unit tests were failing with the new version of oslo.policy (1.38.0) because they were passing in a Mock instance which failed the new, more strict, type check. This commit converts the setUp class of the tests to use an instance of glance.context.RequestContext, which subclasses RequestContext from oslo.context. It also sets the user_id and project_id attributes of the context object to override authorization checks. This should allow glance to pass with newer versions of oslo.policy. Change-Id: I0a69bc9565d57fd6ad8484abc5fce0e8dd45f9f2 Closes-Bug: 1781976
This commit is contained in:
parent
f3496591ae
commit
3e47cbea34
|
@ -31,6 +31,7 @@ from glance.async import utils as async_utils
|
|||
from glance.common.scripts.image_import import main as image_import
|
||||
from glance.common.scripts import utils as script_utils
|
||||
from glance.common import utils
|
||||
from glance import context
|
||||
from glance import domain
|
||||
from glance import gateway
|
||||
import glance.tests.utils as test_utils
|
||||
|
@ -63,7 +64,9 @@ class TestImportTask(test_utils.BaseTestCase):
|
|||
utils.safe_mkdirs(self.work_dir)
|
||||
self.config(work_dir=self.work_dir, group='task')
|
||||
|
||||
self.context = mock.MagicMock()
|
||||
self.context = context.RequestContext(
|
||||
user_id=TENANT1, project_id=TENANT1, overwrite=False
|
||||
)
|
||||
self.img_repo = mock.MagicMock()
|
||||
self.task_repo = mock.MagicMock()
|
||||
|
||||
|
|
Loading…
Reference in New Issue