本文整理汇总了Python中superdesk.errors.ProviderError.providerAddError方法的典型用法代码示例。如果您正苦于以下问题:Python ProviderError.providerAddError方法的具体用法?Python ProviderError.providerAddError怎么用?Python ProviderError.providerAddError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类superdesk.errors.ProviderError
的用法示例。
在下文中一共展示了ProviderError.providerAddError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from superdesk.errors import ProviderError [as 别名]
# 或者: from superdesk.errors.ProviderError import providerAddError [as 别名]
def run(self, provider=None):
if provider:
try:
data = {}
data = superdesk.json.loads(provider)
data.setdefault('content_expiry', superdesk.app.config['INGEST_EXPIRY_MINUTES'])
validator = superdesk.app.validator(superdesk.app.config['DOMAIN']['ingest_providers']['schema'],
'ingest_providers')
validation = validator.validate(data)
if validation:
get_resource_service('ingest_providers').post([data])
return data
else:
ex = Exception('Failed to add Provider as the data provided is invalid. Errors: {}'
.format(str(validator.errors)))
raise ProviderError.providerAddError(exception=ex, provider=data)
except Exception as ex:
raise ProviderError.providerAddError(ex, data)
示例2: run
# 需要导入模块: from superdesk.errors import ProviderError [as 别名]
# 或者: from superdesk.errors.ProviderError import providerAddError [as 别名]
def run(self, provider=None):
if provider:
try:
data = {}
data = superdesk.json.loads(provider)
data.setdefault('name', data['type'])
data.setdefault('source', data['type'])
data.setdefault('content_expiry', INGEST_EXPIRY_MINUTES)
db = superdesk.get_db()
db['ingest_providers'].save(data)
return data
except Exception as ex:
raise ProviderError.providerAddError(ex, data)
示例3: run
# 需要导入模块: from superdesk.errors import ProviderError [as 别名]
# 或者: from superdesk.errors.ProviderError import providerAddError [as 别名]
def run(self, provider=None):
if provider:
try:
data = {}
data = superdesk.json.loads(provider)
data.setdefault('name', data['type'])
data.setdefault('source', data['type'])
data.setdefault('days_to_keep', DAYS_TO_KEEP)
db = superdesk.get_db()
db['ingest_providers'].save(data)
return data
except Exception as ex:
raise ProviderError.providerAddError(ex, data)
示例4: test_raise_providerAddError
# 需要导入模块: from superdesk.errors import ProviderError [as 别名]
# 或者: from superdesk.errors.ProviderError import providerAddError [as 别名]
def test_raise_providerAddError(self):
with assert_raises(ProviderError) as error_context:
try:
ex = Exception("Testing providerAddError")
raise ex
except Exception:
raise ProviderError.providerAddError(ex, self.provider)
exception = error_context.exception
self.assertTrue(exception.code == 2001)
self.assertTrue(exception.message == "Provider could not be saved")
self.assertIsNotNone(exception.system_exception)
self.assertEqual(exception.system_exception.args[0], "Testing providerAddError")
self.assertEqual(len(self.mock_logger_handler.messages['error']), 1)
self.assertEqual(self.mock_logger_handler.messages['error'][0],
"ProviderError Error 2001 - Provider could not be saved: "
"Testing providerAddError on channel TestProvider")