Example #1
0
class ThreadArchivePagination(TestCase):
    def setUp(self):
        last_year = DateFactory.last_year()
        self.board = BoardFactory()
        self.thread = ThreadFactory(time_made=last_year,
                                    board=self.board,
                                    archived=True)
        self.threads = ThreadFactory.create_batch(50,
                                                  time_made=last_year,
                                                  board=self.board,
                                                  archived=True)
        self.first_page = self.client.get(self.board.get_archive_url())
        self.second_page = self.client.get('{}?page=2'.format(
            self.board.get_archive_url()))

    def test_first_page(self):
        for thread in self.threads:
            self.assertContains(self.first_page, thread.post)

    def test_first_page_not_contains(self):
        self.assertNotContains(self.first_page, self.thread.post)

    def test_second_page(self):
        self.assertContains(self.second_page, self.thread.post)

    def test_second_page_not_contains(self):
        for thread in self.threads:
            self.assertNotContains(self.second_page, thread.post)

    def test_page_url(self):
        self.assertContains(self.first_page, '?page=2')
Example #2
0
class ThreadArchiveTestCase(TestCase):
    def setUp(self):
        self.board = BoardFactory()
        self.threads = ThreadFactory.create_batch(5,
                                                  board=self.board,
                                                  archived=True)
        self.not_archived = ThreadFactory(board=self.board, archived=False)
        self.resp = self.client.get(self.board.get_archive_url())

    def test_status(self):
        self.assertEqual(self.resp.status_code, 200)

    def test_template(self):
        self.assertTemplateUsed(self.resp, 'archives/archive_list.html')

    def test_shows_archived(self):
        for thread in self.threads:
            self.assertContains(self.resp, thread.post)

    def test_doesnt_show_active(self):
        self.assertNotContains(self.resp, self.not_archived.post)

    def test_links(self):
        for thread in self.threads:
            self.assertContains(self.resp, thread.get_absolute_url())

    def test_context(self):
        self.assertFalse(self.resp.context['moderation_view'])

    def test_form_context(self):
        self.assertTrue('form' in self.resp.context)
Example #3
0
class ArchiveSearchFormPost(TestCase):
    def setUp(self):
        self.board = BoardFactory()
        self.thread = ThreadFactory(time_made=DateFactory.last_year(),
                                    archived=True,
                                    board=self.board)
        self.time = self.thread.time_made

    def test_board_url(self):
        resp = self.client.post(reverse('archive_search_form'),
                                {'board': self.board.name})
        self.assertRedirects(resp, expected_url=self.board.get_archive_url())

    def test_year_url(self):
        resp = self.client.post(reverse('archive_search_form'), {
            'board': self.board.name,
            'year': self.time.year
        })
        self.assertRedirects(resp,
                             expected_url=self.thread.get_archive_year_url())

    def test_month_url(self):
        resp = self.client.post(
            reverse('archive_search_form'), {
                'board': self.board.name,
                'year': self.time.year,
                'month': self.time.month
            })
        self.assertRedirects(resp,
                             expected_url=self.thread.get_archive_month_url())

    def test_day_url(self):
        resp = self.client.post(
            reverse('archive_search_form'), {
                'board': self.board.name,
                'year': self.time.year,
                'month': self.time.month,
                'day': self.time.day
            })
        self.assertRedirects(resp,
                             expected_url=self.thread.get_archive_day_url())