本文整理汇总了Python中hc.api.models.Check.refresh_from_db方法的典型用法代码示例。如果您正苦于以下问题:Python Check.refresh_from_db方法的具体用法?Python Check.refresh_from_db怎么用?Python Check.refresh_from_db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hc.api.models.Check
的用法示例。
在下文中一共展示了Check.refresh_from_db方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_it_works
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import refresh_from_db [as 别名]
def test_it_works(self):
check = Check(user=self.alice, status="up")
check.save()
url = "/api/v1/checks/%s/pause" % check.code
r = self.client.post(url, "", content_type="application/json",
HTTP_X_API_KEY="abc")
self.assertEqual(r.status_code, 200)
check.refresh_from_db()
self.assertEqual(check.status, "paused")
示例2: PauseTestCase
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import refresh_from_db [as 别名]
class PauseTestCase(BaseTestCase):
def setUp(self):
super(PauseTestCase, self).setUp()
self.check = Check(user=self.alice, status="up")
self.check.save()
def test_it_pauses(self):
url = "/checks/%s/pause/" % self.check.code
self.client.login(username="[email protected]", password="password")
r = self.client.post(url)
self.assertRedirects(r, "/checks/")
self.check.refresh_from_db()
self.assertEqual(self.check.status, "paused")
示例3: test_it_notifies_when_check_goes_down
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import refresh_from_db [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)
示例4: test_it_updates_alert_after
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import refresh_from_db [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)
示例5: test_it_notifies_when_check_goes_up
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import refresh_from_db [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)
示例6: UpdateCheckTestCase
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import refresh_from_db [as 别名]
class UpdateCheckTestCase(BaseTestCase):
def setUp(self):
super(UpdateCheckTestCase, self).setUp()
self.check = Check(user=self.alice)
self.check.save()
def post(self, code, data):
url = "/api/v1/checks/%s" % code
r = self.client.post(url, json.dumps(data),
content_type="application/json")
return r
def test_it_works(self):
r = self.post(self.check.code, {
"api_key": "abc",
"name": "Foo",
"tags": "bar,baz",
"timeout": 3600,
"grace": 60
})
self.assertEqual(r.status_code, 200)
doc = r.json()
assert "ping_url" in doc
self.assertEqual(doc["name"], "Foo")
self.assertEqual(doc["tags"], "bar,baz")
self.assertEqual(doc["last_ping"], None)
self.assertEqual(doc["n_pings"], 0)
self.assertTrue("schedule" not in doc)
self.assertTrue("tz" not in doc)
self.assertEqual(Check.objects.count(), 1)
self.check.refresh_from_db()
self.assertEqual(self.check.name, "Foo")
self.assertEqual(self.check.tags, "bar,baz")
self.assertEqual(self.check.timeout.total_seconds(), 3600)
self.assertEqual(self.check.grace.total_seconds(), 60)
def test_it_unassigns_channels(self):
channel = Channel(user=self.alice)
channel.save()
self.check.assign_all_channels()
r = self.post(self.check.code, {
"api_key": "abc",
"channels": ""
})
self.assertEqual(r.status_code, 200)
check = Check.objects.get()
self.assertEqual(check.channel_set.count(), 0)
def test_it_requires_post(self):
url = "/api/v1/checks/%s" % self.check.code
r = self.client.get(url, HTTP_X_API_KEY="abc")
self.assertEqual(r.status_code, 405)
def test_it_handles_invalid_uuid(self):
r = self.post("not-an-uuid", {"api_key": "abc"})
self.assertEqual(r.status_code, 400)
def test_it_handles_missing_check(self):
made_up_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02"
r = self.post(made_up_code, {"api_key": "abc"})
self.assertEqual(r.status_code, 404)
def test_it_validates_ownership(self):
check = Check(user=self.bob, status="up")
check.save()
r = self.post(check.code, {"api_key": "abc"})
self.assertEqual(r.status_code, 403)
def test_it_updates_cron_to_simple(self):
self.check.kind = "cron"
self.check.schedule = "5 * * * *"
self.check.save()
r = self.post(self.check.code, {"api_key": "abc", "timeout": 3600})
self.assertEqual(r.status_code, 200)
self.check.refresh_from_db()
self.assertEqual(self.check.kind, "simple")
示例7: UpdateTimeoutTestCase
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import refresh_from_db [as 别名]
class UpdateTimeoutTestCase(BaseTestCase):
def setUp(self):
super(UpdateTimeoutTestCase, self).setUp()
self.check = Check(user=self.alice)
self.check.last_ping = timezone.now()
self.check.save()
def test_it_works(self):
url = "/checks/%s/timeout/" % self.check.code
payload = {"kind": "simple", "timeout": 3600, "grace": 60}
self.client.login(username="[email protected]", password="password")
r = self.client.post(url, data=payload)
self.assertRedirects(r, "/checks/")
self.check.refresh_from_db()
self.assertEqual(self.check.kind, "simple")
self.assertEqual(self.check.timeout.total_seconds(), 3600)
self.assertEqual(self.check.grace.total_seconds(), 60)
# alert_after should be updated too
self.assertEqual(self.check.alert_after, self.check.get_alert_after())
def test_it_saves_cron_expression(self):
url = "/checks/%s/timeout/" % self.check.code
payload = {
"kind": "cron",
"schedule": "* * * * *",
"tz": "UTC",
"timeout": 60,
"grace": 60
}
self.client.login(username="[email protected]", password="password")
r = self.client.post(url, data=payload)
self.assertRedirects(r, "/checks/")
self.check.refresh_from_db()
self.assertEqual(self.check.kind, "cron")
self.assertEqual(self.check.schedule, "* * * * *")
def test_team_access_works(self):
url = "/checks/%s/timeout/" % self.check.code
payload = {"kind": "simple", "timeout": 7200, "grace": 60}
# Logging in as bob, not alice. Bob has team access so this
# should work.
self.client.login(username="[email protected]", password="password")
self.client.post(url, data=payload)
check = Check.objects.get(code=self.check.code)
assert check.timeout.total_seconds() == 7200
def test_it_handles_bad_uuid(self):
url = "/checks/not-uuid/timeout/"
payload = {"timeout": 3600, "grace": 60}
self.client.login(username="[email protected]", password="password")
r = self.client.post(url, data=payload)
assert r.status_code == 400
def test_it_handles_missing_uuid(self):
# Valid UUID but there is no check for it:
url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/timeout/"
payload = {"timeout": 3600, "grace": 60}
self.client.login(username="[email protected]", password="password")
r = self.client.post(url, data=payload)
assert r.status_code == 404
def test_it_checks_ownership(self):
url = "/checks/%s/timeout/" % self.check.code
payload = {"timeout": 3600, "grace": 60}
self.client.login(username="[email protected]", password="password")
r = self.client.post(url, data=payload)
assert r.status_code == 403