Skip to content

Commit

Permalink
Use black's preview format
Browse files Browse the repository at this point in the history
  • Loading branch information
jleclanche committed Apr 22, 2023
1 parent 34bfbad commit a7400cf
Show file tree
Hide file tree
Showing 43 changed files with 2,183 additions and 779 deletions.
8 changes: 4 additions & 4 deletions djstripe/admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def __init__(self, *args, **kwargs):
label="Enabled Events",
required=True,
help_text=(
"The list of events to enable for this endpoint. "
"['*'] indicates that all events are enabled, except those that require explicit selection."
"The list of events to enable for this endpoint. ['*'] indicates that all"
" events are enabled, except those that require explicit selection."
),
choices=zip(ENABLED_EVENTS, ENABLED_EVENTS),
initial=["*"],
Expand Down Expand Up @@ -204,8 +204,8 @@ class WebhookEndpointAdminEditForm(WebhookEndpointAdminBaseForm):
label="Enabled Events",
required=True,
help_text=(
"The list of events to enable for this endpoint. "
"['*'] indicates that all events are enabled, except those that require explicit selection."
"The list of events to enable for this endpoint. ['*'] indicates that all"
" events are enabled, except those that require explicit selection."
),
choices=zip(ENABLED_EVENTS, ENABLED_EVENTS),
)
Expand Down
66 changes: 50 additions & 16 deletions djstripe/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,42 @@ def _check_stripe_api_in_settings(messages):
api_qs = APIKey.objects.all()

if not api_qs.exists():
msg = "You don't have any API Keys in the database. Did you forget to add them?"
hint = "Add STRIPE_TEST_SECRET_KEY and STRIPE_LIVE_SECRET_KEY directly from the Django Admin."
msg = (
"You don't have any API Keys in the database. Did you forget to add"
" them?"
)
hint = (
"Add STRIPE_TEST_SECRET_KEY and STRIPE_LIVE_SECRET_KEY directly from"
" the Django Admin."
)
messages.append(checks.Info(msg, hint=hint, id="djstripe.I001"))

# Keys not in admin but in settings
if djstripe_settings.STRIPE_SECRET_KEY:
msg = "Your keys are defined in the settings files. You can now add and manage them directly from the django admin."
hint = "Add STRIPE_TEST_SECRET_KEY and STRIPE_LIVE_SECRET_KEY directly from the Django Admin."
msg = (
"Your keys are defined in the settings files. You can now add and"
" manage them directly from the django admin."
)
hint = (
"Add STRIPE_TEST_SECRET_KEY and STRIPE_LIVE_SECRET_KEY directly"
" from the Django Admin."
)
messages.append(checks.Info(msg, hint=hint, id="djstripe.I002"))

# Ensure keys defined in settings files are valid
_check_stripe_api_in_settings(messages)

# Keys in admin and in settings
elif djstripe_settings.STRIPE_SECRET_KEY:
msg = "Your keys are defined in the settings files and are also in the admin. You can now add and manage them directly from the django admin."
hint = "We suggest adding STRIPE_TEST_SECRET_KEY and STRIPE_LIVE_SECRET_KEY directly from the Django Admin. And removing them from the settings files."
msg = (
"Your keys are defined in the settings files and are also in the admin."
" You can now add and manage them directly from the django admin."
)
hint = (
"We suggest adding STRIPE_TEST_SECRET_KEY and STRIPE_LIVE_SECRET_KEY"
" directly from the Django Admin. And removing them from the settings"
" files."
)
messages.append(checks.Info(msg, hint=hint, id="djstripe.I002"))

# Ensure keys defined in settings files are valid
Expand Down Expand Up @@ -124,8 +143,10 @@ def check_stripe_api_host(app_configs=None, **kwargs):
if not settings.DEBUG and hasattr(settings, "STRIPE_API_HOST"):
messages.append(
checks.Warning(
"STRIPE_API_HOST should not be set in production! "
"This is most likely unintended.",
(
"STRIPE_API_HOST should not be set in production! "
"This is most likely unintended."
),
hint="Remove STRIPE_API_HOST from your Django settings.",
id="djstripe.W002",
)
Expand Down Expand Up @@ -193,7 +214,10 @@ def _check_webhook_endpoint_validation(secret, messages, endpoint=None):
messages.append(
checks.Info(
f"DJSTRIPE_WEBHOOK_VALIDATION is set to 'verify_signature' {extra_msg}",
hint=f"Set {secret_attr} from Django shell or set DJSTRIPE_WEBHOOK_VALIDATION='retrieve_event'",
hint=(
f"Set {secret_attr} from Django shell or set"
" DJSTRIPE_WEBHOOK_VALIDATION='retrieve_event'"
),
id="djstripe.I006",
)
)
Expand All @@ -217,8 +241,10 @@ def check_webhook_validation(app_configs=None, **kwargs):
if djstripe_settings.WEBHOOK_VALIDATION is None:
messages.append(
checks.Warning(
"Webhook validation is disabled, this is a security risk if the "
"webhook view is enabled",
(
"Webhook validation is disabled, this is a security risk if the "
"webhook view is enabled"
),
hint=f"Set {setting_name} to one of: {validation_options}",
id="djstripe.W004",
)
Expand Down Expand Up @@ -302,8 +328,10 @@ def check_subscriber_key_length(app_configs=None, **kwargs):
if key and len(key) > key_max_length:
messages.append(
checks.Error(
"DJSTRIPE_SUBSCRIBER_CUSTOMER_KEY must be no more than "
f"{key_max_length} characters long",
(
"DJSTRIPE_SUBSCRIBER_CUSTOMER_KEY must be no more than "
f"{key_max_length} characters long"
),
hint=f"Current value: {key!r}",
id="djstripe.E001",
)
Expand All @@ -322,7 +350,7 @@ def check_djstripe_settings_foreign_key_to_field(app_configs=None, **kwargs):
setting_name = "DJSTRIPE_FOREIGN_KEY_TO_FIELD"
hint = (
f'Set {setting_name} to "id" if this is a new installation, '
f'otherwise set it to "djstripe_id".'
'otherwise set it to "djstripe_id".'
)
messages = []

Expand Down Expand Up @@ -366,7 +394,10 @@ def check_webhook_event_callback_accepts_api_key(app_configs=None, **kwargs):
# Deprecated in 2.8.0. Raise a warning.
messages.append(
checks.Warning(
"DJSTRIPE_WEBHOOK_EVENT_CALLBACK is deprecated. See release notes for details.",
(
"DJSTRIPE_WEBHOOK_EVENT_CALLBACK is deprecated. See release notes"
" for details."
),
hint=(
"If you need to trigger a function during webhook processing, "
"you can use djstripe.signals instead.\n"
Expand All @@ -387,7 +418,10 @@ def check_webhook_event_callback_accepts_api_key(app_configs=None, **kwargs):
messages.append(
checks.Error(
f"{callable} accepts {signature_sz} arguments.",
hint="You may have forgotten to add api_key parameter to your custom callback.",
hint=(
"You may have forgotten to add api_key parameter to your custom"
" callback."
),
id="djstripe.E004",
)
)
Expand Down
6 changes: 4 additions & 2 deletions djstripe/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,12 @@ class PayoutFailureCode(Enum):
"Your bank notified us that the bank account holder name on file is incorrect."
)
incorrect_account_holder_address = _(
"Your bank notified us that the bank account holder address on file is incorrect."
"Your bank notified us that the bank account holder address on file is"
" incorrect."
)
incorrect_account_holder_tax_id = _(
"Your bank notified us that the bank account holder tax ID on file is incorrect."
"Your bank notified us that the bank account holder tax ID on file is"
" incorrect."
)
invalid_currency = _("Bank account does not support currency.")
no_account = _("Bank account could not be located.")
Expand Down
20 changes: 14 additions & 6 deletions djstripe/management/commands/djstripe_sync_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ def add_arguments(self, parser):
"args",
metavar="ModelName",
nargs="*",
help="restricts sync to these model names (default is to sync all "
"supported models)",
help=(
"restricts sync to these model names (default is to sync all "
"supported models)"
),
)
# Named (optional) arguments
parser.add_argument(
Expand Down Expand Up @@ -93,7 +95,8 @@ def handle(self, *args, api_keys: typing.List[str], **options):

if not api_qs.exists():
self.stderr.write(
"You don't have any API Keys in the database. Did you forget to add them?"
"You don't have any API Keys in the database. Did you forget to add"
" them?"
)
return

Expand Down Expand Up @@ -161,7 +164,9 @@ def sync_model(self, model, api_key: str):
stripe_obj, api_key=api_key.secret
)
self.stdout.write(
f" id={djstripe_obj.id}, pk={djstripe_obj.pk} ({djstripe_obj} on {stripe_account} for {api_key})"
f" id={djstripe_obj.id},"
f" pk={djstripe_obj.pk} ({djstripe_obj} on {stripe_account} for"
f" {api_key})"
)

# syncing BankAccount and Card objects of Stripe Connected Express and Custom Accounts
Expand All @@ -180,7 +185,9 @@ def sync_model(self, model, api_key: str):
stripe_obj, api_key=api_key.secret
)
self.stdout.write(
f" id={djstripe_obj.id}, pk={djstripe_obj.pk} ({djstripe_obj} on {stripe_account} for {api_key})"
f" id={djstripe_obj.id},"
f" pk={djstripe_obj.pk} ({djstripe_obj} on"
f" {stripe_account} for {api_key})"
)
# syncing BankAccount and Card objects of Stripe Connected Express and Custom Accounts
self.sync_bank_accounts_and_cards(
Expand Down Expand Up @@ -568,7 +575,8 @@ def start_sync(self, items, instance, api_key: str):
item_obj = model.sync_from_stripe_data(item, api_key=api_key)

self.stdout.write(
f"\tSyncing {model._meta.verbose_name} ({instance}): id={item_obj.id}, pk={item_obj.pk}"
f"\tSyncing {model._meta.verbose_name} ({instance}): id={item_obj.id},"
f" pk={item_obj.pk}"
)

if bank_count + card_count > 0:
Expand Down
Loading

0 comments on commit a7400cf

Please sign in to comment.