def setup_context(self, username="******", tenant_id="tenant_1", token="test_auth_token", tenant_name='test_tenant', **kwargs): self.addCleanup(context.set_ctx, context.ctx() if context.has_ctx() else None) context.set_ctx(context.Context( username=username, tenant_id=tenant_id, token=token, service_catalog={}, tenant_name=tenant_name, **kwargs))
def setup_context(self, username="******", tenant_id="tenant_1", auth_token="test_auth_token", tenant_name='test_tenant', service_catalog=None, **kwargs): self.addCleanup(context.set_ctx, context.ctx() if context.has_ctx() else None) context.set_ctx(context.Context( username=username, tenant_id=tenant_id, auth_token=auth_token, service_catalog=service_catalog or {}, tenant_name=tenant_name, **kwargs))
def test_context_cleared_in_case_of_exception(self): with mock_validate_config() as validate_config: validate_config.side_effect = SomeException self.assertRaises(SomeException, main.validate_castellan_config) self.assertFalse(context.has_ctx())
def test_context_cleared(self): with mock_validate_config(): main.validate_castellan_config() self.assertFalse(context.has_ctx())
def check_context(): self.assertTrue(context.has_ctx())
def has_ctx(**kwargs): return context.has_ctx()