def setUp(self): super(BaseTestCase, self).setUp() # suppress all but errors here capture_logs = bool_from_env('OS_LOG_CAPTURE') self.useFixture( fixtures.FakeLogger( name='neutron.api.extensions', format=LOG_FORMAT, level=std_logging.ERROR, nuke_handlers=capture_logs, )) self.useFixture(lockutils.ExternalLockFixture()) cfg.CONF.set_override('state_path', self.get_default_temp_dir().path) self.addCleanup(CONF.reset) self.useFixture(ProcessMonitorFixture()) self.useFixture(fixtures.MonkeyPatch( 'neutron.common.exceptions.NeutronException.use_fatal_exceptions', fake_use_fatal_exceptions)) self.useFixture(fixtures.MonkeyPatch( 'oslo_config.cfg.find_config_files', lambda project=None, prog=None, extension=None: [])) self.setup_rpc_mocks() self.setup_config() self.setup_test_registry_instance() policy.init() self.addCleanup(policy.reset) self.addCleanup(rpc_consumer_reg.clear)
def test_init_reset_refresh(self): self.assertIsNone(policy._ENFORCER) policy.init() self.assertIsNotNone(policy._ENFORCER) policy.reset() self.assertIsNone(policy._ENFORCER) policy.refresh() self.assertIsNotNone(policy._ENFORCER)
def test_check_is_advsvc_no_roles_no_advsvc(self): policy.init(policy_file='no_policy.json') ctx = _context.Context('me', 'my_project', roles=['advsvc']) # No advsvc role in the policy file, so cannot assume the role. self.assertFalse(policy.check_is_advsvc(ctx))
def test_check_is_admin_no_roles_no_admin(self): policy.init(policy_file='no_policy.json') ctx = _context.Context('me', 'my_project', roles=['user']).elevated() # With no admin role, elevated() should not work. self.assertFalse(policy.check_is_admin(ctx))