forked from GithubBackups/healthchecks
Webhook for Mandrill inbound email notifications, WIP
This commit is contained in:
parent
b75ab00d18
commit
32fb29c299
@ -15,7 +15,10 @@ class EmailTestCase(TestCase):
|
||||
"event": "inbound",
|
||||
"msg": {
|
||||
"raw_msg": "This is raw message",
|
||||
"to": ["somewhere@example.com", "%s@example.com" % check.code]
|
||||
"to": [
|
||||
["somewhere@example.com", "Somebody"],
|
||||
["%s@example.com" % check.code, "Healthchecks"]
|
||||
]
|
||||
}
|
||||
}]
|
||||
|
||||
@ -29,3 +32,7 @@ class EmailTestCase(TestCase):
|
||||
pings = list(Ping.objects.all())
|
||||
assert pings[0].scheme == "email"
|
||||
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
|
||||
|
@ -40,10 +40,13 @@ def ping(request, code):
|
||||
|
||||
@csrf_exempt
|
||||
def handle_email(request):
|
||||
if request.method != "POST":
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
events = json.loads(request.POST["mandrill_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:
|
||||
check = Check.objects.get(code=code)
|
||||
except ValueError:
|
||||
|
Loading…
x
Reference in New Issue
Block a user