Skip to content

Commit

Permalink
Fix Account __str__ (dj-stripe#1033)
Browse files Browse the repository at this point in the history
Also added test, and fixed Account admin search.
  • Loading branch information
therefromhere authored Oct 14, 2019
1 parent ec16ef7 commit fcf49ed
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion djstripe/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class InvoiceItemInline(admin.StackedInline):
class AccountAdmin(StripeModelAdmin):
list_display = ("business_url", "country", "default_currency")
list_filter = ("details_submitted",)
search_fields = ("business_name", "display_name", "business_url")
search_fields = ("settings", "business_profile")
raw_id_fields = ("branding_icon",)


Expand Down
6 changes: 5 additions & 1 deletion djstripe/models/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ def get_default_account(cls):
return cls._get_or_create_from_stripe_object(account_data)[0]

def __str__(self):
return self.display_name or self.business_name
return (
self.settings.get("dashboard", {}).get("display_name")
or self.business_profile.get("name")
or super().__str__()
)

@classmethod # noqa: C901
def _manipulate_stripe_object_hook(cls, data):
Expand Down
32 changes: 32 additions & 0 deletions tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,38 @@ def test_get_default_account_null_logo(
)


@pytest.mark.django_db
@pytest.mark.parametrize(
("business_profile_update", "settings_dashboard_update", "expected_account_str"),
(
({}, {}, "dj-stripe"),
({}, {"display_name": "some display name"}, "some display name"),
({"name": "some business name"}, {"display_name": ""}, "some business name"),
({"name": ""}, {"display_name": ""}, "<id=acct_1032D82eZvKYlo2C>"),
),
)
@patch("stripe.Account.retrieve", autospec=IS_STATICMETHOD_AUTOSPEC_SUPPORTED)
@patch(
"stripe.FileUpload.retrieve",
return_value=deepcopy(FAKE_FILEUPLOAD_LOGO),
autospec=True,
)
def test_account_str(
fileupload_retrieve_mock,
account_retrieve_mock,
business_profile_update,
settings_dashboard_update,
expected_account_str,
):
fake_account = deepcopy(FAKE_ACCOUNT)
fake_account["business_profile"].update(business_profile_update)
fake_account["settings"]["dashboard"].update(settings_dashboard_update)
account_retrieve_mock.return_value = fake_account
account = Account.get_default_account()

assert str(account) == expected_account_str


@pytest.mark.parametrize(
"mock_account_id, other_mock_account_id, expected_stripe_account",
(
Expand Down

0 comments on commit fcf49ed

Please sign in to comment.