diff --git a/hc/api/tests/test_email_webhook.py b/hc/api/tests/test_email_webhook.py deleted file mode 100644 index 64e80b3c..00000000 --- a/hc/api/tests/test_email_webhook.py +++ /dev/null @@ -1,37 +0,0 @@ -import json - -from django.test import TestCase - -from hc.api.models import Check, Ping - - -class EmailTestCase(TestCase): - - def test_it_works(self): - check = Check() - check.save() - - payload = [{ - "event": "inbound", - "msg": { - "raw_msg": "This is raw message", - "to": [ - ["somewhere@example.com", "Somebody"], - ["%s@example.com" % check.code, "Healthchecks"] - ] - } - }] - - data = {"mandrill_events": json.dumps(payload)} - r = self.client.post("/handle_email/", data=data) - assert r.status_code == 200 - - same_check = Check.objects.get(code=check.code) - assert same_check.status == "up" - - pings = list(Ping.objects.all()) - assert pings[0].scheme == "email" - - def test_it_rejects_get(self): - r = self.client.get("/handle_email/") - assert r.status_code == 400 diff --git a/hc/api/urls.py b/hc/api/urls.py index 2506c48f..b89830d0 100644 --- a/hc/api/urls.py +++ b/hc/api/urls.py @@ -5,6 +5,5 @@ from hc.api import views urlpatterns = [ url(r'^ping/([\w-]+)/$', views.ping, name="hc-ping-slash"), url(r'^ping/([\w-]+)$', views.ping, name="hc-ping"), - url(r'^handle_email/$', views.handle_email, name="hc-handle-email"), url(r'^api/v1/checks/$', views.create_check), ] diff --git a/hc/api/views.py b/hc/api/views.py index 92725864..530baf19 100644 --- a/hc/api/views.py +++ b/hc/api/views.py @@ -45,37 +45,6 @@ def ping(request, code): return response -@csrf_exempt -def handle_email(request): - if request.method != "POST": - return HttpResponseBadRequest() - - events = json.loads(request.POST["mandrill_events"]) - for event in events: - for recipient_address, recipient_name in event["msg"]["to"]: - code, domain = recipient_address.split("@") - try: - check = Check.objects.get(code=code) - except ValueError: - continue - except Check.DoesNotExist: - continue - - check.n_pings = F("n_pings") + 1 - check.last_ping = timezone.now() - if check.status == "new": - check.status = "up" - - check.save() - - ping = Ping(owner=check) - ping.scheme = "email" - ping.save() - - response = HttpResponse("OK") - return response - - @csrf_exempt @check_api_key @validate_json(schemas.check) @@ -84,11 +53,11 @@ def create_check(request): code = 200 response = { "checks": [{ - "name": check.name, - "ping_url" : check.url(), - "tags": check.tags, - "timeout": int(check.timeout.total_seconds()), - "grace": int(check.grace.total_seconds()), + "name": check.name, + "ping_url": check.url(), + "tags": check.tags, + "timeout": int(check.timeout.total_seconds()), + "grace": int(check.grace.total_seconds()), # "channels": check.channels, } for check in Check.objects.filter(user=request.user)] }