Beispiel #1
0
    def test_read_tracking_multi_forum(self):
        self.post

        topic_1 = self.topic
        topic_2 = Topic(name='topic_2', forum=self.forum, user=self.user)
        topic_2.save()

        Post(topic=topic_2, user=self.user, body='one').save()

        forum_2 = Forum(name='forum_2', description='bar', forum=self.parent_forum)
        forum_2.save()

        Topic(name='garbage', forum=forum_2, user=self.user).save()

        self.login_as(self.user)

        #  everything starts unread
        self.assertEqual(ForumReadTracker.objects.count(), 0)
        self.assertEqual(TopicReadTracker.objects.count(), 0)

        #  user reads topic_1, they should get one topic read tracker, there should be no forum read trackers
        self.client.get(topic_1.get_absolute_url())
        self.assertEqual(TopicReadTracker.objects.count(), 1)
        self.assertEqual(TopicReadTracker.objects.filter(user=self.user).count(), 1)
        self.assertEqual(TopicReadTracker.objects.filter(user=self.user, topic=topic_1).count(), 1)

        #  user reads topic_2, they should get a forum read tracker,
        #  there should be no topic read trackers for the user
        self.client.get(topic_2.get_absolute_url())
        self.assertEqual(TopicReadTracker.objects.count(), 0)
        self.assertEqual(ForumReadTracker.objects.count(), 1)
        self.assertEqual(ForumReadTracker.objects.filter(user=self.user).count(), 1)
        self.assertEqual(ForumReadTracker.objects.filter(user=self.user, forum=self.forum).count(), 1)
Beispiel #2
0
 def create(cls, title, user):
     print("Claim:create")
     my_forum = Forum(name = title, category = claim_category())
     my_forum.save()
     my_claim = cls(title = title,
                    forum = my_forum,
                    user = user
                    )
     return my_claim
Beispiel #3
0
    def test_staff(self):
        client = Client()
        parent = Forum(name='hcat', staff=True)
        parent.save()

        forum_in_staff = Forum(name='in_staff', forum=parent)
        forum_in_staff.save()

        topic_in_staff = Topic(forum=forum_in_staff, name='in_staff', user=self.user)
        topic_in_staff.save()

        forum_staff = Forum(name='staff', forum=self.parent_forum, staff=True)
        forum_staff.save()

        topic_staff = Topic(forum=forum_staff, name='staff', user=self.user)
        topic_staff.save()

        post_staff = Post(topic=topic_staff, user=self.user, body='staff')
        post_staff.save()

        post_in_staff = Post(topic=topic_in_staff, user=self.user, body='staff')
        post_in_staff.save()

        self.assertFalse(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])
        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(forum_in_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(topic_in_staff.get_absolute_url()).status_code, 404)

        self.assertEqual(client.get(forum_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(topic_staff.get_absolute_url()).status_code, 404)

        client.login(username='******', password='******')

        self.assertFalse(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])

        self.assertNotContains(client.get(reverse('pybb:index')), forum_staff.get_absolute_url())

        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(forum_in_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(topic_in_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(forum_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(topic_staff.get_absolute_url()).status_code, 404)

        self.user.is_staff = True
        self.user.save()

        self.assertTrue(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])

        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_in_staff.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_in_staff.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_staff.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_staff.get_absolute_url()).status_code, 200)
Beispiel #4
0
    def test_hidden(self):
        client = Client()
        parent = Forum(name='hcat', hidden=True)
        parent.save()

        forum_in_hidden = Forum(name='in_hidden', forum=parent)
        forum_in_hidden.save()

        topic_in_hidden = Topic(forum=forum_in_hidden, name='in_hidden', user=self.user)
        topic_in_hidden.save()

        forum_hidden = Forum(name='hidden', forum=self.parent_forum, hidden=True)
        forum_hidden.save()

        topic_hidden = Topic(forum=forum_hidden, name='hidden', user=self.user)
        topic_hidden.save()

        post_hidden = Post(topic=topic_hidden, user=self.user, body='hidden')
        post_hidden.save()

        post_in_hidden = Post(topic=topic_in_hidden, user=self.user, body='hidden')
        post_in_hidden.save()

        self.assertFalse(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])
        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 302)
        self.assertEqual(client.get(forum_in_hidden.get_absolute_url()).status_code, 302)
        self.assertEqual(client.get(topic_in_hidden.get_absolute_url()).status_code, 302)

        self.assertNotContains(client.get(reverse('pybb:index')), forum_hidden.get_absolute_url())
        self.assertNotContains(client.get(reverse('pybb:feed_topics')), topic_hidden.get_absolute_url())
        self.assertNotContains(client.get(reverse('pybb:feed_topics')), topic_in_hidden.get_absolute_url())

        self.assertNotContains(client.get(reverse('pybb:feed_posts')), post_hidden.get_absolute_url())
        self.assertNotContains(client.get(reverse('pybb:feed_posts')), post_in_hidden.get_absolute_url())
        self.assertEqual(client.get(forum_hidden.get_absolute_url()).status_code, 302)
        self.assertEqual(client.get(topic_hidden.get_absolute_url()).status_code, 302)

        client.login(username='******', password='******')

        self.assertTrue(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])

        self.assertContains(client.get(reverse('pybb:index')), forum_hidden.get_absolute_url())

        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_hidden.get_absolute_url()).status_code, 200)
        self.user.is_staff = True
        self.user.save()
        self.assertTrue(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])
        self.assertContains(client.get(reverse('pybb:index')), forum_hidden.get_absolute_url())

        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_hidden.get_absolute_url()).status_code, 200)
Beispiel #5
0
    def test_staff(self):
        client = Client()
        parent = Forum(name='hcat', staff=True)
        parent.save()

        forum_in_staff = Forum(name='in_staff', forum=parent)
        forum_in_staff.save()

        topic_in_staff = Topic(forum=forum_in_staff,
                               name='in_staff',
                               user=self.user)
        topic_in_staff.save()

        forum_staff = Forum(name='staff', forum=self.parent_forum, staff=True)
        forum_staff.save()

        topic_staff = Topic(forum=forum_staff, name='staff', user=self.user)
        topic_staff.save()

        post_staff = Post(topic=topic_staff, user=self.user, body='staff')
        post_staff.save()

        post_in_staff = Post(topic=topic_in_staff,
                             user=self.user,
                             body='staff')
        post_in_staff.save()

        self.assertFalse(parent.id in [
            c.id for c in client.get(reverse('pybb:index')).context['forums']
        ])
        self.assertEqual(
            client.get(parent.get_absolute_url()).status_code, 404)
        self.assertEqual(
            client.get(forum_in_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(
            client.get(topic_in_staff.get_absolute_url()).status_code, 404)

        self.assertEqual(
            client.get(forum_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(
            client.get(topic_staff.get_absolute_url()).status_code, 404)

        client.login(username='******', password='******')

        self.assertFalse(parent.id in [
            c.id for c in client.get(reverse('pybb:index')).context['forums']
        ])

        self.assertNotContains(client.get(reverse('pybb:index')),
                               forum_staff.get_absolute_url())

        self.assertEqual(
            client.get(parent.get_absolute_url()).status_code, 404)
        self.assertEqual(
            client.get(forum_in_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(
            client.get(topic_in_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(
            client.get(forum_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(
            client.get(topic_staff.get_absolute_url()).status_code, 404)

        self.user.is_staff = True
        self.user.save()

        self.assertTrue(parent.id in [
            c.id for c in client.get(reverse('pybb:index')).context['forums']
        ])

        self.assertEqual(
            client.get(parent.get_absolute_url()).status_code, 200)
        self.assertEqual(
            client.get(forum_in_staff.get_absolute_url()).status_code, 200)
        self.assertEqual(
            client.get(topic_in_staff.get_absolute_url()).status_code, 200)
        self.assertEqual(
            client.get(forum_staff.get_absolute_url()).status_code, 200)
        self.assertEqual(
            client.get(topic_staff.get_absolute_url()).status_code, 200)
Beispiel #6
0
    def test_hidden(self):
        client = Client()
        parent = Forum(name='hcat', hidden=True)
        parent.save()

        forum_in_hidden = Forum(name='in_hidden', forum=parent)
        forum_in_hidden.save()

        topic_in_hidden = Topic(forum=forum_in_hidden,
                                name='in_hidden',
                                user=self.user)
        topic_in_hidden.save()

        forum_hidden = Forum(name='hidden',
                             forum=self.parent_forum,
                             hidden=True)
        forum_hidden.save()

        topic_hidden = Topic(forum=forum_hidden, name='hidden', user=self.user)
        topic_hidden.save()

        post_hidden = Post(topic=topic_hidden, user=self.user, body='hidden')
        post_hidden.save()

        post_in_hidden = Post(topic=topic_in_hidden,
                              user=self.user,
                              body='hidden')
        post_in_hidden.save()

        self.assertFalse(parent.id in [
            c.id for c in client.get(reverse('pybb:index')).context['forums']
        ])
        self.assertEqual(
            client.get(parent.get_absolute_url()).status_code, 302)
        self.assertEqual(
            client.get(forum_in_hidden.get_absolute_url()).status_code, 302)
        self.assertEqual(
            client.get(topic_in_hidden.get_absolute_url()).status_code, 302)

        self.assertNotContains(client.get(reverse('pybb:index')),
                               forum_hidden.get_absolute_url())
        self.assertNotContains(client.get(reverse('pybb:feed_topics')),
                               topic_hidden.get_absolute_url())
        self.assertNotContains(client.get(reverse('pybb:feed_topics')),
                               topic_in_hidden.get_absolute_url())

        self.assertNotContains(client.get(reverse('pybb:feed_posts')),
                               post_hidden.get_absolute_url())
        self.assertNotContains(client.get(reverse('pybb:feed_posts')),
                               post_in_hidden.get_absolute_url())
        self.assertEqual(
            client.get(forum_hidden.get_absolute_url()).status_code, 302)
        self.assertEqual(
            client.get(topic_hidden.get_absolute_url()).status_code, 302)

        client.login(username='******', password='******')

        self.assertTrue(parent.id in [
            c.id for c in client.get(reverse('pybb:index')).context['forums']
        ])

        self.assertContains(client.get(reverse('pybb:index')),
                            forum_hidden.get_absolute_url())

        self.assertEqual(
            client.get(parent.get_absolute_url()).status_code, 200)
        self.assertEqual(
            client.get(forum_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(
            client.get(topic_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(
            client.get(forum_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(
            client.get(topic_hidden.get_absolute_url()).status_code, 200)
        self.user.is_staff = True
        self.user.save()
        self.assertTrue(parent.id in [
            c.id for c in client.get(reverse('pybb:index')).context['forums']
        ])
        self.assertContains(client.get(reverse('pybb:index')),
                            forum_hidden.get_absolute_url())

        self.assertEqual(
            client.get(parent.get_absolute_url()).status_code, 200)
        self.assertEqual(
            client.get(forum_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(
            client.get(topic_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(
            client.get(forum_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(
            client.get(topic_hidden.get_absolute_url()).status_code, 200)