From 3e47cbea340c067cefd2ab1e029dc1fca4f5e954 Mon Sep 17 00:00:00 2001 From: Lance Bragstad Date: Mon, 16 Jul 2018 16:18:03 +0000 Subject: [PATCH] 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 --- glance/tests/unit/async/flows/test_import.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/glance/tests/unit/async/flows/test_import.py b/glance/tests/unit/async/flows/test_import.py index bbc708d22a..70752d8e95 100644 --- a/glance/tests/unit/async/flows/test_import.py +++ b/glance/tests/unit/async/flows/test_import.py @@ -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()