@ -0,0 +1,20 @@ | |||
# -*- coding: utf-8 -*- | |||
# Generated by Django 1.11.6 on 2017-12-29 20:08 | |||
from __future__ import unicode_literals | |||
from django.db import migrations, models | |||
class Migration(migrations.Migration): | |||
dependencies = [ | |||
('api', '0034_auto_20171227_1530'), | |||
] | |||
operations = [ | |||
migrations.AlterField( | |||
model_name='channel', | |||
name='kind', | |||
field=models.CharField(choices=[('email', 'Email'), ('webhook', 'Webhook'), ('hipchat', 'HipChat'), ('slack', 'Slack'), ('pd', 'PagerDuty'), ('pagertree', 'PagerTree'), ('po', 'Pushover'), ('pushbullet', 'Pushbullet'), ('opsgenie', 'OpsGenie'), ('victorops', 'VictorOps'), ('discord', 'Discord'), ('telegram', 'Telegram'), ('sms', 'SMS'), ('zendesk', 'Zendesk')], max_length=20), | |||
), | |||
] |
@ -0,0 +1,68 @@ | |||
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(ZENDESK_CLIENT_ID="t1", ZENDESK_CLIENT_SECRET="s1") | |||
class AddZendeskTestCase(BaseTestCase): | |||
url = "/integrations/add_zendesk/" | |||
def test_instructions_work(self): | |||
self.client.login(username="[email protected]", password="password") | |||
r = self.client.get(self.url) | |||
self.assertContains(r, "Connect Zendesk Support", status_code=200) | |||
def test_post_works(self): | |||
self.client.login(username="[email protected]", password="password") | |||
r = self.client.post(self.url, {"subdomain": "foo"}) | |||
self.assertEqual(r.status_code, 302) | |||
self.assertTrue("foo.zendesk.com" in r["Location"]) | |||
# There should now be a key in session | |||
self.assertTrue("zendesk" in self.client.session) | |||
@override_settings(ZENDESK_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): | |||
session = self.client.session | |||
session["zendesk"] = "foo" | |||
session["subdomain"] = "foodomain" | |||
session.save() | |||
oauth_response = {"access_token": "test-token"} | |||
mock_post.return_value.text = json.dumps(oauth_response) | |||
mock_post.return_value.json.return_value = oauth_response | |||
url = self.url + "?code=12345678&state=foo" | |||
self.client.login(username="[email protected]", password="password") | |||
r = self.client.get(url, follow=True) | |||
self.assertRedirects(r, "/integrations/") | |||
self.assertContains(r, "The Zendesk integration has been added!") | |||
ch = Channel.objects.get() | |||
self.assertEqual(ch.zendesk_token, "test-token") | |||
self.assertEqual(ch.zendesk_subdomain, "foodomain") | |||
# Session should now be clean | |||
self.assertFalse("zendesk" in self.client.session) | |||
self.assertFalse("subdomain" in self.client.session) | |||
def test_it_avoids_csrf(self): | |||
session = self.client.session | |||
session["zendesk"] = "foo" | |||
session.save() | |||
url = self.url + "?code=12345678&state=bar" | |||
self.client.login(username="[email protected]", password="password") | |||
r = self.client.get(url) | |||
self.assertEqual(r.status_code, 400) |
@ -0,0 +1,43 @@ | |||
{% extends "base.html" %} | |||
{% load compress humanize staticfiles hc_extras %} | |||
{% block title %}Add Zendesk - {% site_name %}{% endblock %} | |||
{% block content %} | |||
<div class="row"> | |||
<div class="col-sm-12"> | |||
<h1>Zendesk Support</h1> | |||
<div class="jumbotron"> | |||
<p> | |||
If your team uses <a href="http://zendesk.com/">Zendesk</a>, | |||
you can set up {% site_name %} to create Zendesk support tickets | |||
when checks go <strong>down</strong>, and comment on them when | |||
checks go back <strong>up</strong>. | |||
</p> | |||
<form method="post"> | |||
{% csrf_token %} | |||
<div class="row"> | |||
<div class="col-sm-offset-3 col-sm-6"> | |||
<div class="input-group input-group-lg zendesk-subdomain"> | |||
<input | |||
name="subdomain" | |||
placeholder="Subdomain" | |||
type="text" | |||
class="form-control"> | |||
<span class="input-group-addon">.zendesk.com</span> | |||
</div> | |||
<button type="submit" class="btn btn-lg btn-default btn-block"> | |||
<img class="ai-icon" src="{% static 'img/integrations/zendesk.png' %}" alt="Zendesk" /> | |||
Connect Zendesk Support | |||
</button> | |||
</div> | |||
</div> | |||
</form> | |||
</div> | |||
</div> | |||
</div> | |||
{% endblock %} |
@ -0,0 +1,8 @@ | |||
{% load humanize %} | |||
{% if check.status == "down" %} | |||
{{ check.name_then_code }} is down. | |||
Last ping was {{ check.last_ping|naturaltime }}. | |||
Log: {{ check.log_url }} | |||
{% else %} | |||
{{ check.name_then_code }} received a ping and is now UP | |||
{% endif %} |
@ -0,0 +1,5 @@ | |||
{% if check.status == "down" %} | |||
{{ check.name_then_code }} is down | |||
{% else %} | |||
{{ check.name_then_code }} is now UP | |||
{% endif %} |