Project code in URL for the "Add Apprise" page. cc: #336

This commit is contained in:
Pēteris Caune 2020-02-21 15:40:56 +02:00
parent 056134f2de
commit 88f2a01182
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
5 changed files with 23 additions and 31 deletions

View File

@ -5,17 +5,21 @@ from django.test.utils import override_settings
@override_settings(APPRISE_ENABLED=True) @override_settings(APPRISE_ENABLED=True)
class AddAppriseTestCase(BaseTestCase): class AddAppriseTestCase(BaseTestCase):
def setUp(self):
super(AddAppriseTestCase, self).setUp()
self.url = "/projects/%s/add_apprise/" % 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")
r = self.client.get("/integrations/add_apprise/") r = self.client.get(self.url)
self.assertContains(r, "Integration Settings", status_code=200) self.assertContains(r, "Integration Settings", status_code=200)
def test_it_works(self): def test_it_works(self):
form = {"url": "json://example.org"} form = {"url": "json://example.org"}
self.client.login(username="alice@example.org", password="password") self.client.login(username="alice@example.org", password="password")
r = self.client.post("/integrations/add_apprise/", 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.kind, "apprise") self.assertEqual(c.kind, "apprise")
@ -25,5 +29,5 @@ class AddAppriseTestCase(BaseTestCase):
@override_settings(APPRISE_ENABLED=False) @override_settings(APPRISE_ENABLED=False)
def test_it_requires_client_id(self): def test_it_requires_client_id(self):
self.client.login(username="alice@example.org", password="password") self.client.login(username="alice@example.org", password="password")
r = self.client.get("/integrations/add_apprise/") r = self.client.get(self.url)
self.assertEqual(r.status_code, 404) self.assertEqual(r.status_code, 404)

View File

@ -4,6 +4,8 @@ from hc.test import BaseTestCase
from mock import patch from mock import patch
@override_settings(MATRIX_ACCESS_TOKEN="foo")
@override_settings(MATRIX_HOMESERVER="fake-homeserver")
class AddMatrixTestCase(BaseTestCase): class AddMatrixTestCase(BaseTestCase):
def setUp(self): def setUp(self):
super(AddMatrixTestCase, self).setUp() super(AddMatrixTestCase, self).setUp()
@ -15,8 +17,6 @@ class AddMatrixTestCase(BaseTestCase):
r = self.client.get(self.url) r = self.client.get(self.url)
self.assertContains(r, "Integration Settings", status_code=200) self.assertContains(r, "Integration Settings", status_code=200)
@override_settings(MATRIX_ACCESS_TOKEN="foo")
@override_settings(MATRIX_HOMESERVER="fake-homeserver")
@patch("hc.front.forms.requests.post") @patch("hc.front.forms.requests.post")
def test_it_works(self, mock_post): def test_it_works(self, mock_post):
mock_post.return_value.json.return_value = {"room_id": "fake-room-id"} mock_post.return_value.json.return_value = {"room_id": "fake-room-id"}
@ -30,3 +30,9 @@ class AddMatrixTestCase(BaseTestCase):
self.assertEqual(c.kind, "matrix") self.assertEqual(c.kind, "matrix")
self.assertEqual(c.value, "fake-room-id") self.assertEqual(c.value, "fake-room-id")
self.assertEqual(c.project, self.project) self.assertEqual(c.project, self.project)
@override_settings(MATRIX_ACCESS_TOKEN=None)
def test_it_requires_access_token(self):
self.client.login(username="alice@example.org", password="password")
r = self.client.get(self.url)
self.assertEqual(r.status_code, 404)

View File

@ -37,7 +37,6 @@ channel_urls = [
path("add_telegram/", views.add_telegram, name="hc-add-telegram"), path("add_telegram/", views.add_telegram, name="hc-add-telegram"),
path("add_trello/", views.add_trello, name="hc-add-trello"), path("add_trello/", views.add_trello, name="hc-add-trello"),
path("add_trello/settings/", views.trello_settings, name="hc-trello-settings"), path("add_trello/settings/", views.trello_settings, name="hc-trello-settings"),
path("add_apprise/", views.add_apprise, name="hc-add-apprise"),
path("<uuid:code>/checks/", views.channel_checks, name="hc-channel-checks"), 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>/name/", views.update_channel_name, name="hc-channel-name"),
path("<uuid:code>/test/", views.send_test_notification, name="hc-channel-test"), path("<uuid:code>/test/", views.send_test_notification, name="hc-channel-test"),
@ -53,6 +52,7 @@ channel_urls = [
] ]
project_urls = [ project_urls = [
path("add_apprise/", views.add_apprise, name="hc-add-apprise"),
path("add_email/", views.add_email, name="hc-add-email"), path("add_email/", views.add_email, name="hc-add-email"),
path("add_matrix/", views.add_matrix, name="hc-add-matrix"), path("add_matrix/", views.add_matrix, name="hc-add-matrix"),
path("add_mattermost/", views.add_mattermost, name="hc-add-mattermost"), path("add_mattermost/", views.add_mattermost, name="hc-add-mattermost"),

View File

@ -1502,24 +1502,25 @@ def add_matrix(request, code):
@login_required @login_required
def add_apprise(request): def add_apprise(request, code):
if not settings.APPRISE_ENABLED: if not settings.APPRISE_ENABLED:
raise Http404("apprise integration is not available") raise Http404("apprise integration is not available")
project = _get_project_for_user(request, code)
if request.method == "POST": if request.method == "POST":
form = AddAppriseForm(request.POST) form = AddAppriseForm(request.POST)
if form.is_valid(): if form.is_valid():
channel = Channel(project=request.project, kind="apprise") channel = Channel(project=project, kind="apprise")
channel.value = form.cleaned_data["url"] channel.value = form.cleaned_data["url"]
channel.save() channel.save()
channel.assign_all_checks() channel.assign_all_checks()
messages.success(request, "The Apprise integration has been added!") messages.success(request, "The Apprise integration has been added!")
return redirect("hc-channels") return redirect("hc-p-channels", project.code)
else: else:
form = AddAppriseForm() form = AddAppriseForm()
ctx = {"page": "channels", "project": request.project, "form": form} ctx = {"page": "channels", "project": project, "form": form}
return render(request, "integrations/add_apprise.html", ctx) return render(request, "integrations/add_apprise.html", ctx)

View File

@ -178,7 +178,6 @@
<h2>Email</h2> <h2>Email</h2>
<p>Get an email message when a check goes up or down.</p> <p>Get an email message when a check goes up or down.</p>
<a href="{% url 'hc-add-email' project.code %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-email' project.code %}" class="btn btn-primary">Add Integration</a>
</li> </li>
@ -188,7 +187,6 @@
<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' project.code %}" 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 %}
@ -198,8 +196,7 @@
<h2>Apprise</h2> <h2>Apprise</h2>
<p>Receive instant push notifications using Apprise; see <a href="https://github.com/caronc/apprise#popular-notification-services" >all of the supported services here</a>.</p> <p>Receive instant push notifications using Apprise; see <a href="https://github.com/caronc/apprise#popular-notification-services" >all of the supported services here</a>.</p>
<a href="{% url 'hc-add-apprise' project.code %}" class="btn btn-primary">Add Integration</a>
<a href="{% url 'hc-add-apprise' %}" class="btn btn-primary">Add Integration</a>
</li> </li>
{% endif %} {% endif %}
@ -210,7 +207,6 @@
<h2>Discord</h2> <h2>Discord</h2>
<p>Cross-platform voice and text chat app designed for gamers.</p> <p>Cross-platform voice and text chat app designed for gamers.</p>
<a href="{% url 'hc-add-discord' %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-discord' %}" class="btn btn-primary">Add Integration</a>
</li> </li>
{% endif %} {% endif %}
@ -222,7 +218,6 @@
<h2>Matrix</h2> <h2>Matrix</h2>
<p>Post notifications to a Matrix room.</p> <p>Post notifications to a Matrix room.</p>
<a href="{% url 'hc-add-matrix' project.code %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-matrix' project.code %}" class="btn btn-primary">Add Integration</a>
</li> </li>
{% endif %} {% endif %}
@ -233,7 +228,6 @@
<h2>Mattermost</h2> <h2>Mattermost</h2>
<p>High Trust Messaging for the Enterprise.</p> <p>High Trust Messaging for the Enterprise.</p>
<a href="{% url 'hc-add-mattermost' project.code %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-mattermost' project.code %}" class="btn btn-primary">Add Integration</a>
</li> </li>
@ -243,7 +237,6 @@
<h2>Microsoft Teams</h2> <h2>Microsoft Teams</h2>
<p>Chat and collaboration platform for Microsoft Office 365 customers.</p> <p>Chat and collaboration platform for Microsoft Office 365 customers.</p>
<a href="{% url 'hc-add-msteams' project.code %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-msteams' project.code %}" class="btn btn-primary">Add Integration</a>
</li> </li>
@ -253,7 +246,6 @@
<h2>OpsGenie</h2> <h2>OpsGenie</h2>
<p> Alerting &amp; Incident Management Solution for Dev &amp; Ops.</p> <p> Alerting &amp; Incident Management Solution for Dev &amp; Ops.</p>
<a href="{% url 'hc-add-opsgenie' project.code %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-opsgenie' project.code %}" class="btn btn-primary">Add Integration</a>
</li> </li>
@ -277,7 +269,6 @@
<h2>Pager Team</h2> <h2>Pager Team</h2>
<p>On-call rotations without limits.</p> <p>On-call rotations without limits.</p>
<a href="{% url 'hc-add-pagerteam' project.code %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-pagerteam' project.code %}" class="btn btn-primary">Add Integration</a>
</li> </li>
@ -287,7 +278,6 @@
<h2>PagerTree</h2> <h2>PagerTree</h2>
<p>DevOps Incident Management - On-Call Schedules, Alerts, &amp; Notifications</p> <p>DevOps Incident Management - On-Call Schedules, Alerts, &amp; Notifications</p>
<a href="{% url 'hc-add-pagertree' project.code %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-pagertree' project.code %}" class="btn btn-primary">Add Integration</a>
</li> </li>
@ -297,7 +287,6 @@
<h2>Prometheus</h2> <h2>Prometheus</h2>
<p>Export check and tag status values to Prometheus.</p> <p>Export check and tag status values to Prometheus.</p>
<a href="{% url 'hc-add-prometheus' project.code %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-prometheus' project.code %}" class="btn btn-primary">Add Integration</a>
</li> </li>
@ -308,7 +297,6 @@
<h2>Pushbullet</h2> <h2>Pushbullet</h2>
<p>Pushbullet connects your devices, making them feel like one.</p> <p>Pushbullet connects your devices, making them feel like one.</p>
<a href="{% url 'hc-add-pushbullet' %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-pushbullet' %}" class="btn btn-primary">Add Integration</a>
</li> </li>
{% endif %} {% endif %}
@ -320,7 +308,6 @@
<h2>Pushover</h2> <h2>Pushover</h2>
<p>Receive instant push notifications on your phone or tablet.</p> <p>Receive instant push notifications on your phone or tablet.</p>
<a href="{% url 'hc-add-pushover' %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-pushover' %}" class="btn btn-primary">Add Integration</a>
</li> </li>
{% endif %} {% endif %}
@ -332,7 +319,6 @@
<h2>Shell Command</h2> <h2>Shell Command</h2>
<p>Execute a local shell command when a check goes up or down.</p> <p>Execute a local shell command when a check goes up or down.</p>
<a href="{% url 'hc-add-shell' %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-shell' %}" class="btn btn-primary">Add Integration</a>
</li> </li>
{% endif %} {% endif %}
@ -344,7 +330,6 @@
<h2>SMS</h2> <h2>SMS</h2>
<p>Get a text message to your phone when a check goes down.</p> <p>Get a text message to your phone when a check goes down.</p>
<a href="{% url 'hc-add-sms' project.code %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-sms' project.code %}" class="btn btn-primary">Add Integration</a>
</li> </li>
{% endif %} {% endif %}
@ -356,7 +341,6 @@
<h2>Telegram</h2> <h2>Telegram</h2>
<p>A messaging app with a focus on speed and security.</p> <p>A messaging app with a focus on speed and security.</p>
<a href="{% url 'hc-add-telegram' %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-telegram' %}" class="btn btn-primary">Add Integration</a>
</li> </li>
{% endif %} {% endif %}
@ -368,7 +352,6 @@
<h2>Trello</h2> <h2>Trello</h2>
<p>Create a Trello card when a check goes down.</p> <p>Create a Trello card when a check goes down.</p>
<a href="{% url 'hc-add-trello' %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-trello' %}" class="btn btn-primary">Add Integration</a>
</li> </li>
{% endif %} {% endif %}
@ -379,7 +362,6 @@
<h2>VictorOps</h2> <h2>VictorOps</h2>
<p>On-call scheduling, alerting, and incident tracking.</p> <p>On-call scheduling, alerting, and incident tracking.</p>
<a href="{% url 'hc-add-victorops' project.code %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-victorops' project.code %}" class="btn btn-primary">Add Integration</a>
</li> </li>
@ -390,7 +372,6 @@
<h2>WhatsApp</h2> <h2>WhatsApp</h2>
<p>Get a WhatsApp message when a check goes up or down.</p> <p>Get a WhatsApp message when a check goes up or down.</p>
<a href="{% url 'hc-add-whatsapp' project.code %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-whatsapp' project.code %}" class="btn btn-primary">Add Integration</a>
</li> </li>
{% endif %} {% endif %}