mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-05-01 12:04:46 +00:00
search_fields test cases
This commit is contained in:
parent
a5d728df66
commit
e199b13c3c
2 changed files with 44 additions and 2 deletions
|
|
@ -35,18 +35,22 @@ class CommentInline(djadmin2.Admin2Inline):
|
|||
|
||||
class PostAdmin(djadmin2.ModelAdmin2):
|
||||
inlines = [CommentInline]
|
||||
search_fields = ('title', 'body')
|
||||
search_fields = ('title', '^body')
|
||||
|
||||
class CommentAdmin(djadmin2.ModelAdmin2):
|
||||
search_fields = ('body', '=post__title')
|
||||
|
||||
|
||||
class UserAdmin2(djadmin2.ModelAdmin2):
|
||||
create_form_class = UserCreationForm
|
||||
update_form_class = UserChangeForm
|
||||
search_fields = ('username', 'groups__name')
|
||||
|
||||
api_serializer_class = UserSerializer
|
||||
|
||||
|
||||
# Register each model with the admin
|
||||
djadmin2.default.register(Post, PostAdmin)
|
||||
djadmin2.default.register(Comment)
|
||||
djadmin2.default.register(Comment, CommentAdmin)
|
||||
djadmin2.default.register(User, UserAdmin2)
|
||||
djadmin2.default.register(Group, GroupAdmin2)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import TestCase, Client
|
||||
|
||||
|
|
@ -23,6 +24,31 @@ class AdminIndexTest(BaseIntegrationTest):
|
|||
response = self.client.get(reverse("admin2:dashboard"))
|
||||
self.assertContains(response, reverse("admin2:blog_post_index"))
|
||||
|
||||
class UserListTest(BaseIntegrationTest):
|
||||
def test_search_users_m2m_group(self):
|
||||
# This test should cause the distinct search path to exectue
|
||||
group = Group.objects.create(name="Test Group")
|
||||
self.user.groups.add(group)
|
||||
|
||||
params = {"q":"group"}
|
||||
response = self.client.get(reverse("admin2:auth_user_index"), params)
|
||||
self.assertContains(response, 'user')
|
||||
|
||||
class CommentListTest(BaseIntegrationTest):
|
||||
def test_search_comments(self):
|
||||
# Test search across Foriegn Keys
|
||||
post_1 = Post.objects.create(title="post_1_title", body="body")
|
||||
post_2 = Post.objects.create(title="post_2_title", body="another body")
|
||||
Comment.objects.create(body="comment_post_1_a", post=post_1)
|
||||
Comment.objects.create(body="comment_post_1_b", post=post_1)
|
||||
Comment.objects.create(body="comment_post_2", post=post_2)
|
||||
|
||||
params = {"q":"post_1_title"}
|
||||
response = self.client.get(reverse("admin2:blog_comment_index"), params)
|
||||
self.assertContains(response, "comment_post_1_a")
|
||||
self.assertContains(response, "comment_post_1_b")
|
||||
self.assertNotContains(response, "comment_post_2")
|
||||
|
||||
|
||||
class PostListTest(BaseIntegrationTest):
|
||||
def test_view_ok(self):
|
||||
|
|
@ -52,6 +78,18 @@ class PostListTest(BaseIntegrationTest):
|
|||
response = self.client.post(reverse("admin2:blog_post_index"), params, follow=True)
|
||||
self.assertContains(response, "Items must be selected in order to perform actions on them. No items have been changed.")
|
||||
|
||||
def test_search_posts(self):
|
||||
Post.objects.create(title="a_post_title", body="body")
|
||||
Post.objects.create(title="another_post_title", body="body")
|
||||
Post.objects.create(title="post_with_keyword_in_body", body="another post body")
|
||||
params = {"q":"another"}
|
||||
response = self.client.get(reverse("admin2:blog_post_index"), params)
|
||||
self.assertContains(response, "another_post_title")
|
||||
self.assertContains(response, "post_with_keyword_in_body")
|
||||
self.assertNotContains(response, "a_post_title")
|
||||
|
||||
|
||||
|
||||
|
||||
class PostDetailViewTest(BaseIntegrationTest):
|
||||
def test_view_ok(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue