本文整理汇总了Python中superdesk.errors.ProviderError.ruleError方法的典型用法代码示例。如果您正苦于以下问题:Python ProviderError.ruleError方法的具体用法?Python ProviderError.ruleError怎么用?Python ProviderError.ruleError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类superdesk.errors.ProviderError
的用法示例。
在下文中一共展示了ProviderError.ruleError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply_rule_set
# 需要导入模块: from superdesk.errors import ProviderError [as 别名]
# 或者: from superdesk.errors.ProviderError import ruleError [as 别名]
def apply_rule_set(item, provider, rule_set=None):
"""Applies rules set on the item to be ingested into the system.
If there's no rule set then the item will
be returned without any change.
:param item: Item to be ingested
:param provider: provider object from whom the item was received
:return: item
"""
try:
if rule_set is None and provider.get('rule_set') is not None:
rule_set = superdesk.get_resource_service('rule_sets').find_one(_id=provider['rule_set'], req=None)
if rule_set and 'body_html' in item:
body = item['body_html']
for rule in rule_set['rules']:
body = body.replace(rule['old'], rule['new'])
item['body_html'] = body
return item
except Exception as ex:
raise ProviderError.ruleError(ex, provider)
示例2: test_raise_ruleError
# 需要导入模块: from superdesk.errors import ProviderError [as 别名]
# 或者: from superdesk.errors.ProviderError import ruleError [as 别名]
def test_raise_ruleError(self):
with assert_raises(ProviderError) as error_context:
try:
ex = Exception("Testing ruleError")
raise ex
except Exception:
raise ProviderError.ruleError(ex, self.provider)
exception = error_context.exception
self.assertTrue(exception.code == 2003)
self.assertTrue(exception.message == "Rule could not be applied")
self.assertIsNotNone(exception.system_exception)
self.assertEqual(exception.system_exception.args[0], "Testing ruleError")
self.assertEqual(len(self.mock_logger_handler.messages['error']), 1)
self.assertEqual(self.mock_logger_handler.messages['error'][0],
"ProviderError Error 2003 - Rule could not be applied: "
"Testing ruleError on channel TestProvider")