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())
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')
def setUp(self): self.boards = BoardFactory.create_batch(5) self.list_resp = self.client.get(reverse('api_board-list')) self.board = BoardFactory() self.url = reverse('api_board-detail', kwargs={'slug': self.board.slug}) self.detail_resp = self.client.get(self.url) self.post_data = {'name': faker.word(), 'description': faker.word(), 'slug': faker.word()}
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 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 setUp(self): mod = ModeratorFactory.create_mod() self.client.force_login(mod) self.board = BoardFactory() self.board2 = BoardFactory() self.threads = ThreadFactory.create_batch(5, reported=True, board=self.board) self.threads2 = ThreadFactory.create_batch(5, reported=True, board=self.board2) self.resp_get_all = self.client.get( reverse('dj-mod:moderation_thread_report_list')) self.resp_get_board = self.client.get('{}?board={}'.format( reverse('dj-mod:moderation_thread_report_list'), self.board.slug))
def setUp(self): self.board = BoardFactory() self.thread = ThreadFactory(archived=True, board=self.board) self.thread2 = ThreadFactory(archived=False, board=self.board) self.search_term_thread = ThreadFactory(archived=True, post='&') self.search_term_resp = self.client.post( reverse('archive_search_form'), { 'board': self.search_term_thread.board.slug, 'search_term': '&' }, follow=True) self.subject_resp = self.client.post(reverse('archive_search_form'), { 'board': self.board, 'search_term': self.thread.subject }, follow=True) self.subject_resp2 = self.client.post( reverse('archive_search_form'), { 'board': self.board, 'search_term': self.thread2.subject }, follow=True) self.post_resp = self.client.post(reverse('archive_search_form'), { 'board': self.board, 'search_term': self.thread.post }, follow=True) self.post_resp2 = self.client.post(reverse('archive_search_form'), { 'board': self.board, 'search_term': self.thread2.post }, follow=True)
def setUp(self): self.board = BoardFactory() self.threads = ThreadFactory.create_batch(5, board=self.board) self.list_resp = self.client.get(reverse('api_thread-list')) self.thread = ThreadFactory() self.url = reverse('api_thread-detail', kwargs={'thread_number': self.thread.thread_number}) self.detail_resp = self.client.get(self.url)
def test_no_ban_redirect( self ): #Test that there is no redirect when user has a ban in another board board2 = BoardFactory() ban = TransgressionFactory(banned_from=board2, ip_address=self.ip_addr) resp = self.client.post( reverse('imageboard_thread_create', kwargs={'board': self.board.slug}), { 'post': 'Im not trying to break the rules!', 'name': 'Anon', 'image': ImageFactory(), 'captcha_0': 'dummy', 'captcha_1': 'PASSED' }) self.assertRedirects(resp, expected_url=reverse('imageboard_thread_page', kwargs={ 'board': self.board.slug, 'thread_number': 1 })) resp2 = self.client.post( reverse('imageboard_userpost_create', kwargs={ 'board': self.board.slug, 'thread_number': self.thread.thread_number }), { 'post': 'Im not trying to break the rules!', 'name': 'Anon', 'captcha_0': 'dummy', 'captcha_1': 'PASSED' }) self.assertRedirects(resp2, expected_url=self.thread.get_absolute_url())
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)
def setUp(self): self.empty_resp = self.client.get(reverse('navigation_board_list')) self.boards = BoardFactory.create_batch(5) self.resp = self.client.get(reverse('navigation_board_list')) mod = ModeratorFactory.create_mod() self.client.force_login(mod) self.mod_resp = self.client.get(reverse('navigation_board_list'))
def setUp(self): self.board = BoardFactory() self.thread = ThreadFactory(archived=True, board=self.board) self.thread2 = ThreadFactory(archived=False, board=self.board) self.subject_resp = self.client.post(reverse('archive_search_form'), { 'board': self.board, 'year': self.thread.time_made.year, 'search_term': self.thread.subject }, follow=True) self.subject_resp2 = self.client.post( reverse('archive_search_form'), { 'board': self.board, 'year': self.thread.time_made.year, 'search_term': self.thread2.subject }, follow=True) self.post_resp = self.client.post(reverse('archive_search_form'), { 'board': self.board, 'year': self.thread2.time_made.year, 'search_term': self.thread.post }, follow=True) self.post_resp2 = self.client.post(reverse('archive_search_form'), { 'board': self.board, 'year': self.thread2.time_made.year, 'search_term': self.thread2.post }, follow=True)
def setUp(self): self.ip_addr = '127.0.0.1' self.board1 = Board.objects.create(name='Test board', slug='test') self.thread1 = Thread.objects.create(post='Test thread!', board=self.board1, ip_address=self.ip_addr) self.thread2 = Thread.objects.create(post='This is a test too!', board=self.board1, ip_address=self.ip_addr) self.post1 = UserPost.objects.create(post='JOHNNY GUITAR', thread=self.thread1, ip_address=self.ip_addr) self.post2 = UserPost.objects.create(post='I hate john', name='Not john', thread=self.thread2, ip_address=self.ip_addr) self.board_empty = BoardFactory() number_of_threads = 21 for number in range( number_of_threads): #Create 21 thread to test pagination Thread.objects.create(post=str(number), board=self.board1, ip_address=self.ip_addr) mod = ModeratorFactory.create_mod() self.client.force_login( mod) #Login a mod to test delete views which require permissions
def setUp(self): self.ip_addr = '127.0.0.1' self.ban_data = { 'banned_until': '2049-07-22', 'reason': 'Breaking the rules.' } self.board = BoardFactory() self.thread = ThreadFactory(board=self.board, ip_address=self.ip_addr) self.post = UserPostFactory(thread=self.thread, ip_address=self.ip_addr) self.old_THREAD_COOLDOWN = settings.THREAD_COOLDOWN settings.THREAD_COOLDOWN = 0 self.old_POST_COOLDOWN = settings.POST_COOLDOWN settings.POST_COOLDOWN = 0 mod = ModeratorFactory.create_mod() self.client.force_login(mod)
def setUp(self): self.boards = BoardFactory.create_batch(5) for board in self.boards: RuleFactory.create_batch(2, board=board) self.global_rules = RuleFactory.create_batch(2, board=None) self.resp = self.client.get(reverse('rules_rule_list')) self.global_rule_query = Rule.objects.filter( board=None) #Must do this to bypass ordering shenanigans
def setUp(self): self.board = BoardFactory() self.thread = ThreadFactory(board=self.board) self.resp = self.client.get( reverse('api_board-detail', kwargs={'slug': self.board.slug})).wsgi_request self.data = BoardSerializer(instance=self.board, context={ 'request': self.resp }).data
def setUp(self): last_month = DateFactory.last_month() self.board = BoardFactory() self.threads = ThreadFactory.create_batch(5, time_made=last_month, board=self.board, archived=True) self.not_archived = ThreadFactory(time_made=last_month, board=self.board, archived=False) self.resp = self.client.get(self.threads[0].get_archive_month_url())
def setUp(self): yesterday = DateFactory.yesterday() self.board = BoardFactory() self.threads = ThreadFactory.create_batch(5, time_made=yesterday, board=self.board, archived=True) self.not_archived = ThreadFactory(time_made=yesterday, board=self.board, archived=False) self.resp = self.client.get(self.threads[0].get_archive_day_url())
def setUp(self): mod = ModeratorFactory.create_mod() self.client.force_login(mod) self.board = BoardFactory() self.last_thread = ThreadFactory(reported=True, board=self.board) self.threads = ThreadFactory.create_batch(150, reported=True, board=self.board) self.resp = self.client.get('{}?board={}'.format( reverse('dj-mod:moderation_thread_report_list'), self.board.slug)) self.resp2 = self.client.get('{}?board={}&page=2'.format( reverse('dj-mod:moderation_thread_report_list'), self.board.slug))
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)
def setUp(self): self.board = BoardFactory() self.ip_address = '127.0.0.1' self.url = reverse('api_thread-list') get_captcha_resp = self.client.get(reverse('rest_validator_view')) self.key = get_captcha_resp.data['captcha_key'] self.captcha_value = CaptchaStore.objects.get(hashkey=self.key).challenge validate_resp = self.client.post(reverse('rest_validator_view'), {'captcha_key': self.key, 'captcha_value': self.captcha_value}) self.data = { 'subject': faker.name(), 'name': faker.name(), 'post': faker.text(), 'image': ImageFactory(), 'board': reverse('api_board-detail', kwargs={'slug': self.board.slug}), 'captcha_key': self.key, }
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())
def setUp(self): self.board = BoardFactory() self.global_rule = RuleFactory(board=None) self.board_rule = RuleFactory(board=self.board)
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)
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 setUp(self): self.board = BoardFactory() self.board2 = BoardFactory() resp = self.client.get(reverse('dj-mod:login')) self.request = resp.wsgi_request self.thread = ThreadFactory(ip_address=self.get_remote_address())
def setUp(self): resp = self.client.get(reverse('dj-mod:login')) self.request = resp.wsgi_request self.board = BoardFactory()
def setUp(self): self.board = BoardFactory()
def setUp(self): self.current_year = timezone.now().year self.board = BoardFactory().name
class BanViewTestCase(TestCase): def setUp(self): self.ip_addr = '127.0.0.1' self.ban_data = { 'banned_until': '2049-07-22', 'reason': 'Breaking the rules.' } self.board = BoardFactory() self.thread = ThreadFactory(board=self.board, ip_address=self.ip_addr) self.post = UserPostFactory(thread=self.thread, ip_address=self.ip_addr) self.old_THREAD_COOLDOWN = settings.THREAD_COOLDOWN settings.THREAD_COOLDOWN = 0 self.old_POST_COOLDOWN = settings.POST_COOLDOWN settings.POST_COOLDOWN = 0 mod = ModeratorFactory.create_mod() self.client.force_login(mod) def tearDown(self): settings.THREAD_COOLDOWN = self.old_THREAD_COOLDOWN settings.POST_COOLDOWN = self.old_POST_COOLDOWN def test_thread_ban_get(self): resp = self.client.get( reverse('dj-mod:moderation_thread_ban', kwargs={'thread_number': self.thread.thread_number})) self.assertEqual(resp.status_code, 200) self.assertTemplateUsed(resp, 'moderation/transgression_form.html') self.assertTrue('form' in resp.context) def test_thread_board_ban_post(self): resp = self.client.post( reverse('dj-mod:moderation_thread_ban', kwargs={'thread_number': self.thread.thread_number}), self.ban_data) self.assertEqual(resp.status_code, 302) new_ban = Transgression.objects.get(reason=self.ban_data['reason']) self.assertEqual(new_ban.reason, self.ban_data['reason']) self.assertEqual(new_ban.ip_address, '127.0.0.1') self.assertEqual(new_ban.banned_from, self.board) def test_thread_global_ban_post(self): reason = TransgressionFactory.reason resp = self.client.post( self.thread.get_ban_url(), { 'reason': reason, 'banned_until': TransgressionFactory.banned_until, 'global_ban': True }) self.assertEqual(resp.status_code, 302) new_ban = Transgression.objects.get(reason=reason) self.assertEqual(new_ban.global_ban, True) self.assertEqual(new_ban.banned_from, None) def test_userpost_ban_get(self): resp = self.client.get( reverse('dj-mod:moderation_userpost_ban', kwargs={'post_number': self.post.post_number})) self.assertEqual(resp.status_code, 200) self.assertTemplateUsed(resp, 'moderation/transgression_form.html') self.assertTrue('form' in resp.context) def test_userpost_board_ban_post(self): resp = self.client.post( reverse('dj-mod:moderation_userpost_ban', kwargs={'post_number': self.post.post_number}), self.ban_data) self.assertEqual(resp.status_code, 302) new_ban = Transgression.objects.get(reason=self.ban_data['reason']) self.assertEqual(new_ban.reason, self.ban_data['reason']) self.assertEqual(new_ban.ip_address, '127.0.0.1') self.assertEqual(new_ban.banned_from, self.board) def test_userpost_global_ban_post(self): reason = TransgressionFactory.reason resp = self.client.post( self.post.get_ban_url(), { 'reason': reason, 'banned_until': TransgressionFactory.banned_until, 'global_ban': True }) self.assertEqual(resp.status_code, 302) new_ban = Transgression.objects.get(reason=reason) self.assertEqual(new_ban.global_ban, True) self.assertEqual(new_ban.banned_from, None) def test_ban_page_redirect_global_ban( self ): #Test that banned user redirect to the banned page correctly when user has global ban ban = TransgressionFactory(global_ban=True, ip_address=self.ip_addr) resp = self.client.post(self.board.get_thread_create_url(), { 'post': 'Im trying to break the rules!', 'name': 'Anon' }) self.assertRedirects( resp, expected_url=reverse('dj-mod:moderation_ban_page')) resp2 = self.client.post(self.thread.get_post_create_url(), { 'post': 'Im trying to break the rules!', 'name': 'Anon' }) self.assertRedirects( resp2, expected_url=reverse('dj-mod:moderation_ban_page')) def test_ban_page_redirect_board_specific( self ): #Test that banned user redirects to the banned page correctly when user has board specific ban ban = TransgressionFactory(banned_from=self.board, ip_address=self.ip_addr) resp = self.client.post( reverse('imageboard_thread_create', kwargs={'board': self.board.slug}), { 'post': 'Im trying to break the rules!', 'name': 'Anon', 'image': ImageFactory() }) self.assertRedirects( resp, expected_url=reverse('dj-mod:moderation_ban_page')) resp2 = self.client.post( reverse('imageboard_userpost_create', kwargs={ 'board': self.board.slug, 'thread_number': self.thread.thread_number }), { 'post': 'Im trying to break the rules!', 'name': 'Anon' }) self.assertRedirects( resp2, expected_url=reverse('dj-mod:moderation_ban_page')) def test_no_ban_redirect( self ): #Test that there is no redirect when user has a ban in another board board2 = BoardFactory() ban = TransgressionFactory(banned_from=board2, ip_address=self.ip_addr) resp = self.client.post( reverse('imageboard_thread_create', kwargs={'board': self.board.slug}), { 'post': 'Im not trying to break the rules!', 'name': 'Anon', 'image': ImageFactory(), 'captcha_0': 'dummy', 'captcha_1': 'PASSED' }) self.assertRedirects(resp, expected_url=reverse('imageboard_thread_page', kwargs={ 'board': self.board.slug, 'thread_number': 1 })) resp2 = self.client.post( reverse('imageboard_userpost_create', kwargs={ 'board': self.board.slug, 'thread_number': self.thread.thread_number }), { 'post': 'Im not trying to break the rules!', 'name': 'Anon', 'captcha_0': 'dummy', 'captcha_1': 'PASSED' }) self.assertRedirects(resp2, expected_url=self.thread.get_absolute_url()) def test_ban_page(self): #Test that ban page displays correctly bans = TransgressionFactory.create_batch(5, ip_address=self.ip_addr) resp = self.client.get(reverse('dj-mod:moderation_ban_page')) self.assertEqual(resp.status_code, 200) self.assertTemplateUsed(resp, 'moderation/transgression_detail.html') self.assertTrue('transgression_list' in resp.context) for ban in bans: self.assertContains(resp, ban.reason)