@ -0,0 +1,46 @@ | |||||
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(DISCORD_CLIENT_ID="t1", DISCORD_CLIENT_SECRET="s1") | |||||
class AddDiscordTestCase(BaseTestCase): | |||||
url = "/integrations/add_discord/" | |||||
def test_instructions_work(self): | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.get(self.url) | |||||
self.assertContains(r, "Connect Discord", status_code=200) | |||||
self.assertContains(r, "discordapp.com/api/oauth2/authorize") | |||||
@override_settings(DISCORD_CLIENT_ID=None) | |||||
def test_it_requires_client_id(self): | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.get(self.url) | |||||
self.assertEqual(r.status_code, 404) | |||||
@patch("hc.front.views.requests.post") | |||||
def test_it_handles_oauth_response(self, mock_post): | |||||
oauth_response = { | |||||
"access_token": "test-token", | |||||
"webhook": { | |||||
"url": "foo", | |||||
"id": "bar" | |||||
} | |||||
} | |||||
mock_post.return_value.text = json.dumps(oauth_response) | |||||
mock_post.return_value.json.return_value = oauth_response | |||||
url = self.url + "?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 Discord integration has been added!") | |||||
ch = Channel.objects.get() | |||||
self.assertEqual(ch.discord_webhook_url, "foo") |
@ -11,14 +11,10 @@ class AddPushbulletTestCase(BaseTestCase): | |||||
url = "/integrations/add_pushbullet/" | url = "/integrations/add_pushbullet/" | ||||
def test_instructions_work(self): | def test_instructions_work(self): | ||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.get(self.url) | |||||
self.assertContains(r, "Connect Pushbullet") | |||||
def test_it_shows_instructions(self): | |||||
self.client.login(username="[email protected]", password="password") | self.client.login(username="[email protected]", password="password") | ||||
r = self.client.get(self.url) | r = self.client.get(self.url) | ||||
self.assertContains(r, "www.pushbullet.com/authorize", status_code=200) | self.assertContains(r, "www.pushbullet.com/authorize", status_code=200) | ||||
self.assertContains(r, "Connect Pushbullet") | |||||
@override_settings(PUSHBULLET_CLIENT_ID=None) | @override_settings(PUSHBULLET_CLIENT_ID=None) | ||||
def test_it_requires_client_id(self): | def test_it_requires_client_id(self): | ||||
@ -0,0 +1,37 @@ | |||||
{% extends "base.html" %} | |||||
{% load compress humanize staticfiles hc_extras %} | |||||
{% block title %}Add Discord - {% site_name %}{% endblock %} | |||||
{% block content %} | |||||
<div class="row"> | |||||
<div class="col-sm-12"> | |||||
<h1>Discord</h1> | |||||
<div class="jumbotron"> | |||||
<p> | |||||
With this integration, {% site_name %} will send | |||||
a notification to a <a href="http://discord.com/">Discord</a> | |||||
channel when a check | |||||
goes <strong>up</strong> or <strong>down</strong>. | |||||
</p> | |||||
<form method="post" class="text-center"> | |||||
{% csrf_token %} | |||||
<a href="{{ authorize_url }}" class="btn btn-default"> | |||||
<img class="ai-icon" src="{% static 'img/integrations/discord.png' %}" alt="Discord" /> | |||||
Connect Discord | |||||
</a> | |||||
</form> | |||||
</div> | |||||
</div> | |||||
</div> | |||||
{% endblock %} | |||||
{% block scripts %} | |||||
{% compress js %} | |||||
<script src="{% static 'js/jquery-2.1.4.min.js' %}"></script> | |||||
<script src="{% static 'js/bootstrap.min.js' %}"></script> | |||||
{% endcompress %} | |||||
{% endblock %} |