Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for admin search #113

Merged
merged 2 commits into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions hordak/tests/admin/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,42 @@ def test_account_list(self):
self.assertContains(res, '<td class="field-type_">Income</td>', html=True)
self.assertContains(res, '<td class="field-type_">Asset</td>', html=True)

def test_search_query(self):
"""Test that search query works"""
superuser = get_user_model().objects.create_superuser(username="superuser")
self.client.force_login(superuser)
url = reverse("admin:hordak_account_changelist")
res = self.client.get(url + "?q=Bank")
self.assertContains(
res,
f'<a href="/admin/hordak/account/{self.bank_account.id}/change/'
'?_changelist_filters=q%3DBank">Bank account</a>',
html=True,
)
self.assertContains(res, '<p class="paginator">1 account</p>', html=True)

def test_filter_query(self):
"""Test that filter query works"""
superuser = get_user_model().objects.create_superuser(username="superuser")
self.client.force_login(superuser)
url = reverse("admin:hordak_account_changelist")
res = self.client.get(url + "?type__exact=AS")
self.assertContains(
res,
f'<a href="/admin/hordak/account/{self.bank_account.id}/change/'
'?_changelist_filters=type__exact%3DAS">Bank account</a>',
html=True,
)
self.assertContains(res, '<p class="paginator">1 account</p>', html=True)

def test_filter_query_liability(self):
"""Test that filter query works"""
superuser = get_user_model().objects.create_superuser(username="superuser")
self.client.force_login(superuser)
url = reverse("admin:hordak_account_changelist")
res = self.client.get(url + "?type__exact=LI")
self.assertContains(res, '<p class="paginator">0 accounts</p>', html=True)

def test_account_edit(self):
"""Test account edit page"""
superuser = get_user_model().objects.create_superuser(username="superuser")
Expand Down
Loading