forked from GithubBackups/healthchecks
When creating a check via API, optionally assign all channels.
This commit is contained in:
parent
5725a3a30a
commit
6efb822f95
@ -3,6 +3,7 @@ check = {
|
||||
"name": {"type": "string"},
|
||||
"tags": {"type": "string"},
|
||||
"timeout": {"type": "number", "minimum": 60, "maximum": 604800},
|
||||
"grace": {"type": "number", "minimum": 60, "maximum": 604800}
|
||||
"grace": {"type": "number", "minimum": 60, "maximum": 604800},
|
||||
"channels": {"type": "string"}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import json
|
||||
|
||||
from hc.api.models import Check
|
||||
from hc.api.models import Channel, Check
|
||||
from hc.test import BaseTestCase
|
||||
from hc.accounts.models import Profile
|
||||
|
||||
@ -35,6 +35,19 @@ class CreateCheckTestCase(BaseTestCase):
|
||||
self.assertEqual(check.timeout.total_seconds(), 3600)
|
||||
self.assertEqual(check.grace.total_seconds(), 60)
|
||||
|
||||
def test_it_assigns_channels(self):
|
||||
channel = Channel(user=self.alice)
|
||||
channel.save()
|
||||
|
||||
r = self.post("/api/v1/checks/", {
|
||||
"api_key": "abc",
|
||||
"channels": "*"
|
||||
})
|
||||
|
||||
self.assertEqual(r.status_code, 201)
|
||||
check = Check.objects.get()
|
||||
self.assertEqual(check.channel_set.get(), channel)
|
||||
|
||||
def test_it_handles_missing_request_body(self):
|
||||
r = self.client.post("/api/v1/checks/",
|
||||
content_type="application/json")
|
||||
@ -50,7 +63,7 @@ class CreateCheckTestCase(BaseTestCase):
|
||||
content_type="application/json")
|
||||
self.assertEqual(r.json()["error"], "could not parse request body")
|
||||
|
||||
def test_it_reject_small_timeout(self):
|
||||
def test_it_rejects_small_timeout(self):
|
||||
r = self.post("/api/v1/checks/", {"api_key": "abc", "timeout": 0})
|
||||
self.assertEqual(r.json()["error"], "timeout is too small")
|
||||
|
||||
|
@ -93,6 +93,11 @@ def create_check(request):
|
||||
|
||||
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()
|
||||
|
||||
response = {
|
||||
"ping_url": check.url()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user