-
-
Notifications
You must be signed in to change notification settings - Fork 968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #1722 -- Add more tests for fundraising webhook #1761
base: main
Are you sure you want to change the base?
Conversation
fundraising/tests/test_views.py
Outdated
customer.return_value = self.stripe_data("customer") | ||
payment_intent.return_value = self.stripe_data("payment_intent") | ||
event = self.stripe_data("session_completed") | ||
WebhookHandler(event).handle() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason behind not using self.post_event()
like the other tests and calling the class directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this to call self.post_event()
!
fundraising/tests/test_views.py
Outdated
event = self.stripe_data("session_completed") | ||
WebhookHandler(event).handle() | ||
customer.assert_called_once() | ||
payment_intent.assert_called_once() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinks that should also be tested:
- That the email is sent. There's an example above,
self.assertEqual(len(mail.outbox), 1)
- That the response of the handler is the correct one, It should be a 204.
- What happens if the
DjangoHero
instance doesn't exist (this should probably be a different test (or could be a new PR to add this to every event test since right now they don't check this case))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It now checks that the email is sent, and the status code is 204.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the case where DjangoHero
does not exist, I added a test that modifies the existing DjangoHero's stripe_customer_id, and then check that count for DjangoHero is increased to 2. Is that the right approach?
self.hero.stripe_customer_id = "" | ||
self.hero.save() | ||
response = self.post_event(self.stripe_data("session_completed")) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we check here too that the mail is sent?
self.assertEqual(DjangoHero.objects.count(), 1) | ||
|
||
def test_checkout_session_completed_new_hero(self): | ||
self.hero.stripe_customer_id = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if there's a better way to do this. Either by deleting the Hero in this test before the event or by not hardcoding the stripe customer id in the setUp
.
This approach works, tho.
@bmispelon Any suggestions?
Fix for #1722
Added test for
checkout_session_completed
. The test fails when reverting the change in e995213.A new file is added in
test_data
. It was generated by calling callingstripe.Customer.list().data[0]
,stripe.PaymentIntent.list().data[0]
, etc.@bmispelon @alexgmin