本文整理汇总了Python中instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory.enable_monitoring方法的典型用法代码示例。如果您正苦于以下问题:Python OpenEdXInstanceFactory.enable_monitoring方法的具体用法?Python OpenEdXInstanceFactory.enable_monitoring怎么用?Python OpenEdXInstanceFactory.enable_monitoring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory
的用法示例。
在下文中一共展示了OpenEdXInstanceFactory.enable_monitoring方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_enable_monitoring
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import enable_monitoring [as 别名]
def test_enable_monitoring(self, mock_newrelic):
"""
Check that the `enable_monitoring` method creates New Relic Synthetics
monitors for each of the instance's public urls, and enables email
alerts.
"""
monitor_ids = [str(uuid4()) for i in range(3)]
mock_newrelic.get_synthetics_monitors.return_value = []
mock_newrelic.create_synthetics_monitor.side_effect = monitor_ids
instance = OpenEdXInstanceFactory()
instance.enable_monitoring()
# Check that the monitors have been created
mock_newrelic.delete_synthetics_monitor.assert_not_called()
mock_newrelic.create_synthetics_monitor.assert_has_calls([
call(instance.url),
call(instance.studio_url),
call(instance.lms_preview_url),
], any_order=True)
self.assertCountEqual(
instance.new_relic_availability_monitors.values_list('pk', flat=True),
monitor_ids
)
# Check that alert emails have been set up
mock_newrelic.add_synthetics_email_alerts.assert_has_calls([
call(monitor_id, ['[email protected]'])
for monitor_id in monitor_ids
], any_order=True)
示例2: test_update_monitoring
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import enable_monitoring [as 别名]
def test_update_monitoring(self, mock_newrelic):
"""
Check that the `enable_monitoring` method only creates New Relic
Synthetics monitors for urls that are not already monitored, and
removes monitors for urls that are no longer used.
"""
instance = OpenEdXInstanceFactory()
existing_monitors = [
instance.new_relic_availability_monitors.create(pk=str(uuid4()))
for i in range(2)
]
mock_newrelic.get_synthetics_monitors.return_value = [
# This monitor is fine, keep it
{
'id': existing_monitors[0].pk,
'uri': instance.url,
},
# This monitor is for an old url, delete it
{
'id': existing_monitors[1].pk,
'uri': 'http://example.com/old-url',
},
]
new_ids = [str(uuid4()) for i in range(2)]
mock_newrelic.create_synthetics_monitor.side_effect = new_ids
instance.enable_monitoring()
# Check that the old monitor has been deleted and that new monitors
# have been created
mock_newrelic.delete_synthetics_monitor.assert_called_once_with(existing_monitors[1].pk)
mock_newrelic.create_synthetics_monitor.assert_has_calls([
call(instance.studio_url),
call(instance.lms_preview_url),
], any_order=True)
self.assertCountEqual(
instance.new_relic_availability_monitors.values_list('pk', flat=True),
[existing_monitors[0].pk] + new_ids
)