@@ -0,0 +1,2802 @@
+from django.core.urlresolvers import reverse%0Afrom django.test import TestCase, Client%0Afrom reddit.models import RedditUser, Submission, Comment, Vote%0Afrom django.contrib.auth.models import User%0Afrom django.utils.crypto import get_random_string%0A%0A%0Aclass TestViewingThreadComments(TestCase):%0A    def setUp(self):%0A        self.c = Client()%0A        self.credentials = %7B'username':'username',%0A                            'password':'password'%7D%0A        author = RedditUser.objects.create(%0A            user=User.objects.create_user(**self.credentials)%0A        )%0A%0A        submission = Submission.objects.create(%0A            id=1,%0A            score=1,%0A            title=get_random_string(length=12),%0A            author=author%0A        )%0A%0A        for _ in range(3):%0A            Comment.objects.create(%0A                author_name=author.user.username,%0A                author=author,%0A                submission=submission,%0A                html_comment=%22root comment%22%0A            )%0A%0A        # Add some replies%0A        parent = Comment.objects.get(id=1)%0A        for _ in range(2):%0A            Comment.objects.create(%0A                author_name=author.user.username,%0A                author=author,%0A                submission=submission,%0A                parent=parent,%0A                html_comment=%22reply comment%22%0A            )%0A%0A        # add upvote to one root comment,%0A        Vote.create(%0A            user=author,%0A            vote_object=Comment.objects.get(id=1),%0A            vote_value=1%0A        ).save()%0A%0A        # and downvote to one reply comment%0A        Vote.create(%0A            user=author,%0A            vote_object=Comment.objects.get(id=5),%0A            vote_value=-1%0A        ).save()%0A%0A        # add upvote to the submission%0A        Vote.create(%0A            user=author,%0A            vote_object=submission,%0A            vote_value=1%0A        ).save()%0A%0A    def test_valid_public_comment_view(self):%0A        self.c.logout()%0A        r = self.c.get(reverse('Thread', args=(1,)))%0A        submission = Submission.objects.get(id=1)%0A        self.assertEqual(r.status_code, 200)%0A        self.assertEqual(r.context%5B'submission'%5D, submission)%0A        self.assertEqual(len(r.context%5B'comments'%5D), 5)%0A        self.assertContains(r, 'root comment', count=3)%0A        self.assertContains(r, 'reply comment', count=2)%0A        self.assertEqual(r.context%5B'comment_votes'%5D, %7B%7D)%0A        self.assertIsNone(r.context%5B'sub_vote'%5D)%0A%0A    def test_comment_votes(self):%0A        self.c.login(**self.credentials)%0A        r = self.c.get(reverse('Thread', args=(1,)))%0A        self.assertEqual(r.status_code, 200)%0A        self.assertEqual(r.context%5B'sub_vote'%5D, 1)%0A        self.assertEqual(r.context%5B'comment_votes'%5D, %7B1:1, 5:-1%7D)%0A        self.assertContains(r, 'root comment', count=3)%0A        self.assertContains(r, 'reply comment', count=2)

Add comment viewing tests