-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: #328 sign-up-returns-validation-error-on-fresh-installation-with…
…out-env-variables
- Loading branch information
1 parent
6a74062
commit 7405734
Showing
10 changed files
with
88 additions
and
1 deletion.
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
Empty file.
Empty file.
20 changes: 20 additions & 0 deletions
20
packages/backend/apps/users/management/commands/init_customers_plans.py
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from apps.finances.services import subscriptions | ||
from django.core.management.base import BaseCommand | ||
|
||
from config import settings | ||
from ...models import User | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Creates stripe customer and schedule subscription plan' | ||
|
||
def handle(self, *args, **options): | ||
if not settings.STRIPE_LIVE_MODE and not settings.STRIPE_TEST_SECRET_KEY: | ||
return | ||
|
||
if settings.STRIPE_LIVE_MODE and not settings.STRIPE_LIVE_SECRET_KEY: | ||
return | ||
|
||
users = User.objects.filter(djstripe_customers__isnull=True, is_superuser=False) | ||
for user in users: | ||
subscriptions.initialize_user(user=user) |
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
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
import factory | ||
from django.db.models import signals | ||
|
||
from apps.users.management.commands.init_customers_plans import Command | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
class TestUserPostSaveSignal: | ||
@factory.django.mute_signals(signals.post_save) | ||
def test_command_run_for_users_without_customer(self, stripe_customer_factory, user_factory, mocker): | ||
mock = mocker.patch("apps.finances.services.subscriptions.initialize_user") | ||
user = user_factory.create() | ||
stripe_customer_factory.create() | ||
|
||
Command().handle() | ||
|
||
mock.assert_called_once_with(user=user) | ||
|
||
@factory.django.mute_signals(signals.post_save) | ||
def test_command_do_not_run_for_superusers(self, user_factory, mocker): | ||
mock = mocker.patch("apps.finances.services.subscriptions.initialize_user") | ||
user_factory.create(is_superuser=True) | ||
|
||
Command().handle() | ||
|
||
mock.assert_not_called() |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pytest | ||
from stripe.error import AuthenticationError | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
class TestUserPostSaveSignal: | ||
def test_signal_is_not_raising_exception_on_auth_error(self, user_factory, mocker): | ||
mock = mocker.patch("apps.finances.services.subscriptions.initialize_user", side_effect=AuthenticationError()) | ||
|
||
user_factory.create() | ||
|
||
mock.assert_called_once() | ||
|
||
def test_reraise_stripe_error(self, user_factory, totp_mock, mocker): | ||
initial_error = Exception | ||
mocker.patch("apps.finances.services.subscriptions.initialize_user", side_effect=initial_error()) | ||
|
||
with pytest.raises(initial_error) as error: | ||
user_factory.create() | ||
|
||
assert initial_error == error.type |
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
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