def setUp(self): admin = AdminSite() self.ma = PostAdmin(Post, admin) for author in User.objects.all(): title = "%s's title" % author.username post = Post(title=title, author=author) post.save() self.client.login(username='******', password='******')
class PostAdminTestCase(TestCase): fixtures = ['myblog_test_fixture.json', ] def setUp(self): admin = AdminSite() self.ma = PostAdmin(Post, admin) for author in User.objects.all(): title = "%s's title" % author.username post = Post(title=title, author=author) post.save() self.client.login(username='******', password='******') def test_author_link(self): expected_link_path = '/admin/auth/user/%s' for post in Post.objects.all(): expected = expected_link_path % post.author.pk actual = self.ma.author_link(post) self.assertTrue(expected in actual)