예제 #1
0
파일: tests.py 프로젝트: magatz/pybbm-1
    def test_topic_move_form_with_new_forum(self):
        forum = Forum.objects.create(name='temporary forum')

        topic = Topic.objects.create(name='move_topic', forum=forum, user=self.superuser)

        post = Post(topic=topic, user=self.superuser, body='move post')
        post.save()

        name = 'new name for temporary topic'

        form = TopicMoveForm(topic=topic, data={
            'name': name,
            'forum': self.forum.pk,
            'redirection_type': TopicRedirection.TYPE_PERMANENT_REDIRECT
        })

        self.assertTrue(form.is_valid())

        new_topic = form.save()

        topic = Topic.objects.get(pk=topic.pk)

        self.assertTrue(topic.redirect)

        self.failUnless(new_topic.slug is not None)
        self.assertEqual(new_topic.redirections.count(), 1)
        self.assertEqual(Post.objects.get(pk=post.pk).topic, new_topic)
        self.assertEqual(topic.posts.count(), 0)
예제 #2
0
    def test_topic_move_form_with_new_forum(self):
        forum = Forum.objects.create(name='temporary forum')

        topic = Topic.objects.create(name='move_topic',
                                     forum=forum,
                                     user=self.superuser)

        post = Post(topic=topic, user=self.superuser, body='move post')
        post.save()

        name = 'new name for temporary topic'

        form = TopicMoveForm(topic=topic,
                             data={
                                 'name':
                                 name,
                                 'forum':
                                 self.forum.pk,
                                 'redirection_type':
                                 TopicRedirection.TYPE_PERMANENT_REDIRECT
                             })

        self.assertTrue(form.is_valid())

        new_topic = form.save()

        topic = Topic.objects.get(pk=topic.pk)

        self.assertTrue(topic.redirect)

        self.assertTrue(new_topic.slug is not None)
        self.assertEqual(new_topic.redirections.count(), 1)
        self.assertEqual(Post.objects.get(pk=post.pk).topic, new_topic)
        self.assertEqual(topic.posts.count(), 0)
예제 #3
0
    def test_topic_move_form_errors(self):
        forum = Forum.objects.create(name='temporary forum')

        topic = Topic.objects.create(name='move_topic',
                                     forum=forum,
                                     user=self.superuser)

        post = Post(topic=topic, user=self.superuser, body='move post')
        post.save()

        form = TopicMoveForm(topic=topic,
                             data={
                                 'name':
                                 topic.name,
                                 'forum':
                                 forum.pk,
                                 'redirection_type':
                                 TopicRedirection.TYPE_PERMANENT_REDIRECT
                             })

        self.assertFalse(form.is_valid())
        self.assertIn('name', form.errors)

        Topic.objects.create(name='move_topic',
                             forum=self.forum,
                             user=self.superuser)

        form = TopicMoveForm(topic=topic,
                             data={
                                 'forum':
                                 self.forum.pk,
                                 'redirection_type':
                                 TopicRedirection.TYPE_PERMANENT_REDIRECT
                             })

        self.assertFalse(form.is_valid())
        self.assertIn('name', form.errors)

        form = TopicMoveForm(topic=topic,
                             data={
                                 'forum':
                                 self.forum.pk,
                                 'redirection_type':
                                 TopicRedirection.TYPE_EXPIRING_REDIRECT
                             })

        self.assertFalse(form.is_valid())
        self.assertIn('expired', form.errors)
예제 #4
0
파일: tests.py 프로젝트: magatz/pybbm-1
    def test_topic_move_form_errors(self):
        forum = Forum.objects.create(name='temporary forum')

        topic = Topic.objects.create(name='move_topic', forum=forum, user=self.superuser)

        post = Post(topic=topic, user=self.superuser, body='move post')
        post.save()

        form = TopicMoveForm(topic=topic, data={
            'name': topic.name,
            'forum': forum.pk,
            'redirection_type': TopicRedirection.TYPE_PERMANENT_REDIRECT
        })

        self.assertFalse(form.is_valid())
        self.assertIn('name', form.errors)

        Topic.objects.create(name='move_topic', forum=self.forum, user=self.superuser)

        form = TopicMoveForm(topic=topic, data={
            'forum': self.forum.pk,
            'redirection_type': TopicRedirection.TYPE_PERMANENT_REDIRECT
        })

        self.assertFalse(form.is_valid())
        self.assertIn('name', form.errors)

        form = TopicMoveForm(topic=topic, data={
            'forum': self.forum.pk,
            'redirection_type': TopicRedirection.TYPE_EXPIRING_REDIRECT
        })

        self.assertFalse(form.is_valid())
        self.assertIn('expired', form.errors)