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 from ..models import Post, Comment class BaseIntegrationTest(TestCase): """ Base TestCase for integration tests. """ def setUp(self): self.client = Client() self.user = get_user_model()(username='user', is_staff=True, is_superuser=True) self.user.set_password("password") self.user.save() self.client.login(username='user', password='password') class AdminIndexTest(BaseIntegrationTest): def test_view_ok(self): 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): post = Post.objects.create(title="A Post Title", body="body") response = self.client.get(reverse("admin2:blog_post_index")) self.assertContains(response, post.title) def test_list_filter_presence(self): Post.objects.create(title="post_1_title", body="body") Post.objects.create(title="post_2_title", body="another body") response = self.client.get(reverse("admin2:blog_post_index")) self.assertContains(response, 'id="list_filter_container"') def test_actions_displayed(self): response = self.client.get(reverse("admin2:blog_post_index")) self.assertInHTML('Delete selected items', response.content) def test_actions_displayed_twice(self): # If actions_on_top and actions_on_bottom are both set response = self.client.get(reverse("admin2:blog_comment_index")) self.assertContains(response, '