Beispiel #1
0
    def setUp(self):
        super(TestCase, self).setUp()
        token_info = {
            'token': {
                'project': {
                    'id': 'fake_project'
                },
                'user': {
                    'id': 'fake_user'
                }
            }
        }
        self.context = magnum_context.RequestContext(
            auth_token_info=token_info,
            project_id='fake_project',
            user_id='fake_user')

        self.policy = self.useFixture(policy_fixture.PolicyFixture())

        self.useFixture(
            fixtures.MockPatchObject(oslo_messaging, 'Notifier',
                                     fake_notifier.FakeNotifier))
        self.addCleanup(fake_notifier.reset)

        def make_context(*args, **kwargs):
            # If context hasn't been constructed with token_info
            if not kwargs.get('auth_token_info'):
                kwargs['auth_token_info'] = copy.deepcopy(token_info)
            if not kwargs.get('project_id'):
                kwargs['project_id'] = 'fake_project'
            if not kwargs.get('user_id'):
                kwargs['user_id'] = 'fake_user'

            context = magnum_context.RequestContext(*args, **kwargs)
            return magnum_context.RequestContext.from_dict(context.to_dict())

        p = mock.patch.object(magnum_context,
                              'make_context',
                              side_effect=make_context)
        self.mock_make_context = p.start()
        self.addCleanup(p.stop)

        self.useFixture(conf_fixture.ConfFixture())
        self.useFixture(fixtures.NestedTempfile())

        self._base_test_obj_backup = copy.copy(
            objects_base.MagnumObjectRegistry._registry._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        def reset_pecan():
            pecan.set_config({}, overwrite=True)

        self.addCleanup(reset_pecan)
Beispiel #2
0
    def setUp(self):
        super(TestCase, self).setUp()
        token_info = {
            'token': {
                'project': {
                    'id': 'fake_project'
                },
                'user': {
                    'id': 'fake_user'
                }
            }
        }

        trustee_domain_id = '12345678-9012-3456-7890-123456789abc'

        self.context = magnum_context.RequestContext(
            auth_token_info=token_info,
            project_id='fake_project',
            user_id='fake_user',
            is_admin=False)

        self.global_mocks = {}

        self.keystone_client = magnum_keystone.KeystoneClientV3(self.context)

        self.policy = self.useFixture(policy_fixture.PolicyFixture())

        self.output = self.useFixture(output_fixture.OutputStreamCapture())

        self.useFixture(fixtures.MockPatchObject(
            oslo_messaging, 'Notifier',
            fake_notifier.FakeNotifier))
        self.addCleanup(fake_notifier.reset)

        def make_context(*args, **kwargs):
            # If context hasn't been constructed with token_info
            if not kwargs.get('auth_token_info'):
                kwargs['auth_token_info'] = copy.deepcopy(token_info)
            if not kwargs.get('project_id'):
                kwargs['project_id'] = 'fake_project'
            if not kwargs.get('user_id'):
                kwargs['user_id'] = 'fake_user'
            if not kwargs.get('is_admin'):
                kwargs['is_admin'] = False

            context = magnum_context.RequestContext(*args, **kwargs)
            return magnum_context.RequestContext.from_dict(context.to_dict())

        p = mock.patch.object(magnum_context, 'make_context',
                              side_effect=make_context)

        self.global_mocks['magnum.common.context.make_context'] = p

        q = mock.patch.object(magnum_keystone.KeystoneClientV3,
                              'trustee_domain_id',
                              return_value=trustee_domain_id)

        self.global_mocks[
            'magnum.common.keystone.KeystoneClientV3.trustee_domain_id'] = q

        self.mock_make_context = p.start()
        self.addCleanup(p.stop)

        self.mock_make_trustee_domain_id = q.start()
        self.addCleanup(q.stop)

        self.useFixture(conf_fixture.ConfFixture())
        self.useFixture(fixtures.NestedTempfile())

        self._base_test_obj_backup = copy.copy(
            objects_base.MagnumObjectRegistry._registry._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        def reset_pecan():
            pecan.set_config({}, overwrite=True)

        self.addCleanup(reset_pecan)