Skip to content

Commit

Permalink
Merge pull request #519 from blueyed/fix-account-search
Browse files Browse the repository at this point in the history
AccountAdmin: fix search_fields
  • Loading branch information
paltman authored Mar 14, 2018
2 parents 8c4f6a6 + 5eda5f0 commit 640bf7b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pinax/stripe/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ class AccountAdmin(ModelAdmin):
search_fields = [
"display_name",
"stripe_id",
],
]


admin.site.register(
Expand Down
25 changes: 24 additions & 1 deletion pinax/stripe/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.contrib.auth import get_user_model
from django.db import connection
from django.test import Client, SimpleTestCase, TestCase
from django.test import Client, RequestFactory, SimpleTestCase, TestCase
from django.test.utils import CaptureQueriesContext
from django.utils import timezone

Expand Down Expand Up @@ -170,6 +170,29 @@ def test_account_filter(self):
response = self.client.get(url + "?stripe_account=none")
self.assertEqual(response.status_code, 200)

@classmethod
def get_changelist(cls, model_class, data=None):
from django.contrib.admin.sites import AdminSite
from django.utils.module_loading import import_string

admin_class = import_string("pinax.stripe.admin.{}Admin".format(
model_class.__name__))

ma = admin_class(model_class, AdminSite())

info = ma.model._meta.app_label, ma.model._meta.model_name
url = reverse("admin:%s_%s_changelist" % info)
request = RequestFactory().get(url, data=data)
request.user = cls.user
return ma.changelist_view(request).context_data["cl"]

def test_account_search(self):
cl = self.get_changelist(Account)
self.assertEqual(list(cl.queryset), [self.account])

cl = self.get_changelist(Account, {"q": "acc_doesnotexist"})
self.assertEqual(list(cl.queryset), [])


class AdminSimpleTestCase(SimpleTestCase):

Expand Down

0 comments on commit 640bf7b

Please sign in to comment.