-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
18 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import logging | ||
import random | ||
import string | ||
from unittest.mock import patch | ||
from unittest.mock import PropertyMock, patch | ||
|
||
from app import billing as stripe | ||
from app import marketplace_subscriptions, marketplace_users | ||
|
@@ -34,15 +35,28 @@ def test_reconcile_org_user(initialized_db): | |
mock.assert_called_with(org_user.email) | ||
|
||
|
||
def test_exception_handling(initialized_db): | ||
def test_exception_handling(initialized_db, caplog): | ||
with patch("data.billing.FakeStripe.Customer.retrieve") as mock: | ||
mock.side_effect = stripe.error.InvalidRequestException | ||
worker._perform_reconciliation(marketplace_users, marketplace_subscriptions) | ||
with patch("data.billing.FakeStripe.Customer.retrieve") as mock: | ||
mock.side_effect = stripe.error.APIConnectionError | ||
worker._perform_reconciliation(marketplace_users, marketplace_subscriptions) | ||
with patch("data.billing.FakeStripe.Customer.subscription") as mock: | ||
mock.side_effect = AttributeError | ||
|
||
|
||
def test_attribute_error(initialized_db, caplog): | ||
test_user = model.user.create_user("stripe_user", "password", "[email protected]") | ||
test_user.stripe_id = "cus_" + "".join(random.choices(string.ascii_lowercase, k=14)) | ||
test_user.save() | ||
|
||
with patch("data.billing.FakeStripe.Customer.retrieve") as mock: | ||
|
||
class MockCustomer: | ||
@property | ||
def subscription(self): | ||
raise AttributeError | ||
|
||
mock.return_value = MockCustomer() | ||
worker._perform_reconciliation(marketplace_users, marketplace_subscriptions) | ||
|
||
|
||
|