Pēteris Caune
4 years ago
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
13 changed files with 200 additions and 136 deletions
-
2README.md
-
36hc/front/tests/test_add_linenotify.py
-
81hc/front/tests/test_add_linenotify_complete.py
-
2hc/front/tests/test_add_pushbullet_complete.py
-
1hc/front/urls.py
-
89hc/front/views.py
-
3hc/settings.py
-
BINstatic/img/integrations/setup_linenotify_1.png
-
BINstatic/img/integrations/setup_linenotify_2.png
-
BINstatic/img/integrations/setup_linenotify_3.png
-
2templates/front/channels.html
-
2templates/front/welcome.html
-
118templates/integrations/add_linenotify.html
@ -0,0 +1,81 @@ |
|||
from unittest.mock import patch |
|||
|
|||
from django.test.utils import override_settings |
|||
from hc.api.models import Channel |
|||
from hc.test import BaseTestCase |
|||
|
|||
|
|||
@override_settings(LINENOTIFY_CLIENT_ID="t1", LINENOTIFY_CLIENT_SECRET="s1") |
|||
class AddLineNotifyCompleteTestCase(BaseTestCase): |
|||
url = "/integrations/add_linenotify/" |
|||
|
|||
@patch("hc.front.views.requests") |
|||
def test_it_handles_oauth_response(self, mock_requests): |
|||
session = self.client.session |
|||
session["add_linenotify"] = ("foo", str(self.project.code)) |
|||
session.save() |
|||
|
|||
mock_requests.post.return_value.json.return_value = { |
|||
"status": 200, |
|||
"access_token": "test-token", |
|||
} |
|||
|
|||
mock_requests.get.return_value.json.return_value = {"target": "Alice"} |
|||
|
|||
url = self.url + "?code=12345678&state=foo" |
|||
|
|||
self.client.login(username="alice@example.org", password="password") |
|||
r = self.client.get(url, follow=True) |
|||
self.assertRedirects(r, self.channels_url) |
|||
self.assertContains(r, "The LINE Notify integration has been added!") |
|||
|
|||
ch = Channel.objects.get() |
|||
self.assertEqual(ch.value, "test-token") |
|||
self.assertEqual(ch.name, "Alice") |
|||
self.assertEqual(ch.project, self.project) |
|||
|
|||
# Session should now be clean |
|||
self.assertFalse("add_linenotify" in self.client.session) |
|||
|
|||
def test_it_avoids_csrf(self): |
|||
session = self.client.session |
|||
session["add_linenotify"] = ("foo", str(self.project.code)) |
|||
session.save() |
|||
|
|||
url = self.url + "?code=12345678&state=bar" |
|||
|
|||
self.client.login(username="alice@example.org", password="password") |
|||
r = self.client.get(url) |
|||
self.assertEqual(r.status_code, 403) |
|||
|
|||
def test_it_handles_denial(self): |
|||
session = self.client.session |
|||
session["add_linenotify"] = ("foo", str(self.project.code)) |
|||
session.save() |
|||
|
|||
self.client.login(username="alice@example.org", password="password") |
|||
r = self.client.get(self.url + "?error=access_denied&state=foo", follow=True) |
|||
self.assertRedirects(r, self.channels_url) |
|||
self.assertContains(r, "LINE Notify setup was cancelled") |
|||
|
|||
self.assertEqual(Channel.objects.count(), 0) |
|||
|
|||
# Session should now be clean |
|||
self.assertFalse("add_linenotify" in self.client.session) |
|||
|
|||
@override_settings(LINENOTIFY_CLIENT_ID=None) |
|||
def test_it_requires_client_id(self): |
|||
url = self.url + "?code=12345678&state=bar" |
|||
|
|||
self.client.login(username="alice@example.org", password="password") |
|||
r = self.client.get(url) |
|||
self.assertEqual(r.status_code, 404) |
|||
|
|||
def test_it_requires_rw_access(self): |
|||
self.bobs_membership.rw = False |
|||
self.bobs_membership.save() |
|||
|
|||
url = self.url + "?code=12345678&state=bar" |
|||
self.client.login(username="bob@example.org", password="password") |
|||
r = self.client.get(url) |
|||
self.assertEqual(r.status_code, 403) |
Before Width: 2030 | Height: 1626 | Size: 253 KiB |
Before Width: 996 | Height: 1472 | Size: 121 KiB |
Before Width: 1034 | Height: 906 | Size: 79 KiB |
@ -1,104 +1,30 @@ |
|||
{% extends "base.html" %} |
|||
{% load humanize static hc_extras %} |
|||
|
|||
{% block title %}LineNotify Integration for {% site_name %}{% endblock %} |
|||
{% block title %}LINE Notify Integration for {{ site_name }}{% endblock %} |
|||
|
|||
|
|||
{% block content %} |
|||
<div class="row"> |
|||
<div class="col-sm-12"> |
|||
<h1>LINE Notify</h1> |
|||
|
|||
<p><a href="https://notify-bot.line.me/en/">LINE Notify</a> |
|||
allows you to send notifications directly to your LINE chats. |
|||
You can set up {% site_name %} to post status updates directly to an |
|||
appropriate LINE chat. </p> |
|||
|
|||
|
|||
<h2>Setup Guide</h2> |
|||
|
|||
<div class="row ai-step"> |
|||
<div class="col-sm-6"> |
|||
<span class="step-no"></span> |
|||
<p> |
|||
Log into your LINE account, |
|||
go to <strong>My Page</strong> in the upper right corner. |
|||
In the <strong>My Page</strong>, scroll to the bottom of the page, |
|||
and click on <strong>Generate token</strong> button. |
|||
</p> |
|||
</div> |
|||
<div class="col-sm-6"> |
|||
<div class="marker-wrap"> |
|||
<span style="left: 77%; top: 14%;" class="marker"></span> |
|||
<img |
|||
class="ai-guide-screenshot" |
|||
alt="Screenshot" |
|||
src="{% static 'img/integrations/setup_linenotify_1.png' %}" /> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="row ai-step"> |
|||
<div class="col-sm-6"> |
|||
<span class="step-no"></span> |
|||
<p> |
|||
It will pop up the <strong>Generate token</strong> Form. |
|||
Fill out the details, and click the button. |
|||
</p> |
|||
</div> |
|||
<div class="col-sm-6"> |
|||
<img |
|||
class="ai-guide-screenshot" |
|||
alt="Screenshot" |
|||
src="{% static 'img/integrations/setup_linenotify_2.png' %}"> |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="row ai-step"> |
|||
<div class="col-sm-6"> |
|||
<span class="step-no"></span> |
|||
<p> |
|||
Copy the displayed <strong>Token</strong> and paste it |
|||
in the form below. |
|||
Save the integration, and it's done! |
|||
</p> |
|||
</div> |
|||
<div class="col-sm-6"> |
|||
<img |
|||
class="ai-guide-screenshot" |
|||
alt="Screenshot" |
|||
src="{% static 'img/integrations/setup_linenotify_3.png' %}"> |
|||
</div> |
|||
</div> |
|||
|
|||
<h2>Integration Settings</h2> |
|||
|
|||
<form method="post" class="form-horizontal"> |
|||
{% csrf_token %} |
|||
<div class="form-group {{ form.value.css_classes }}"> |
|||
<label for="api-token" class="col-sm-2 control-label">API Token</label> |
|||
<div class="col-sm-10"> |
|||
<input |
|||
id="api-token" |
|||
type="text" |
|||
class="form-control" |
|||
name="token" |
|||
placeholder="" |
|||
value="{{ form.token.value|default:"" }}"> |
|||
|
|||
{% if form.token.errors %} |
|||
<div class="help-block"> |
|||
{{ form.token.errors|join:"" }} |
|||
</div> |
|||
{% endif %} |
|||
</div> |
|||
</div> |
|||
<div class="form-group"> |
|||
<div class="col-sm-offset-2 col-sm-10"> |
|||
<button type="submit" class="btn btn-primary">Save Integration</button> |
|||
</div> |
|||
</div> |
|||
</form> |
|||
</div> |
|||
<div class="col-sm-12"> |
|||
<h1>LINE Notify</h1> |
|||
|
|||
<div class="jumbotron"> |
|||
<p> |
|||
With the <a href="https://notify-bot.line.me/en/">LINE Notify</a> |
|||
integration, {{ site_name }} will send |
|||
a notification to your selected LINE chat 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-lg btn-default"> |
|||
<img class="ai-icon" src="{% static 'img/integrations/linenotify.png' %}" alt="LINE Notify" /> |
|||
Connect LINE Notify |
|||
</a> |
|||
</form> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
{% endblock %} |
|||
{% endblock %} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue