@ -754,6 +754,44 @@ class NotifyTestCase(BaseTestCase): | |||||
self.assertEqual(email.to[0], "[email protected]") | self.assertEqual(email.to[0], "[email protected]") | ||||
self.assertEqual(email.subject, "Monthly WhatsApp Limit Reached") | self.assertEqual(email.subject, "Monthly WhatsApp Limit Reached") | ||||
@patch("hc.api.transports.requests.request") | |||||
def test_call(self, mock_post): | |||||
value = {"label": "foo", "value": "+1234567890"} | |||||
self._setup_data("call", json.dumps(value)) | |||||
self.check.last_ping = now() - td(hours=2) | |||||
mock_post.return_value.status_code = 200 | |||||
self.channel.notify(self.check) | |||||
assert Notification.objects.count() == 1 | |||||
args, kwargs = mock_post.call_args | |||||
payload = kwargs["data"] | |||||
self.assertEqual(payload["To"], "+1234567890") | |||||
@patch("hc.api.transports.requests.request") | |||||
def test_call_limit(self, mock_post): | |||||
# At limit already: | |||||
self.profile.last_sms_date = now() | |||||
self.profile.sms_sent = 50 | |||||
self.profile.save() | |||||
definition = {"value": "+1234567890"} | |||||
self._setup_data("call", json.dumps(definition)) | |||||
self.channel.notify(self.check) | |||||
self.assertFalse(mock_post.called) | |||||
n = Notification.objects.get() | |||||
self.assertTrue("Monthly phone call limit exceeded" in n.error) | |||||
# And email should have been sent | |||||
self.assertEqual(len(mail.outbox), 1) | |||||
email = mail.outbox[0] | |||||
self.assertEqual(email.to[0], "[email protected]") | |||||
self.assertEqual(email.subject, "Monthly Phone Call Limit Reached") | |||||
@patch("apprise.Apprise") | @patch("apprise.Apprise") | ||||
@override_settings(APPRISE_ENABLED=True) | @override_settings(APPRISE_ENABLED=True) | ||||
def test_apprise_enabled(self, mock_apprise): | def test_apprise_enabled(self, mock_apprise): | ||||
@ -0,0 +1,59 @@ | |||||
from django.test.utils import override_settings | |||||
from hc.api.models import Channel | |||||
from hc.test import BaseTestCase | |||||
@override_settings(TWILIO_ACCOUNT="foo", TWILIO_AUTH="foo", TWILIO_FROM="123") | |||||
class AddCallTestCase(BaseTestCase): | |||||
def setUp(self): | |||||
super(AddCallTestCase, self).setUp() | |||||
self.url = "/projects/%s/add_call/" % self.project.code | |||||
def test_instructions_work(self): | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.get(self.url) | |||||
self.assertContains(r, "Get a phone call") | |||||
@override_settings(USE_PAYMENTS=True) | |||||
def test_it_warns_about_limits(self): | |||||
self.profile.sms_limit = 0 | |||||
self.profile.save() | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.get(self.url) | |||||
self.assertContains(r, "upgrade to a") | |||||
def test_it_creates_channel(self): | |||||
form = {"label": "My Phone", "value": "+1234567890"} | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.post(self.url, form) | |||||
self.assertRedirects(r, self.channels_url) | |||||
c = Channel.objects.get() | |||||
self.assertEqual(c.kind, "call") | |||||
self.assertEqual(c.sms_number, "+1234567890") | |||||
self.assertEqual(c.name, "My Phone") | |||||
self.assertEqual(c.project, self.project) | |||||
def test_it_rejects_bad_number(self): | |||||
form = {"value": "not a phone number"} | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.post(self.url, form) | |||||
self.assertContains(r, "Invalid phone number format.") | |||||
def test_it_trims_whitespace(self): | |||||
form = {"value": " +1234567890 "} | |||||
self.client.login(username="[email protected]", password="password") | |||||
self.client.post(self.url, form) | |||||
c = Channel.objects.get() | |||||
self.assertEqual(c.sms_number, "+1234567890") | |||||
@override_settings(TWILIO_AUTH=None) | |||||
def test_it_requires_credentials(self): | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.get(self.url) | |||||
self.assertEqual(r.status_code, 404) |
@ -1 +1 @@ | |||||
Monthly {{ transport }} Limit Reached | |||||
Monthly {% if transport == "phone call" %}Phone Call{% else %}{{ transport }}{% endif %} Limit Reached |
@ -0,0 +1,84 @@ | |||||
{% extends "base.html" %} | |||||
{% load humanize static hc_extras %} | |||||
{% block title %}Add Phone Call Integration - {{ site_name }}{% endblock %} | |||||
{% block content %} | |||||
<div class="row"> | |||||
<div class="col-sm-12"> | |||||
<h1>Phone Call</h1> | |||||
<p> | |||||
Get a phone call when a check goes down. When you pick up the call, | |||||
a text-to-speech engine will read out a message and then hang up. | |||||
</p> | |||||
{% if show_pricing and profile.sms_limit == 0 %} | |||||
<p class="alert alert-info"> | |||||
<strong>Paid plan required.</strong> | |||||
Phone call notifications are not available on the free plan–they | |||||
cost too much! Please upgrade to a | |||||
<a href="{% url 'hc-billing' %}">paid plan</a> | |||||
to enable phone call notifications. | |||||
</p> | |||||
{% endif %} | |||||
<h2>Integration Settings</h2> | |||||
<form method="post" class="form-horizontal"> | |||||
{% csrf_token %} | |||||
<div class="form-group {{ form.label.css_classes }}"> | |||||
<label for="id_label" class="col-sm-2 control-label">Label</label> | |||||
<div class="col-sm-6"> | |||||
<input | |||||
id="id_label" | |||||
type="text" | |||||
class="form-control" | |||||
name="label" | |||||
placeholder="Alice's Phone" | |||||
value="{{ form.label.value|default:"" }}"> | |||||
{% if form.label.errors %} | |||||
<div class="help-block"> | |||||
{{ form.label.errors|join:"" }} | |||||
</div> | |||||
{% else %} | |||||
<span class="help-block"> | |||||
Optional. If you add multiple phone numbers, | |||||
the labels will help you tell them apart. | |||||
</span> | |||||
{% endif %} | |||||
</div> | |||||
</div> | |||||
<div class="form-group {{ form.value.css_classes }}"> | |||||
<label for="id_number" class="col-sm-2 control-label">Phone Number</label> | |||||
<div class="col-sm-3"> | |||||
<input | |||||
id="id_number" | |||||
type="tel" | |||||
class="form-control" | |||||
name="value" | |||||
placeholder="+1234567890" | |||||
value="{{ form.value.value|default:"" }}"> | |||||
{% if form.value.errors %} | |||||
<div class="help-block"> | |||||
{{ form.value.errors|join:"" }} | |||||
</div> | |||||
{% else %} | |||||
<span class="help-block"> | |||||
Make sure the phone number starts with "+" and has the | |||||
country code. | |||||
</span> | |||||
{% 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> | |||||
{% endblock %} |
@ -0,0 +1 @@ | |||||
<Response><Say>Hello! A message from {{ site_name }}: The check "{{ check.name_then_code }}" is down.</Say></Response> |