def test_store_current_resets_correctly(self): # By default a new context is stored. ctx = context.RequestContext() # the use of the fixture should put us in a reset state, not # doing so is a bug because when this fixture is consumed by # other test suites there is no guaruntee that all tests use # this fixture. self.useFixture(fixture.ClearRequestContext()) self.assertIsNone(context.get_current()) ctx = context.RequestContext() self.assertIs(context.get_current(), ctx) fixture.ClearRequestContext()._remove_cached_context() self.assertIsNone(context.get_current())
def setUp(self): super(NotificationsTestCase, self).setUp() self.fixture = self.useFixture(o_fixture.ClearRequestContext()) self.net_info = fake_network.fake_get_instance_nw_info(self, 1, 1) def fake_get_nw_info(cls, ctxt, instance): self.assertTrue(ctxt.is_admin) return self.net_info self.stub_out('nova.network.api.API.get_instance_nw_info', fake_get_nw_info) fake_network.set_stub_network_methods(self) fake_notifier.stub_notifier(self.stubs) self.addCleanup(fake_notifier.reset) self.flags(network_manager='nova.network.manager.FlatManager', notify_on_state_change="vm_and_task_state", host='testhost') self.flags(api_servers=['http://localhost:9292'], group='glance') self.user_id = 'fake' self.project_id = 'fake' self.context = context.RequestContext(self.user_id, self.project_id) self.instance = self._wrapped_create() self.decorated_function_called = False
def setUp(self): super(NotificationsTestCase, self).setUp() self.fixture = self.useFixture(o_fixture.ClearRequestContext()) self.net_info = fake_network.fake_get_instance_nw_info(self.stubs, 1, 1) def fake_get_nw_info(cls, ctxt, instance): self.assertTrue(ctxt.is_admin) return self.net_info self.stubs.Set(network_api.API, 'get_instance_nw_info', fake_get_nw_info) fake_network.set_stub_network_methods(self.stubs) fake_notifier.stub_notifier(self.stubs) self.addCleanup(fake_notifier.reset) self.flags(compute_driver='nova.virt.fake.FakeDriver', network_manager='nova.network.manager.FlatManager', notify_on_state_change="vm_and_task_state", host='testhost') self.user_id = 'fake' self.project_id = 'fake' self.context = context.RequestContext(self.user_id, self.project_id) self.instance = self._wrapped_create() self.decorated_function_called = False
def setUp(self): super(TestThreadLocalContext, self).setUp() self.useFixture(context_fixture.ClearRequestContext()) # This will set the thread local copy of the context self.context = context.RequestContext('user', 'project') # Start the compute service to initialize compute RPC self.start_service('compute')
def setUp(self): super(BaseTestCase, self).setUp() self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) self.useFixture(log_fixture.get_logging_handle_error_fixture()) self.useFixture(ConfigFixture(CONF)) self.useFixture(oc_fixture.ClearRequestContext()) self.useFixture(PolicyFixture())
def setUp(self): super(BaseTestCase, self).setUp() self.context_fixture = self.useFixture( fixture_context.ClearRequestContext()) self.config_fixture = self.useFixture( fixture_config.Config(cfg.ConfigOpts())) self.config = self.config_fixture.config self.CONF = self.config_fixture.conf log.register_options(self.CONF)
def setUp(self): super(BaseTestCase, self).setUp() self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) self.useFixture( fixtures.MockPatchObject(sys, 'exit', side_effect=UnexpectedExit)) self.useFixture(log_fixture.get_logging_handle_error_fixture()) warnings.filterwarnings('error', category=DeprecationWarning, module='^keystone\\.') warnings.filterwarnings( 'ignore', category=DeprecationWarning, message=r"Using function/method 'db_version\(\)' is deprecated") warnings.simplefilter('error', exc.SAWarning) if hasattr(exc, "RemovedIn20Warning"): warnings.simplefilter('ignore', exc.RemovedIn20Warning) self.addCleanup(warnings.resetwarnings) # Ensure we have an empty threadlocal context at the start of each # test. self.assertIsNone(oslo_context.get_current()) self.useFixture(oslo_ctx_fixture.ClearRequestContext()) orig_debug_level = ldap.get_option(ldap.OPT_DEBUG_LEVEL) self.addCleanup(ldap.set_option, ldap.OPT_DEBUG_LEVEL, orig_debug_level) orig_tls_cacertfile = ldap.get_option(ldap.OPT_X_TLS_CACERTFILE) if orig_tls_cacertfile is None: orig_tls_cacertfile = '' self.addCleanup(ldap.set_option, ldap.OPT_X_TLS_CACERTFILE, orig_tls_cacertfile) orig_tls_cacertdir = ldap.get_option(ldap.OPT_X_TLS_CACERTDIR) # Setting orig_tls_cacertdir to None is not allowed. if orig_tls_cacertdir is None: orig_tls_cacertdir = '' self.addCleanup(ldap.set_option, ldap.OPT_X_TLS_CACERTDIR, orig_tls_cacertdir) orig_tls_require_cert = ldap.get_option(ldap.OPT_X_TLS_REQUIRE_CERT) self.addCleanup(ldap.set_option, ldap.OPT_X_TLS_REQUIRE_CERT, orig_tls_require_cert) self.addCleanup(ks_ldap.PooledLDAPHandler.connection_pools.clear)
def setUp(self): super(BaseTestCase, self).setUp() self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) self.useFixture(mockpatch.PatchObject(sys, 'exit', side_effect=UnexpectedExit)) self.useFixture(log_fixture.get_logging_handle_error_fixture()) warnings.filterwarnings('error', category=DeprecationWarning, module='^keystone\\.') warnings.simplefilter('error', exc.SAWarning) self.addCleanup(warnings.resetwarnings) # Ensure we have an empty threadlocal context at the start of each # test. self.assertIsNone(oslo_context.get_current()) self.useFixture(oslo_ctx_fixture.ClearRequestContext())
def setUp(self): super(TestContextHook, self).setUp() self.useFixture(fixture.ClearRequestContext()) self.state = mock.Mock() self.state.controller.__self__ = mock.MagicMock(autospec=True) self.state.request = mock.Mock() self.state.request.headers = {} self.state.response.headers = {} self.state.request.environ = {} self.state.request.host_url = 'https://cdn.com' self.state.request.path = '/v1.0/endpoint' oslo_config_patcher = mock.patch('oslo_config.cfg.CONF') self.mock_cfg = oslo_config_patcher.start() self.mock_cfg.project_id_in_url = False self.addCleanup(oslo_config_patcher.stop) self.hook = hooks.context.ContextHook()
def setUp(self): super(NotificationsTestCase, self).setUp() self.fixture = self.useFixture(o_fixture.ClearRequestContext()) self.net_info = fake_network.fake_get_instance_nw_info(self) self.notifier = self.useFixture(fixtures.NotificationFixture(self)) self.flags(host='testhost') self.flags(notify_on_state_change="vm_and_task_state", group='notifications') self.flags(api_servers=['http://localhost:9292'], group='glance') self.user_id = 'fake' self.project_id = 'fake' self.context = context.RequestContext(self.user_id, self.project_id) self.fake_time = datetime.datetime(2017, 2, 2, 16, 45, 0) timeutils.set_time_override(self.fake_time) self.instance = self._wrapped_create() self.decorated_function_called = False
def setUp(self): super(SpawnNTestCase, self).setUp() self.useFixture(context_fixture.ClearRequestContext()) self.spawn_name = 'spawn_n'
def setUp(self): super(BaseTestCase, self).setUp() self.useFixture(ConfigFixture()) self.useFixture(DisableStatsdFixture()) self.useFixture(oo_ctx.ClearRequestContext()) self.useFixture(PolicyFixture())
def setUp(self): super(BaseTestCase, self).setUp() self.useFixture(ConfigFixture()) self.useFixture(oo_ctx.ClearRequestContext())
def setUp(self): super(ContextTest, self).setUp() self.warnings = self.useFixture(WarningsFixture()) self.useFixture(fixture.ClearRequestContext())
def mock_context(test): return test.useFixture(oo_ctx.ClearRequestContext())
def test_store_current(self): # By default a new context is stored. ctx = context.RequestContext() self.assertIs(context.get_current(), ctx) fixture.ClearRequestContext()._remove_cached_context() self.assertIsNone(context.get_current())
def setUp(self): super(ContextTestCase, self).setUp() self.useFixture(o_fixture.ClearRequestContext())
def setUp(self): super(TestRequestLimit, self).setUp() self.useFixture(oo_cfg.Config()) self.useFixture(oo_ctx.ClearRequestContext())