@ -0,0 +1,24 @@ | |||
import json | |||
from hc.api.models import Channel | |||
from hc.test import BaseTestCase | |||
class ChannelsTestCase(BaseTestCase): | |||
def test_it_formats_complex_slack_value(self): | |||
ch = Channel(kind="slack", user=self.alice) | |||
ch.value = json.dumps({ | |||
"ok": True, | |||
"team_name": "foo-team", | |||
"incoming_webhook": { | |||
"url": "http://example.org", | |||
"channel": "#bar" | |||
} | |||
}) | |||
ch.save() | |||
self.client.login(username="[email protected]", password="password") | |||
r = self.client.get("/integrations/") | |||
self.assertContains(r, "foo-team", status_code=200) | |||
self.assertContains(r, "#bar") |
@ -0,0 +1,53 @@ | |||
import json | |||
from django.test.utils import override_settings | |||
from hc.api.models import Channel | |||
from hc.test import BaseTestCase | |||
from mock import patch | |||
@override_settings(PUSHOVER_API_TOKEN="token", PUSHOVER_SUBSCRIPTION_URL="url") | |||
class SlackCallbackTestCase(BaseTestCase): | |||
@patch("hc.front.views.requests.post") | |||
def test_it_works(self, mock_post): | |||
oauth_response = { | |||
"ok": True, | |||
"team_name": "foo", | |||
"incoming_webhook": { | |||
"url": "http://example.org", | |||
"channel": "bar" | |||
} | |||
} | |||
mock_post.return_value.text = json.dumps(oauth_response) | |||
mock_post.return_value.json.return_value = oauth_response | |||
url = "/integrations/add_slack_btn/?code=12345678" | |||
self.client.login(username="[email protected]", password="password") | |||
r = self.client.get(url, follow=True) | |||
self.assertRedirects(r, "/integrations/") | |||
self.assertContains(r, "The Slack integration has been added!") | |||
ch = Channel.objects.get() | |||
self.assertEqual(ch.slack_team, "foo") | |||
self.assertEqual(ch.slack_channel, "bar") | |||
self.assertEqual(ch.slack_webhook_url, "http://example.org") | |||
@patch("hc.front.views.requests.post") | |||
def test_it_handles_error(self, mock_post): | |||
oauth_response = { | |||
"ok": False, | |||
"error": "something went wrong" | |||
} | |||
mock_post.return_value.text = json.dumps(oauth_response) | |||
mock_post.return_value.json.return_value = oauth_response | |||
url = "/integrations/add_slack_btn/?code=12345678" | |||
self.client.login(username="[email protected]", password="password") | |||
r = self.client.get(url, follow=True) | |||
self.assertRedirects(r, "/integrations/") | |||
self.assertContains(r, "something went wrong") |
@ -6,6 +6,14 @@ | |||
{% block content %} | |||
<div class="row"> | |||
{% if messages %} | |||
<div class="col-sm-12"> | |||
{% for message in messages %} | |||
<p class="alert alert-{{ message.tags }}">{{ message }}</p> | |||
{% endfor %} | |||
</div> | |||
{% endif %} | |||
<div class="col-sm-12"> | |||
<table class="table channels-table"> | |||
{% if channels %} | |||
@ -44,6 +52,15 @@ | |||
<span class="preposition">user key</span> | |||
{{ ch.po_value|first }} | |||
({{ ch.po_value|last }} priority) | |||
{% elif ch.kind == "slack" %} | |||
{% if ch.slack_team %} | |||
<span class="preposition">team</span> | |||
{{ ch.slack_team }}, | |||
<span class="preposition">channel</span> | |||
{{ ch.slack_channel }} | |||
{% else %} | |||
{{ ch.value }} | |||
{% endif %} | |||
{% elif ch.kind == "webhook" %} | |||
<table> | |||
{% if ch.value_down %} | |||
@ -107,16 +124,22 @@ | |||
<ul class="add-integration"> | |||
<li> | |||
<img src="{% static 'img/integrations/slack.png' %}" | |||
alt="Slack icon" /> | |||
class="icon" alt="Slack icon" /> | |||
<h2>Slack</h2> | |||
<p>A messaging app for teams.</p> | |||
{% if slack_client_id %} | |||
<a href="https://slack.com/oauth/authorize?scope=incoming-webhook&client_id={{ slack_client_id }}"> | |||
<img alt="Add to Slack" height="40" width="139" src="https://platform.slack-edge.com/img/add_to_slack.png" srcset="https://platform.slack-edge.com/img/add_to_slack.png 1x, https://platform.slack-edge.com/img/[email protected] 2x" /> | |||
</a> | |||
{% else %} | |||
<a href="{% url 'hc-add-slack' %}" class="btn btn-primary">Add Integration</a> | |||
{% endif %} | |||
</li> | |||
<li> | |||
<img src="{% static 'img/integrations/email.png' %}" | |||
alt="Email icon" /> | |||
class="icon" alt="Email icon" /> | |||
<h2>Email</h2> | |||
<p>Get an email message when check goes up or down.</p> | |||
@ -125,7 +148,7 @@ | |||
</li> | |||
<li> | |||
<img src="{% static 'img/integrations/webhook.png' %}" | |||
alt="Webhook icon" /> | |||
class="icon" alt="Webhook icon" /> | |||
<h2>Webhook</h2> | |||
<p>Receive a HTTP callback when a check goes down.</p> | |||
@ -134,7 +157,7 @@ | |||
</li> | |||
<li> | |||
<img src="{% static 'img/integrations/pd.png' %}" | |||
alt="PagerDuty icon" /> | |||
class="icon" alt="PagerDuty icon" /> | |||
<h2>PagerDuty</h2> | |||
<p>On-call scheduling, alerting, and incident tracking.</p> | |||
@ -143,7 +166,7 @@ | |||
</li> | |||
<li> | |||
<img src="{% static 'img/integrations/hipchat.png' %}" | |||
alt="HipChat icon" /> | |||
class="icon" alt="HipChat icon" /> | |||
<h2>HipChat</h2> | |||
<p>Group and private chat, file sharing, and integrations.</p> | |||
@ -152,7 +175,7 @@ | |||
</li> | |||
<li> | |||
<img src="{% static 'img/integrations/victorops.png' %}" | |||
alt="VictorOps icon" /> | |||
class="icon" alt="VictorOps icon" /> | |||
<h2>VictorOps</h2> | |||
<p>On-call scheduling, alerting, and incident tracking.</p> | |||
@ -162,7 +185,7 @@ | |||
{% if enable_pushover %} | |||
<li> | |||
<img src="{% static 'img/integrations/pushover.png' %}" | |||
alt="Pushover icon" /> | |||
class="icon" alt="Pushover icon" /> | |||
<h2>Pushover</h2> | |||
<p>Receive instant push notifications on your phone or tablet.</p> | |||