本文整理汇总了Python中hc.api.models.Check类的典型用法代码示例。如果您正苦于以下问题:Python Check类的具体用法?Python Check怎么用?Python Check使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Check类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_status_works_with_grace_period
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_post_works
def test_post_works(self):
check = Check()
check.save()
csrf_client = Client(enforce_csrf_checks=True)
r = csrf_client.post("/ping/%s/" % check.code)
assert r.status_code == 200
示例3: checks
def checks(request):
if request.method == "GET":
q = Check.objects.filter(user=request.user)
tags = set(request.GET.getlist("tag"))
for tag in tags:
# approximate filtering by tags
q = q.filter(tags__contains=tag)
checks = []
for check in q:
# precise, final filtering
if not tags or check.matches_tag_set(tags):
checks.append(check.to_dict())
return JsonResponse({"checks": checks})
elif request.method == "POST":
created = False
check = _lookup(request.user, request.json)
if check is None:
num_checks = Check.objects.filter(user=request.user).count()
if num_checks >= request.user.profile.check_limit:
return HttpResponseForbidden()
check = Check(user=request.user)
created = True
_update(check, request.json)
return JsonResponse(check.to_dict(), status=201 if created else 200)
# If request is neither GET nor POST, return "405 Method not allowed"
return HttpResponse(status=405)
示例4: UpdateNameTestCase
class UpdateNameTestCase(TestCase):
def setUp(self):
self.alice = User(username="alice")
self.alice.set_password("password")
self.alice.save()
self.check = Check(user=self.alice)
self.check.save()
def test_it_works(self):
url = "/checks/%s/name/" % self.check.code
payload = {"name": "Alice Was Here"}
self.client.login(username="alice", password="password")
r = self.client.post(url, data=payload)
assert r.status_code == 302
check = Check.objects.get(code=self.check.code)
assert check.name == "Alice Was Here"
def test_it_checks_ownership(self):
charlie = User(username="charlie")
charlie.set_password("password")
charlie.save()
url = "/checks/%s/name/" % self.check.code
payload = {"name": "Charlie Sent This"}
self.client.login(username="charlie", password="password")
r = self.client.post(url, data=payload)
assert r.status_code == 403
def test_it_handles_bad_uuid(self):
url = "/checks/not-uuid/name/"
payload = {"name": "Alice Was Here"}
self.client.login(username="alice", 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/name/"
payload = {"name": "Alice Was Here"}
self.client.login(username="alice", password="password")
r = self.client.post(url, data=payload)
assert r.status_code == 404
def test_it_sanitizes_tags(self):
url = "/checks/%s/name/" % self.check.code
payload = {"tags": " foo bar\r\t \n baz \n"}
self.client.login(username="alice", password="password")
self.client.post(url, data=payload)
check = Check.objects.get(id=self.check.id)
self.assertEqual(check.tags, "foo bar baz")
示例5: checks
def checks(request):
if request.method == "GET":
q = Check.objects.filter(user=request.user)
doc = {"checks": [check.to_dict() for check in q]}
return JsonResponse(doc)
elif request.method == "POST":
check = Check(user=request.user)
check.name = str(request.json.get("name", ""))
check.tags = str(request.json.get("tags", ""))
if "timeout" in request.json:
check.timeout = td(seconds=request.json["timeout"])
if "grace" in request.json:
check.grace = td(seconds=request.json["grace"])
check.save()
# This needs to be done after saving the check, because of
# the M2M relation between checks and channels:
if request.json.get("channels") == "*":
check.assign_all_channels()
return JsonResponse(check.to_dict(), status=201)
# If request is neither GET nor POST, return "405 Method not allowed"
return HttpResponse(status=405)
示例6: test_it_works
def test_it_works(self):
check = Check()
check.save()
payload = [{
"event": "inbound",
"msg": {
"raw_msg": "This is raw message",
"to": [
["[email protected]", "Somebody"],
["%[email protected]" % check.code, "Healthchecks"]
]
}
}]
data = {"mandrill_events": json.dumps(payload)}
r = self.client.post("/handle_email/", data=data)
assert r.status_code == 200
same_check = Check.objects.get(code=check.code)
assert same_check.status == "up"
pings = list(Ping.objects.all())
assert pings[0].scheme == "email"
assert pings[0].body == "This is raw message"
示例7: test_it_handles_grace_period
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)
示例8: test_head_works
def test_head_works(self):
check = Check()
check.save()
csrf_client = Client(enforce_csrf_checks=True)
r = csrf_client.head("/ping/%s/" % check.code)
assert r.status_code == 200
assert Ping.objects.count() == 1
示例9: test_it_strips_tags
def test_it_strips_tags(self):
check = Check()
check.tags = " foo bar "
self.assertEquals(check.tags_list(), ["foo", "bar"])
check.tags = " "
self.assertEquals(check.tags_list(), [])
示例10: test_it_shows_only_users_checks
def test_it_shows_only_users_checks(self):
bobs_check = Check(user=self.bob, name="Bob 1")
bobs_check.save()
r = self.get()
data = r.json()
self.assertEqual(len(data["checks"]), 2)
for check in data["checks"]:
self.assertNotEqual(check["name"], "Bob 1")
示例11: test_unique_accepts_only_whitelisted_values
def test_unique_accepts_only_whitelisted_values(self):
existing = Check(user=self.alice, name="Foo")
existing.save()
self.post({
"api_key": "abc",
"name": "Foo",
"unique": ["status"]
}, expected_fragment="unexpected value")
示例12: add_check
def add_check(request):
assert request.method == "POST"
check = Check(user=request.team.user)
check.save()
check.assign_all_channels()
return redirect("hc-checks")
示例13: test_it_validates_ownership
def test_it_validates_ownership(self):
check = Check(user=self.bob, 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, 400)
示例14: NotifyTestCase
class NotifyTestCase(TestCase):
def _setup_data(self, channel_kind, channel_value, email_verified=True):
self.alice = User(username="alice")
self.alice.save()
self.check = Check()
self.check.status = "down"
self.check.save()
self.channel = Channel(user=self.alice)
self.channel.kind = channel_kind
self.channel.value = channel_value
self.channel.email_verified = email_verified
self.channel.save()
self.channel.checks.add(self.check)
@patch("hc.api.models.requests.get")
def test_webhook(self, mock_get):
self._setup_data("webhook", "http://example")
mock_get.return_value.status_code = 200
self.channel.notify(self.check)
mock_get.assert_called_with(u"http://example", timeout=5)
@patch("hc.api.models.requests.get", side_effect=ReadTimeout)
def test_webhooks_handle_timeouts(self, mock_get):
self._setup_data("webhook", "http://example")
self.channel.notify(self.check)
assert Notification.objects.count() == 1
def test_email(self):
self._setup_data("email", "[email protected]")
self.channel.notify(self.check)
assert Notification.objects.count() == 1
# And email should have been sent
self.assertEqual(len(mail.outbox), 1)
def test_it_skips_unverified_email(self):
self._setup_data("email", "[email protected]", email_verified=False)
self.channel.notify(self.check)
assert Notification.objects.count() == 0
self.assertEqual(len(mail.outbox), 0)
@patch("hc.api.models.requests.post")
def test_pd(self, mock_post):
self._setup_data("pd", "123")
mock_post.return_value.status_code = 200
self.channel.notify(self.check)
assert Notification.objects.count() == 1
args, kwargs = mock_post.call_args
assert "trigger" in kwargs["data"]
示例15: test_it_switches
def test_it_switches(self):
c = Check(user=self.alice, name="This belongs to Alice")
c.save()
self.client.login(username="[email protected]", password="password")
url = "/accounts/switch_team/%s/" % self.alice.username
r = self.client.get(url, follow=True)
self.assertContains(r, "This belongs to Alice")