Ejemplo n.º 1
0
class ArchivedThreadTestCase(TestCase):
    def setUp(self):
        self.board = BoardFactory()
        self.thread = ThreadFactory(board=self.board)
        self.thread2 = ThreadFactory(board=self.board)
        threads = ThreadFactory.create_batch(110, board=self.board)
        self.thread.refresh_from_db()

    def test_thread_archived_threads(self):
        resp = self.client.get('{}?page=10'.format(
            self.board.get_absolute_url()))
        self.assertNotContains(resp, self.thread2.post)

    def test_no_extra_pages(self):
        resp = self.client.get('{}?page=11'.format(
            self.board.get_absolute_url()))
        self.assertEqual(resp.status_code, 404)

    def test_thread_archived_threads_no_posting(self):
        resp = self.client.post(self.thread.get_post_create_url(),
                                {'post': faker.text()})
        self.assertTrue(resp.status_code, 405)
Ejemplo n.º 2
0
class ThreadCatalogTestCase(TestCase):
    def setUp(self):
        self.board = BoardFactory()
        self.threads = ThreadFactory.create_batch(5, board=self.board)
        self.thread1 = ThreadFactory(subject='test', board=self.board)
        self.thread2 = ThreadFactory(post='test', board=self.board)
        self.archived_thread = ThreadFactory(board=self.board, archived=True)
        self.resp_all_threads = self.client.get(self.board.get_catalog_url())
        self.resp_specific = self.client.get('{}?search={}'.format(
            self.board.get_catalog_url(), 'test'))
        self.resp_post_search = self.client.post(self.board.get_catalog_url(),
                                                 {'search_term': 'Test'})

    def test_view_works(self):
        self.assertEqual(self.resp_all_threads.status_code, 200)

    def test_template(self):
        self.assertTemplateUsed(self.resp_all_threads,
                                'imageboard/catalog.html')

    def test_context(self):
        self.assertEqual(self.resp_all_threads.context['board'], self.board)

    def test_threads_displayed(self):
        for thread in self.threads:
            self.assertContains(self.resp_all_threads, thread.subject)

    def test_archived_not_displayed(self):
        self.assertNotContains(self.resp_all_threads,
                               self.archived_thread.post)

    def test_subject_search(self):
        self.assertContains(self.resp_specific, self.thread1.subject)

    def test_post_search(self):
        self.assertContains(self.resp_specific, self.thread2.post)

    def test_post_redirect(self):
        self.assertRedirects(self.resp_post_search,
                             expected_url='{}?search={}'.format(
                                 self.board.get_catalog_url(), 'Test'),
                             status_code=302)

    def test_nothing_found(self):
        resp = self.client.get('{}?search={}'.format(
            self.board.get_catalog_url(),
            'ÄÖÅ'))  #Test with a word the factory can't produce
        self.assertContains(resp, 'Nothing found.')

    def test_archived_not_searched(self):
        resp = self.client.get('{}?search={}'.format(
            self.board.get_catalog_url(), self.archived_thread.subject))
        self.assertNotContains(resp, self.archived_thread.subject)

    def test_back_link(self):
        self.assertContains(self.resp_all_threads,
                            self.board.get_absolute_url())

    def test_search_term_unquoted(self):
        thread = ThreadFactory(post='&')
        resp = self.client.get('{}?search={}'.format(
            thread.board.get_catalog_url(), '%26'),
                               follow=True)
        self.assertContains(resp, thread.post)