本文整理汇总了Python中hc.api.models.Check.last_ping方法的典型用法代码示例。如果您正苦于以下问题:Python Check.last_ping方法的具体用法?Python Check.last_ping怎么用?Python Check.last_ping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hc.api.models.Check
的用法示例。
在下文中一共展示了Check.last_ping方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_status_works_with_grace_period
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import last_ping [as 别名]
def test_status_works_with_grace_period(self):
check = Check()
check.status = "up"
check.last_ping = timezone.now() - timedelta(days=1, minutes=30)
self.assertTrue(check.in_grace_period())
self.assertEqual(check.get_status(), "up")
示例2: test_it_handles_grace_period
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import last_ping [as 别名]
def test_it_handles_grace_period(self):
check = Check(user=self.alice, status="up")
# 1 day 30 minutes after ping the check is in grace period:
check.last_ping = timezone.now() - timedelta(days=1, minutes=30)
check.save()
# Expect no exceptions--
handle_one(check)
示例3: test_paused_check_is_not_in_grace_period
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import last_ping [as 别名]
def test_paused_check_is_not_in_grace_period(self):
check = Check()
check.status = "up"
check.last_ping = timezone.now() - timedelta(days=1, minutes=30)
self.assertTrue(check.in_grace_period())
check.status = "paused"
self.assertFalse(check.in_grace_period())
示例4: test_it_works_synchronously
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import last_ping [as 别名]
def test_it_works_synchronously(self, mock_notify):
check = Check(user=self.alice, status="up")
check.last_ping = now() - timedelta(days=2)
check.alert_after = check.get_alert_after()
check.save()
call_command("sendalerts", loop=False, use_threads=False)
# It should call `notify` instead of `notify_on_thread`
self.assertTrue(mock_notify.called)
示例5: test_it_skips_nag_if_none_down
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import last_ping [as 别名]
def test_it_skips_nag_if_none_down(self):
check = Check(name="Test Check", user=self.alice)
check.last_ping = now()
check.save()
self.profile.nag_period = td(hours=1)
self.profile.save()
sent = self.profile.send_report(nag=True)
self.assertFalse(sent)
self.assertEqual(len(mail.outbox), 0)
示例6: test_next_ping_with_cron_syntax
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import last_ping [as 别名]
def test_next_ping_with_cron_syntax(self):
dt = timezone.make_aware(datetime(2000, 1, 1), timezone=timezone.utc)
# Expect ping every round hour
check = Check()
check.kind = "cron"
check.schedule = "0 * * * *"
check.status = "up"
check.last_ping = dt
d = check.to_dict()
self.assertEqual(d["next_ping"], "2000-01-01T01:00:00+00:00")
示例7: test_it_updates_owners_next_nag_date
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import last_ping [as 别名]
def test_it_updates_owners_next_nag_date(self):
self.profile.nag_period = timedelta(hours=1)
self.profile.save()
check = Check(user=self.alice, status="down")
check.last_ping = now() - timedelta(days=2)
check.alert_after = check.get_alert_after()
check.save()
notify(check.id, Mock())
self.profile.refresh_from_db()
self.assertIsNotNone(self.profile.next_nag_date)
示例8: test_it_sends_report
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import last_ping [as 别名]
def test_it_sends_report(self):
check = Check(name="Test Check", user=self.alice)
check.last_ping = now()
check.save()
sent = self.profile.send_report()
self.assertTrue(sent)
# And an email should have been sent
self.assertEqual(len(mail.outbox), 1)
message = mail.outbox[0]
self.assertEqual(message.subject, 'Monthly Report')
self.assertIn("Test Check", message.body)
示例9: test_it_does_not_touch_already_set_next_nag_dates
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import last_ping [as 别名]
def test_it_does_not_touch_already_set_next_nag_dates(self):
original_nag_date = now() - timedelta(minutes=30)
self.profile.nag_period = timedelta(hours=1)
self.profile.next_nag_date = original_nag_date
self.profile.save()
check = Check(user=self.alice, status="down")
check.last_ping = now() - timedelta(days=2)
check.alert_after = check.get_alert_after()
check.save()
notify(check.id, Mock())
self.profile.refresh_from_db()
self.assertEqual(self.profile.next_nag_date, original_nag_date)
示例10: test_it_notifies_when_check_goes_down
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import last_ping [as 别名]
def test_it_notifies_when_check_goes_down(self, mock_notify):
check = Check(user=self.alice, status="up")
check.last_ping = timezone.now() - timedelta(days=2)
check.alert_after = check.get_alert_after()
check.save()
result = Command().handle_one()
# If it finds work, it should return True
self.assertTrue(result)
# It should change stored status to "down"
check.refresh_from_db()
self.assertEqual(check.status, "down")
# It should call `notify`
self.assertTrue(mock_notify.called)
示例11: test_status_works_with_cron_syntax
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import last_ping [as 别名]
def test_status_works_with_cron_syntax(self):
dt = timezone.make_aware(datetime(2000, 1, 1), timezone=timezone.utc)
# Expect ping every midnight, default grace is 1 hour
check = Check()
check.kind = "cron"
check.schedule = "0 0 * * *"
check.status = "up"
check.last_ping = dt
# 00:30am
now = dt + timedelta(days=1, minutes=30)
self.assertEqual(check.get_status(now), "up")
# 1:30am
now = dt + timedelta(days=1, minutes=90)
self.assertEqual(check.get_status(now), "down")
示例12: test_it_sends_nag
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import last_ping [as 别名]
def test_it_sends_nag(self):
check = Check(name="Test Check", user=self.alice)
check.status = "down"
check.last_ping = now()
check.save()
self.profile.nag_period = td(hours=1)
self.profile.save()
sent = self.profile.send_report(nag=True)
self.assertTrue(sent)
# And an email should have been sent
self.assertEqual(len(mail.outbox), 1)
message = mail.outbox[0]
self.assertEqual(message.subject, 'Reminder: 1 check still down')
self.assertIn("Test Check", message.body)
示例13: test_status_works_with_timezone
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import last_ping [as 别名]
def test_status_works_with_timezone(self):
dt = timezone.make_aware(datetime(2000, 1, 1), timezone=timezone.utc)
# Expect ping every day at 10am, default grace is 1 hour
check = Check()
check.kind = "cron"
check.schedule = "0 10 * * *"
check.status = "up"
check.last_ping = dt
check.tz = "Australia/Brisbane" # UTC+10
# 10:30am
now = dt + timedelta(days=1, minutes=30)
self.assertEqual(check.get_status(now), "up")
# 11:30am
now = dt + timedelta(days=1, minutes=90)
self.assertEqual(check.get_status(now), "down")
示例14: test_it_updates_alert_after
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import last_ping [as 别名]
def test_it_updates_alert_after(self, mock_notify):
check = Check(user=self.alice, status="up")
check.last_ping = timezone.now() - timedelta(hours=1)
check.alert_after = check.last_ping
check.save()
result = Command().handle_one()
# If it finds work, it should return True
self.assertTrue(result)
# It should change stored status to "down"
check.refresh_from_db()
# alert_after should have been increased
self.assertTrue(check.alert_after > check.last_ping)
# notify should *not* have been called
self.assertFalse(mock_notify.called)
示例15: test_it_notifies_when_check_goes_up
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import last_ping [as 别名]
def test_it_notifies_when_check_goes_up(self, mock_notify):
check = Check(user=self.alice, status="down")
check.last_ping = now()
check.alert_after = check.get_alert_after()
check.save()
result = Command().handle_one()
# If it finds work, it should return True
self.assertTrue(result)
# It should change stored status to "up"
check.refresh_from_db()
self.assertEqual(check.status, "up")
# It should call `notify_on_thread`
self.assertTrue(mock_notify.called)
# alert_after now should be set
self.assertTrue(check.alert_after)