本文整理汇总了Python中wafflehaus.try_context.context_filter.filter_factory函数的典型用法代码示例。如果您正苦于以下问题:Python filter_factory函数的具体用法?Python filter_factory怎么用?Python filter_factory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了filter_factory函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_strategy_unknown_should_500_noop_testing
def test_create_strategy_unknown_should_500_noop_testing(self):
"""The none strategy simply is a noop."""
result = context_filter.filter_factory(self.unknown_testing)(self.app)
self.assertIsNotNone(result)
self.assertTrue(isinstance(result, context_filter.ContextFilter))
resp = result.__call__.request('/something', method='HEAD')
self.assertEqual(self.app, resp)
示例2: test_requires_auth_will_fail_without_info
def test_requires_auth_will_fail_without_info(self):
result = context_filter.filter_factory(self.strat_neutron_a)(self.app)
self.assertIsNotNone(result)
headers = {'Content-Type': 'application/json',
'X_ROLES': 'testrole, testrole2', }
resp = result.__call__.request('/', method='HEAD', headers=headers)
self.assertTrue(isinstance(resp, webob.exc.HTTPForbidden))
示例3: test_create_strategy_neutron_no_user
def test_create_strategy_neutron_no_user(self):
result = context_filter.filter_factory(self.strat_neutron)(self.app)
self.assertIsNotNone(result)
self.assertTrue(isinstance(result, context_filter.ContextFilter))
self.assertFalse('neutron.context' in self.req)
headers = {'Content-Type': 'application/json', }
resp = result.__call__.request('/', method='HEAD', headers=headers)
self.assertEqual(self.app, resp)
示例4: test_create_strategy_neutron
def test_create_strategy_neutron(self):
result = context_filter.filter_factory(self.strat_neutron)(self.app)
self.assertIsNotNone(result)
self.assertTrue(isinstance(result, context_filter.ContextFilter))
headers = {'Content-Type': 'application/json',
'X_USER_ID': 'derp', }
result.__call__.request('/', method='HEAD', headers=headers)
context = result.strat_instance.context
self.assertTrue(context.is_admin)
示例5: test_advsvc_is_false_when_admin_and_not_advsvc_role
def test_advsvc_is_false_when_admin_and_not_advsvc_role(self):
result = context_filter.filter_factory(self.strat_neutron)(self.app)
self.assertIsNotNone(result)
self.assertTrue(isinstance(result, context_filter.ContextFilter))
headers = {'Content-Type': 'application/json'}
resp = result.__call__.request('/', method='HEAD', headers=headers)
self.assertEqual(self.app, resp)
context = result.strat_instance.context
self.assertFalse(context.is_advsvc)
示例6: test_create_strategy_test_noop_testing
def test_create_strategy_test_noop_testing(self):
"""This is a test strategy to see if this thing works."""
result = context_filter.filter_factory(self.strat_test)(self.app)
self.assertTrue(isinstance(result, context_filter.ContextFilter))
resp = result.__call__.request('/something', method='HEAD')
self.assertEqual(self.app, resp)
self.assertEqual(1, self.context_init.call_count)
self.assertTrue(isinstance(result, context_filter.ContextFilter))
"""Should be 1 because of a new instance."""
self.assertEqual(1, self.context_init.call_count)
示例7: test_advsvc_is_true_when_policy_says_it_is
def test_advsvc_is_true_when_policy_says_it_is(self):
self.adv_svc.return_value = True
result = context_filter.filter_factory(self.strat_neutron)(self.app)
self.assertIsNotNone(result)
self.assertTrue(isinstance(result, context_filter.ContextFilter))
headers = {'Content-Type': 'application/json'}
resp = result.__call__.request('/', method='HEAD', headers=headers)
self.assertEqual(self.app, resp)
context = result.strat_instance.context
self.assertTrue(context.is_advsvc)
示例8: test_create_strategy_neutron_with_no_roles
def test_create_strategy_neutron_with_no_roles(self):
result = context_filter.filter_factory(self.strat_neutron)(self.app)
self.assertIsNotNone(result)
self.assertTrue(isinstance(result, context_filter.ContextFilter))
self.assertFalse('neutron.context' in self.req)
headers = {'Content-Type': 'application/json',
'X_ROLES': None, }
with patch('neutron.policy.get_admin_roles',
self.get_admin_mock):
resp = result.__call__.request('/', method='HEAD', headers=headers)
self.assertEqual(self.app, resp)
示例9: test_create_strategy_neutron_with_empty_roles
def test_create_strategy_neutron_with_empty_roles(self):
result = context_filter.filter_factory(self.strat_neutron)(self.app)
self.assertIsNotNone(result)
self.assertTrue(isinstance(result, context_filter.ContextFilter))
headers = {'Content-Type': 'application/json',
'X_ROLES': '', }
resp = result.__call__.request('/', method='HEAD', headers=headers)
self.assertEqual(self.app, resp)
context = result.strat_instance.context
self.assertTrue(context.is_admin)
self.assertTrue(hasattr(context, 'roles'))
示例10: test_override_runtime_enabled
def test_override_runtime_enabled(self):
"""The none strategy simply is a noop."""
self.set_reconfigure()
headers = {'X_WAFFLEHAUS_CONTEXTFILTER_ENABLED': False}
result = context_filter.filter_factory(self.strat_test)(self.app)
self.assertTrue(isinstance(result, context_filter.ContextFilter))
resp = result.__call__.request('/something', method='HEAD',
headers=headers)
self.assertEqual(self.app, resp)
self.assertEqual(0, self.context_init.call_count)
self.assertTrue(isinstance(result, context_filter.ContextFilter))
"""Should be 1 because of a new instance."""
self.assertEqual(0, self.context_init.call_count)
示例11: test_verify_non_duplicate_request_id_admin
def test_verify_non_duplicate_request_id_admin(self):
result = context_filter.filter_factory(self.strat_neutron)(self.app)
self.assertIsNotNone(result)
self.assertTrue(isinstance(result, context_filter.ContextFilter))
headers = {'Content-Type': 'application/json', }
resp = result.__call__.request('/', method='HEAD', headers=headers)
context = result.strat_instance.context
self.assertTrue(context.is_admin)
self.assertEqual(self.app, resp)
# Generate another call in order to force oslo.context to refresh
# the _request_store, which in turn generates a new request_id
resp = result.__call__.request('/', method='HEAD', headers=headers)
context1 = result.strat_instance.context
self.assertNotEqual(context.request_id, context1.request_id)
示例12: test_create_strategy_neutron_appends_to_admin_role
def test_create_strategy_neutron_appends_to_admin_role(self):
result = context_filter.filter_factory(self.strat_neutron)(self.app)
self.assertIsNotNone(result)
self.assertFalse('neutron.context' in self.req)
headers = {'Content-Type': 'application/json',
'X_ROLES': 'testrole, testrole2', }
with patch('neutron.policy.get_admin_roles',
self.get_admin_mock):
resp = result.__call__.request('/', method='HEAD', headers=headers)
self.assertEqual(self.app, resp)
context = result.strat_instance.context
self.assertTrue(hasattr(context, 'roles'))
self.assertTrue('testrole' in context.roles)
self.assertTrue('testrole2' in context.roles)
self.assertTrue('admin' in context.roles)
self.assertEqual(3, len(context.roles))
示例13: test_requires_auth_is_not_admin
def test_requires_auth_is_not_admin(self):
result = context_filter.filter_factory(self.strat_neutron_a)(self.app)
self.assertIsNotNone(result)
headers = {'Content-Type': 'application/json',
'X_TENANT_ID': '123456',
'X_USER_ID': 'foo',
'X_ROLES': 'testrole, testrole2', }
policy_check = self.create_patch('neutron.policy.check_is_admin')
policy_check.return_value = False
resp = result.__call__.request('/', method='HEAD', headers=headers)
self.assertEqual(self.app, resp)
self.assertEqual(2, policy_check.call_count)
context = result.strat_instance.context
self.assertTrue(hasattr(context, 'roles'))
self.assertTrue('testrole' in context.roles)
self.assertTrue('testrole2' in context.roles)
self.assertFalse(context.is_admin)
self.assertEqual(2, len(context.roles))
示例14: test_verify_non_duplicate_request_id_non_admin
def test_verify_non_duplicate_request_id_non_admin(self):
result = context_filter.filter_factory(self.strat_neutron_a)(self.app)
self.assertIsNotNone(result)
headers = {'Content-Type': 'application/json',
'X_TENANT_ID': '123456',
'X_USER_ID': 'foo',
'X_ROLES': 'testrole, testrole2', }
policy_check = self.create_patch('neutron.policy.check_is_admin')
policy_check.return_value = False
resp = result.__call__.request('/', method='HEAD', headers=headers)
self.assertEqual(self.app, resp)
self.assertEqual(2, policy_check.call_count)
context = result.strat_instance.context
self.assertTrue(hasattr(context, 'roles'))
self.assertTrue('testrole' in context.roles)
self.assertTrue('testrole2' in context.roles)
self.assertFalse(context.is_admin)
self.assertEqual(2, len(context.roles))
# Generate another call in order to force oslo.context to refresh
# the _request_store, which in turn generates a new request_id
resp = result.__call__.request('/', method='HEAD', headers=headers)
context1 = result.strat_instance.context
self.assertNotEqual(context.request_id, context1.request_id)