forked from GithubBackups/healthchecks
Project code in URL for the "Add Webhook" page. cc: #336
This commit is contained in:
parent
ea423e5420
commit
59f5b7a5f5
@ -23,7 +23,7 @@ class AddEmailTestCase(BaseTestCase):
|
|||||||
|
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
r = self.client.post(self.url, form)
|
r = self.client.post(self.url, form)
|
||||||
self.assertRedirects(r, "/projects/%s/integrations/" % self.project.code)
|
self.assertRedirects(r, self.channels_url)
|
||||||
|
|
||||||
c = Channel.objects.get()
|
c = Channel.objects.get()
|
||||||
doc = json.loads(c.value)
|
doc = json.loads(c.value)
|
||||||
@ -79,7 +79,7 @@ class AddEmailTestCase(BaseTestCase):
|
|||||||
|
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
r = self.client.post(self.url, form)
|
r = self.client.post(self.url, form)
|
||||||
self.assertRedirects(r, "/projects/%s/integrations/" % self.project.code)
|
self.assertRedirects(r, self.channels_url)
|
||||||
|
|
||||||
c = Channel.objects.get()
|
c = Channel.objects.get()
|
||||||
doc = json.loads(c.value)
|
doc = json.loads(c.value)
|
||||||
@ -95,7 +95,7 @@ class AddEmailTestCase(BaseTestCase):
|
|||||||
|
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
r = self.client.post(self.url, form)
|
r = self.client.post(self.url, form)
|
||||||
self.assertRedirects(r, "/projects/%s/integrations/" % self.project.code)
|
self.assertRedirects(r, self.channels_url)
|
||||||
|
|
||||||
c = Channel.objects.get()
|
c = Channel.objects.get()
|
||||||
doc = json.loads(c.value)
|
doc = json.loads(c.value)
|
||||||
|
@ -3,7 +3,9 @@ from hc.test import BaseTestCase
|
|||||||
|
|
||||||
|
|
||||||
class AddWebhookTestCase(BaseTestCase):
|
class AddWebhookTestCase(BaseTestCase):
|
||||||
url = "/integrations/add_webhook/"
|
def setUp(self):
|
||||||
|
super(AddWebhookTestCase, self).setUp()
|
||||||
|
self.url = "/projects/%s/add_webhook/" % self.project.code
|
||||||
|
|
||||||
def test_instructions_work(self):
|
def test_instructions_work(self):
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
@ -20,7 +22,7 @@ class AddWebhookTestCase(BaseTestCase):
|
|||||||
|
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
r = self.client.post(self.url, form)
|
r = self.client.post(self.url, form)
|
||||||
self.assertRedirects(r, "/integrations/")
|
self.assertRedirects(r, self.channels_url)
|
||||||
|
|
||||||
c = Channel.objects.get()
|
c = Channel.objects.get()
|
||||||
self.assertEqual(c.project, self.project)
|
self.assertEqual(c.project, self.project)
|
||||||
@ -95,7 +97,7 @@ class AddWebhookTestCase(BaseTestCase):
|
|||||||
|
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
r = self.client.post(self.url, form)
|
r = self.client.post(self.url, form)
|
||||||
self.assertRedirects(r, "/integrations/")
|
self.assertRedirects(r, self.channels_url)
|
||||||
|
|
||||||
c = Channel.objects.get()
|
c = Channel.objects.get()
|
||||||
self.assertEqual(c.down_webhook_spec["body"], "hello")
|
self.assertEqual(c.down_webhook_spec["body"], "hello")
|
||||||
@ -110,7 +112,7 @@ class AddWebhookTestCase(BaseTestCase):
|
|||||||
|
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
r = self.client.post(self.url, form)
|
r = self.client.post(self.url, form)
|
||||||
self.assertRedirects(r, "/integrations/")
|
self.assertRedirects(r, self.channels_url)
|
||||||
|
|
||||||
c = Channel.objects.get()
|
c = Channel.objects.get()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -140,7 +142,7 @@ class AddWebhookTestCase(BaseTestCase):
|
|||||||
|
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
r = self.client.post(self.url, form)
|
r = self.client.post(self.url, form)
|
||||||
self.assertRedirects(r, "/integrations/")
|
self.assertRedirects(r, self.channels_url)
|
||||||
|
|
||||||
c = Channel.objects.get()
|
c = Channel.objects.get()
|
||||||
self.assertEqual(c.down_webhook_spec["headers"], {"test": "123"})
|
self.assertEqual(c.down_webhook_spec["headers"], {"test": "123"})
|
||||||
|
@ -24,7 +24,6 @@ check_urls = [
|
|||||||
|
|
||||||
channel_urls = [
|
channel_urls = [
|
||||||
path("", views.channels, name="hc-channels"),
|
path("", views.channels, name="hc-channels"),
|
||||||
path("add_webhook/", views.add_webhook, name="hc-add-webhook"),
|
|
||||||
path("add_shell/", views.add_shell, name="hc-add-shell"),
|
path("add_shell/", views.add_shell, name="hc-add-shell"),
|
||||||
path("add_pd/", views.add_pd, name="hc-add-pd"),
|
path("add_pd/", views.add_pd, name="hc-add-pd"),
|
||||||
path("add_pdc/", views.add_pdc, name="hc-add-pdc"),
|
path("add_pdc/", views.add_pdc, name="hc-add-pdc"),
|
||||||
@ -76,6 +75,7 @@ urlpatterns = [
|
|||||||
path("integrations/", include(channel_urls)),
|
path("integrations/", include(channel_urls)),
|
||||||
path("projects/<uuid:code>/integrations/", views.channels, name="hc-p-channels"),
|
path("projects/<uuid:code>/integrations/", views.channels, name="hc-p-channels"),
|
||||||
path("projects/<uuid:code>/add_email/", views.add_email, name="hc-add-email"),
|
path("projects/<uuid:code>/add_email/", views.add_email, name="hc-add-email"),
|
||||||
|
path("projects/<uuid:code>/add_webhook/", views.add_webhook, name="hc-add-webhook"),
|
||||||
path("docs/", views.serve_doc, name="hc-docs"),
|
path("docs/", views.serve_doc, name="hc-docs"),
|
||||||
path("docs/api/", views.docs_api, name="hc-docs-api"),
|
path("docs/api/", views.docs_api, name="hc-docs-api"),
|
||||||
path("docs/cron/", views.docs_cron, name="hc-docs-cron"),
|
path("docs/cron/", views.docs_cron, name="hc-docs-cron"),
|
||||||
|
@ -851,22 +851,24 @@ def add_email(request, code):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def add_webhook(request):
|
def add_webhook(request, code):
|
||||||
|
project = _get_project_for_user(request, code)
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = AddWebhookForm(request.POST)
|
form = AddWebhookForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
channel = Channel(project=request.project, kind="webhook")
|
channel = Channel(project=project, kind="webhook")
|
||||||
channel.value = form.get_value()
|
channel.value = form.get_value()
|
||||||
channel.save()
|
channel.save()
|
||||||
|
|
||||||
channel.assign_all_checks()
|
channel.assign_all_checks()
|
||||||
return redirect("hc-channels")
|
return redirect("hc-p-channels", project.code)
|
||||||
else:
|
else:
|
||||||
form = AddWebhookForm()
|
form = AddWebhookForm()
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
"page": "channels",
|
"page": "channels",
|
||||||
"project": request.project,
|
"project": project,
|
||||||
"form": form,
|
"form": form,
|
||||||
"now": timezone.now().replace(microsecond=0).isoformat(),
|
"now": timezone.now().replace(microsecond=0).isoformat(),
|
||||||
}
|
}
|
||||||
|
@ -50,3 +50,5 @@ class BaseTestCase(TestCase):
|
|||||||
self.charlies_profile = Profile(user=self.charlie)
|
self.charlies_profile = Profile(user=self.charlie)
|
||||||
self.charlies_profile.current_project = self.charlies_project
|
self.charlies_profile.current_project = self.charlies_project
|
||||||
self.charlies_profile.save()
|
self.charlies_profile.save()
|
||||||
|
|
||||||
|
self.channels_url = "/projects/%s/integrations/" % self.project.code
|
||||||
|
@ -189,7 +189,7 @@
|
|||||||
<h2>Webhook</h2>
|
<h2>Webhook</h2>
|
||||||
<p>Receive a HTTP callback when a check goes down.</p>
|
<p>Receive a HTTP callback when a check goes down.</p>
|
||||||
|
|
||||||
<a href="{% url 'hc-add-webhook' %}" class="btn btn-primary">Add Integration</a>
|
<a href="{% url 'hc-add-webhook' project.code %}" class="btn btn-primary">Add Integration</a>
|
||||||
</li>
|
</li>
|
||||||
{% if enable_apprise %}
|
{% if enable_apprise %}
|
||||||
<li>
|
<li>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user