Browse Source

Webhook for Mandrill inbound email notifications, WIP

pull/7/head
Pēteris Caune 9 years ago
parent
commit
32fb29c299
2 changed files with 13 additions and 3 deletions
  1. +8
    -1
      hc/api/tests/test_email_webhook.py
  2. +5
    -2
      hc/api/views.py

+ 8
- 1
hc/api/tests/test_email_webhook.py View File

@ -15,7 +15,10 @@ class EmailTestCase(TestCase):
"event": "inbound", "event": "inbound",
"msg": { "msg": {
"raw_msg": "This is raw message", "raw_msg": "This is raw message",
"to": ["[email protected]", "%s@example.com" % check.code]
"to": [
["[email protected]", "Somebody"],
["%s@example.com" % check.code, "Healthchecks"]
]
} }
}] }]
@ -29,3 +32,7 @@ class EmailTestCase(TestCase):
pings = list(Ping.objects.all()) pings = list(Ping.objects.all())
assert pings[0].scheme == "email" assert pings[0].scheme == "email"
assert pings[0].body == "This is raw message" assert pings[0].body == "This is raw message"
def test_it_rejects_get(self):
r = self.client.get("/handle_email/")
assert r.status_code == 400

+ 5
- 2
hc/api/views.py View File

@ -40,10 +40,13 @@ def ping(request, code):
@csrf_exempt @csrf_exempt
def handle_email(request): def handle_email(request):
if request.method != "POST":
return HttpResponseBadRequest()
events = json.loads(request.POST["mandrill_events"]) events = json.loads(request.POST["mandrill_events"])
for event in events: for event in events:
for to_address in event["msg"]["to"]:
code, domain = to_address.split("@")
for recipient_address, recipient_name in event["msg"]["to"]:
code, domain = recipient_address.split("@")
try: try:
check = Check.objects.get(code=code) check = Check.objects.get(code=code)
except ValueError: except ValueError:


Loading…
Cancel
Save