0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-03-15 20:54:53 +00:00

Add "Test!" function in the Integrations page. Fixes

This commit is contained in:
Pēteris Caune 2019-04-20 17:55:16 +03:00
parent 2a7129f8c8
commit ab86580b32
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
6 changed files with 73 additions and 3 deletions

View file

@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
- Show "Badges" and "Settings" in top navigation (#234)
- Upgrade to Django 2.2
- Can configure the email integration to only report the "down" events (#231)
- Add "Test!" function in the Integrations page (#207)
## 1.6.0 - 2019-04-01

View file

@ -0,0 +1,30 @@
from django.core import mail
from hc.api.models import Channel
from hc.test import BaseTestCase
class SendTestNotificationTestCase(BaseTestCase):
def setUp(self):
super(SendTestNotificationTestCase, self).setUp()
self.channel = Channel(kind="email", project=self.project)
self.channel.email_verified = True
self.channel.value = "alice@example.org"
self.channel.save()
self.url = "/integrations/%s/test/" % self.channel.code
def test_it_sends_test_email(self):
self.client.login(username="alice@example.org", password="password")
r = self.client.post(self.url, {}, follow=True)
self.assertRedirects(r, "/integrations/")
self.assertContains(r, "Test notification sent!")
# And email should have been sent
self.assertEqual(len(mail.outbox), 1)
email = mail.outbox[0]
self.assertEqual(email.to[0], "alice@example.org")
self.assertTrue("X-Bounce-Url" in email.extra_headers)
self.assertTrue("List-Unsubscribe" in email.extra_headers)

View file

@ -40,6 +40,7 @@ channel_urls = [
path('add_matrix/', views.add_matrix, name="hc-add-matrix"),
path('<uuid:code>/checks/', views.channel_checks, name="hc-channel-checks"),
path('<uuid:code>/name/', views.update_channel_name, name="hc-channel-name"),
path('<uuid:code>/test/', views.send_test_notification, name="hc-channel-test"),
path('<uuid:code>/remove/', views.remove_channel, name="hc-remove-channel"),
path('<uuid:code>/verify/<slug:token>/', views.verify_email,
name="hc-verify-email"),

View file

@ -659,6 +659,30 @@ def unsubscribe_email(request, code, token):
return render(request, "front/unsubscribe_success.html")
@require_POST
@login_required
def send_test_notification(request, code):
channel = get_object_or_404(Channel, code=code)
if channel.project_id != request.project.id:
return HttpResponseForbidden()
dummy = Check(name="TEST", status="down")
dummy.last_ping = timezone.now() - td(days=1)
dummy.n_pings = 42
if channel.kind == "email":
error = channel.transport.notify(dummy, channel.get_unsub_link())
else:
error = channel.transport.notify(dummy)
if error:
messages.warning(request, "Could not send a test notification: %s" % error)
else:
messages.success(request, "Test notification sent!")
return redirect("hc-channels")
@require_POST
@login_required
def remove_channel(request, code):

View file

@ -105,11 +105,15 @@ table.channels-table > tbody > tr > th {
color: #000;
}
.channel-remove {
.channel-row .actions form {
display: inline;
}
.channel-row .actions .btn {
visibility: hidden;
}
.channel-row:hover .channel-remove {
.channel-row:hover .actions .btn {
visibility: visible;
}

View file

@ -131,7 +131,17 @@
<p>Used {{ profile.sms_sent_this_month }} of {{ profile.sms_limit }} sends this month.</p>
{% endif %}
</td>
<td>
<td class="actions">
<form action="{% url 'hc-channel-test' ch.code %}" method="post">
{% csrf_token %}
<button
class="btn btn-sm btn-default"
data-toggle="tooltip"
title="Send a test notification using this integration"
type="submit">
Test!
</button>
</form>
<button
data-kind="{{ ch.get_kind_display }}"
data-url="{% url 'hc-remove-channel' ch.code %}"