Exemple #1
0
    def test_all_forums(self):
        """all_forums returns queryset with forums tree"""
        root = Forum.objects.root_category()

        test_forum_a = Forum(name='Test', role='category')
        test_forum_a.insert_at(root, position='last-child', save=True)

        test_forum_b = Forum(name='Test 2', role='category')
        test_forum_b.insert_at(root, position='last-child', save=True)

        all_forums_from_db = [f for f in Forum.objects.all_forums(True)]

        self.assertIn(test_forum_a, all_forums_from_db)
        self.assertIn(test_forum_b, all_forums_from_db)
Exemple #2
0
    def test_move_thread(self):
        """its possible to move thread"""
        self.override_acl({'can_move_threads': 0})
        response = self.client.post(self.thread.get_absolute_url(),
                                    data={'thread_action': 'move'})
        self.assertEqual(response.status_code, 200)

        self.override_acl({'can_move_threads': 1})
        response = self.client.post(self.thread.get_absolute_url(),
                                    data={'thread_action': 'move'})
        self.assertEqual(response.status_code, 200)
        self.assertIn("Move thread to forum:", response.content)

        new_forum = Forum(name="New Forum", slug="new-forum", role="forum")
        new_forum.insert_at(self.forum.parent, save=True)

        self.override_acl({'can_move_threads': 1})
        self.override_acl({'can_move_threads': 1}, new_forum)
        response = self.client.post(self.thread.get_absolute_url(),
                                    data={
                                        'thread_action': 'move',
                                        'new_forum': unicode(new_forum.id),
                                        'submit': '1'
                                    })
        self.assertEqual(response.status_code, 302)
        self.assertEqual(self.reload_thread().forum, new_forum)

        # we made forum "empty", assert that board index renders
        response = self.client.get(reverse('misago:index'))
        self.assertEqual(response.status_code, 200)
    def setUp(self):
        super(CategoryViewsTests, self).setUp()
        categories_qs = Forum.objects.all_forums().filter(role='category')
        master_category = categories_qs[:1][0]

        self.category = Forum(role='category',
                              name='Test category',
                              slug='test-category')
        self.category.insert_at(master_category, save=True)
Exemple #4
0
    def test_move_threads(self):
        """moderation allows for moving threads"""
        new_forum = Forum(name="New Forum", slug="new-forum", role="forum")
        new_forum.insert_at(self.forum, save=True)

        test_acl = {
            'can_see': 1,
            'can_browse': 1,
            'can_see_all_threads': 1,
            'can_move_threads': 1
        }

        self.override_acl(test_acl)
        response = self.client.get(self.link)
        self.assertEqual(response.status_code, 200)
        self.assertIn("Move threads", response.content)

        threads = [testutils.post_thread(self.forum) for t in xrange(10)]

        # see move threads form
        self.override_acl(test_acl)
        response = self.client.post(self.link,
                                    data={
                                        'action': 'move',
                                        'thread': [t.pk for t in threads[:5]]
                                    })
        self.assertEqual(response.status_code, 200)

        for thread in threads[:5]:
            self.assertIn(thread.title, response.content)

        # submit form with non-existing forum
        self.override_acl(test_acl)
        response = self.client.post(self.link,
                                    data={
                                        'action': 'move',
                                        'thread': [t.pk for t in threads[:5]],
                                        'submit': '',
                                        'new_forum': new_forum.pk + 1234
                                    })
        self.assertEqual(response.status_code, 200)
        self.assertIn("Select valid forum.", response.content)

        # attempt move to category
        self.override_acl(test_acl)

        category = Forum.objects.all_forums().filter(role="category")[:1][0]
        response = self.client.post(self.link,
                                    data={
                                        'action': 'move',
                                        'thread': [t.pk for t in threads[:5]],
                                        'submit': '',
                                        'new_forum': category.pk
                                    })
        self.assertEqual(response.status_code, 200)
        self.assertIn("You can't move threads to category.",
                      response.content)

        # attempt move to redirect
        self.override_acl(test_acl)

        redirect = Forum.objects.all_forums().filter(role="redirect")[:1][0]
        response = self.client.post(self.link,
                                    data={
                                        'action': 'move',
                                        'thread': [t.pk for t in threads[:5]],
                                        'submit': '',
                                        'new_forum': redirect.pk
                                    })
        self.assertEqual(response.status_code, 200)
        self.assertIn("You can't move threads to redirect.",
                      response.content)

        # move to new_forum
        self.override_acl(test_acl)
        self.override_acl(test_acl, new_forum)
        response = self.client.post(self.link,
                                    data={
                                        'action': 'move',
                                        'thread': [t.pk for t in threads[:5]],
                                        'submit': '',
                                        'new_forum': new_forum.pk
                                    })
        self.assertEqual(response.status_code, 302)

        self.override_acl(test_acl)
        response = self.client.get(self.link)
        self.assertEqual(response.status_code, 200)
        self.assertIn("5 threads were moved to "New Forum".",
                      response.content)

        for thread in new_forum.thread_set.all():
            self.assertIn(thread, threads[:5])
        for thread in self.forum.thread_set.all():
            self.assertIn(thread, threads[5:])