Skip to content

Commit

Permalink
taught zebra to understand ping events.
Browse files Browse the repository at this point in the history
  • Loading branch information
skoczen committed Sep 25, 2011
1 parent 08b753e commit 1558193
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions zebra/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
zebra_webhook_recurring_payment_succeeded = django.dispatch.Signal(providing_args=WEBHOOK_ARGS)
zebra_webhook_subscription_trial_ending = django.dispatch.Signal(providing_args=WEBHOOK_ARGS)
zebra_webhook_subscription_final_payment_attempt_failed = django.dispatch.Signal(providing_args=WEBHOOK_ARGS)
zebra_webhook_subscription_ping_sent = django.dispatch.Signal(providing_args=[])
3 changes: 3 additions & 0 deletions zebra/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def webhooks(request):
elif json["event"] == "subscription_final_payment_attempt_failed":
zebra_webhook_subscription_final_payment_attempt_failed.send(sender=None, customer=_try_to_get_customer_from_customer_id(json["customer"]), full_json=json)

elif json["event"] == "ping":
zebra_webhook_subscription_ping_sent.send(sender=None)

else:
return HttpResponse(status=400)

Expand Down
20 changes: 20 additions & 0 deletions zebra_sample_project/marty/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,23 @@ def test_webhooks_return_valid_customer_obj_as_an_arg(self):

self.assertEqual(response.status_code, 200)
self.assertEqual(self.customer, cust)




def test_ping_webhook_signal_fired(self):
zebra_webhook_subscription_ping_sent.connect(self._signal_reciever)

self.assertEqual(self.signal_kwargs, None)

# Pulled directly from the stripe docs
test_post_data = {'json': simplejson.dumps(
{
"event":"ping",
}
) }

c = Client()
response = c.post(reverse("zebra:webhooks"), test_post_data)

self.assertEqual(response.status_code, 200)

0 comments on commit 1558193

Please sign in to comment.