-
Notifications
You must be signed in to change notification settings - Fork 10
fix(billing): Fix update address raise error #298
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eb5cc74
fix(billing): Fix update address raise error
suejung-sentry 9577b40
add test
suejung-sentry c7880f0
Merge remote-tracking branch 'origin/main' into sshin/billing
suejung-sentry 489cf74
incorporate pr comments
suejung-sentry 22fe994
fix tests
suejung-sentry c081f96
fix this other test that started failing about stripe api key dunno
suejung-sentry c8731a6
remove my vscode config recommendation
suejung-sentry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1859,20 +1859,29 @@ def test_update_email_address(self, modify_customer_mock): | |
| self.stripe.update_email_address(owner, "[email protected]") | ||
| modify_customer_mock.assert_called_once_with(customer_id, email=email) | ||
|
|
||
| @patch("logging.Logger.error") | ||
| def test_update_billing_address_with_invalid_address(self, log_error_mock): | ||
| @patch("services.billing.stripe.Customer.retrieve") | ||
| @patch("services.billing.stripe.PaymentMethod.modify") | ||
| @patch("services.billing.stripe.Customer.modify") | ||
| def test_update_billing_address_with_invalid_address( | ||
| self, | ||
| modify_customer_mock, | ||
| modify_payment_mock, | ||
| retrieve_customer_mock, | ||
| ): | ||
| owner = OwnerFactory(stripe_customer_id="123", stripe_subscription_id="123") | ||
| assert self.stripe.update_billing_address(owner, "John Doe", "gabagool") is None | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test was failing in CI dunno, was giving error about missing API key again. So changed it to take mocks for the calls to stripe api and still tests invalid address scenario |
||
|
|
||
| # TODO: Logically we expect an error about an invalid billing address, but | ||
| # CI is getting an error about a missing API key and local envs are getting | ||
| # an error about the customer not existing. Needs to be fixed. | ||
| msg, log_args = log_error_mock.call_args | ||
| assert msg[0] == "Unable to update billing address for customer" | ||
| assert log_args["extra"]["customer_id"] == "123" | ||
| assert log_args["extra"]["subscription_id"] == "123" | ||
| # assert extra["error"] == "Some error about an invalid address" | ||
| # assert extra["error_type"] == "AppropriateExceptionType" | ||
| # save a copy of the original and set it back after this test | ||
| original_side_effect = modify_customer_mock.side_effect | ||
| modify_customer_mock.side_effect = Exception("Invalid billing address") | ||
| self.addCleanup( | ||
| setattr, modify_customer_mock, "side_effect", original_side_effect | ||
| ) | ||
|
|
||
| with self.assertRaises(Exception): | ||
| self.stripe.update_billing_address(owner, "John Doe", "gabagool") | ||
|
|
||
| retrieve_customer_mock.assert_called_once() | ||
| modify_payment_mock.assert_called_once() | ||
| modify_customer_mock.assert_called_once() | ||
|
|
||
| def test_update_billing_address_when_no_customer_id(self): | ||
| owner = OwnerFactory(stripe_customer_id=None) | ||
|
|
@@ -1925,6 +1934,45 @@ def test_update_billing_address( | |
| name="John Doe", | ||
| ) | ||
|
|
||
| @patch("services.billing.stripe.Customer.retrieve") | ||
| @patch("services.billing.stripe.PaymentMethod.modify") | ||
| @patch("services.billing.stripe.Customer.modify") | ||
| def test_update_billing_address_with_error( | ||
| self, modify_customer_mock, modify_payment_mock, retrieve_customer_mock | ||
| ): | ||
| subscription_id = "sub_abc" | ||
| customer_id = "cus_abc" | ||
| owner = OwnerFactory( | ||
| stripe_subscription_id=subscription_id, stripe_customer_id=customer_id | ||
| ) | ||
| billing_address = { | ||
| "line1": "45 Fremont St.", | ||
| "line2": "", | ||
| "city": "San Francisco", | ||
| "state": "CA", | ||
| "country": "US", | ||
| "postal_code": "94105", | ||
| } | ||
| # Set the side effect only for this test, and reset after | ||
| original_side_effect = modify_payment_mock.side_effect | ||
| modify_payment_mock.side_effect = stripe.error.CardError( | ||
| message="Your card was declined.", param="number", code="card_declined" | ||
| ) | ||
| self.addCleanup( | ||
| lambda: setattr(modify_payment_mock, "side_effect", original_side_effect) | ||
| ) | ||
|
|
||
| with self.assertRaises(stripe.error.CardError): | ||
| self.stripe.update_billing_address( | ||
| owner, | ||
| name="John Doe", | ||
| billing_address=billing_address, | ||
| ) | ||
|
|
||
| retrieve_customer_mock.assert_called_once() | ||
| modify_payment_mock.assert_called_once() | ||
| modify_customer_mock.assert_not_called() | ||
|
|
||
| @patch("services.billing.stripe.Invoice.retrieve") | ||
| def test_get_invoice_not_found(self, retrieve_invoice_mock): | ||
| invoice_id = "abc" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.