def setUp(self): self.thread = ThreadFactory() self.posts = UserPostFactory.create_batch(5, thread=self.thread) self.list_resp = self.client.get(reverse('api_post-list')) self.post = UserPostFactory(thread=self.thread) self.url = reverse('api_post-detail', kwargs={'post_number': self.post.post_number}) self.detail_resp = self.client.get(self.url)
class ModerationPermissions( TestCase ): #Test that users without permissions can't access moderation pages def setUp(self): self.thread = ThreadFactory(reported=True) self.post = UserPostFactory(reported=True) def test_thread_ban(self): resp = self.client.get(self.thread.get_ban_url()) self.assertEqual(resp.status_code, 403) def test_userpost_ban(self): resp = self.client.get(self.post.get_ban_url()) self.assertEqual(resp.status_code, 403) def test_thread_reports(self): resp = self.client.get(reverse('dj-mod:moderation_thread_report_list')) self.assertEqual(resp.status_code, 403) def test_userpost_reports(self): resp = self.client.get( reverse('dj-mod:moderation_userpost_report_list')) self.assertEqual(resp.status_code, 403) def test_thread_report_dismiss(self): resp = self.client.get(self.thread.get_report_dismiss_url()) self.assertEqual(resp.status_code, 403) def test_userpost_report_dismiss(self): resp = self.client.get(self.post.get_report_dismiss_url()) self.assertEqual(resp.status_code, 403)
class UserPostReportDismissView(TestCase): def setUp(self): mod = ModeratorFactory.create_mod() self.client.force_login(mod) self.post = UserPostFactory(reported=True) self.resp_get = self.client.get(self.post.get_report_dismiss_url()) self.resp_post = self.client.post(self.post.get_report_dismiss_url()) def test_report_dismiss_view_works(self): self.assertEqual(self.resp_get.status_code, 200) def test_report_dismiss_template(self): self.assertTemplateUsed(self.resp_get, 'moderation/report_confirm_delete.html') def test_report_dimiss_context(self): self.assertEqual(self.resp_get.context['object'], self.post) def test_report_dismiss_contains(self): self.assertContains(self.resp_get, self.post.post_number) def test_report_dismiss_redirect(self): self.assertRedirects( self.resp_post, expected_url=reverse('dj-mod:moderation_userpost_report_list'), status_code=302) def test_report_dismissed(self): self.post.refresh_from_db() self.assertFalse(self.post.reported)
def setUp(self): self.thread = ThreadFactory() posts = UserPostFactory.create_batch(500, thread=self.thread) self.thread2 = ThreadFactory() posts2 = UserPostFactory.create_batch(350, thread=self.thread2) post = UserPostFactory( thread=self.thread ) #Make a post to test that bumb_order doesn't change
def setUp(self): name = 'Name #test' post = UserPostFactory(name=name) signer = Signer() tripcode = '!{}'.format( signer.sign('#test')[-10:]) #Process the expected tripcode self.processed_name = name.replace('#test', tripcode) self.trip_name = post.name #Below set up a test for a name without a trip to check that there are no unintended processing or errors self.name_without_trip = 'Name' post2 = UserPostFactory(name=self.name_without_trip) self.no_trip = post2.name
def setUp(self): mod = ModeratorFactory.create_mod() self.client.force_login(mod) self.board = BoardFactory() self.thread = ThreadFactory(board=self.board) self.posts = UserPostFactory.create_batch(150, reported=True, thread=self.thread) self.last_post = UserPostFactory(reported=True, thread=self.thread) self.resp = self.client.get('{}?board={}'.format( reverse('dj-mod:moderation_userpost_report_list'), self.board.slug)) self.resp2 = self.client.get('{}?board={}&page=2'.format( reverse('dj-mod:moderation_userpost_report_list'), self.board.slug))
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.post = UserPostFactory() self.resp = self.client.get(reverse('api_post-list')).wsgi_request self.data = UserPostSerializer(instance=self.post, context={ 'request': self.resp }).data
def setUp(self): self.thread = ThreadFactory(id_enabled=True) self.post = UserPostFactory(thread=self.thread) value1 = str(self.post.ip_address) + str(self.thread.thread_number) value2 = str(self.thread.ip_address) + str(self.thread.thread_number) signer = Signer() self.unique_post_id = signer.sign(value1)[-10:] self.unique_thread_id = signer.sign(value2)[-10:]
def setUp(self): mod = ModeratorFactory.create_mod() self.client.force_login(mod) self.board = BoardFactory() self.board2 = BoardFactory() self.thread = ThreadFactory(board=self.board) self.thread2 = ThreadFactory(board=self.board2) self.posts = UserPostFactory.create_batch(5, thread=self.thread, reported=True) self.posts2 = UserPostFactory.create_batch(5, thread=self.thread2, reported=True) self.resp_get_all = self.client.get( reverse('dj-mod:moderation_userpost_report_list')) self.resp_get_board = self.client.get('{}?board={}'.format( reverse('dj-mod:moderation_userpost_report_list'), self.board.slug))
def setUp(self): self.thread = ThreadFactory() self.posts = UserPostFactory.create_batch(5, thread=self.thread) self.resp = self.client.get( reverse('api_thread-detail', kwargs={'thread_number': self.thread.thread_number})).wsgi_request self.data = ThreadSerializer(instance=self.thread, context={ 'request': self.resp }).data
class ImageboardPermissions( TestCase ): #Test that users with no permissions can't access delete views def setUp(self): self.thread = ThreadFactory() self.post = UserPostFactory() def test_no_thread_delete_permission(self): resp = self.client.get(self.thread.get_delete_url()) self.assertEqual(resp.status_code, 403) def test_no_userpost_delete_permission(self): resp = self.client.get(self.post.get_delete_url()) self.assertEqual(resp.status_code, 403)
class UserPostReportTestCase(TestCase): def setUp(self): self.post = UserPostFactory() self.get_resp = self.client.get(self.post.get_report_url()) self.post_resp = self.client.post(self.post.get_report_url()) self.post.refresh_from_db() def test_template_used(self): self.assertTemplateUsed(self.get_resp, 'imageboard/userpost_report_confirm.html') def test_context(self): self.assertTrue('userpost' in self.get_resp.context) def test_context_correct(self): self.assertEqual(self.get_resp.context['userpost'], self.post) def test_redirect(self): self.assertRedirects(self.post_resp, expected_url=self.post.get_absolute_url(), status_code=302) def test_thread_reported(self): self.assertTrue(self.post.reported)
class ImageTestCase(TestCase): #Test that images are shown def setUp(self): self.thread = ThreadFactory() self.post = UserPostFactory() def test_thread_image_shown(self): resp = self.client.get(self.thread.board.get_absolute_url()) self.assertContains(resp, self.thread.image.url) def test_post_image_shown(self): resp = self.client.get(self.post.get_absolute_url()) self.assertContains(resp, self.post.image.url) def test_image_in_catalog(self): resp = self.client.get(self.thread.board.get_catalog_url()) self.assertContains(resp, self.thread.image.url)
def test_cooldown_true(self): thread = ThreadFactory(ip_address=self.get_remote_address()) post = UserPostFactory(ip_address=self.get_remote_address()) self.assertTrue(self.user_on_cooldown(Thread)) self.assertTrue(self.user_on_cooldown(UserPost))
def setUp(self): self.thread1 = ThreadFactory() self.thread2 = ThreadFactory() self.post1 = UserPostFactory(thread=self.thread1, sage=True) self.thread1.refresh_from_db()
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)
def setUp(self): self.post = UserPostFactory() self.get_resp = self.client.get(self.post.get_report_url()) self.post_resp = self.client.post(self.post.get_report_url()) self.post.refresh_from_db()
def setUp(self): self.post_set1 = UserPostFactory.create_batch(5) self.post_set2 = UserPostFactory.create_batch(5) self.resp = self.client.get(reverse('navigation_frontpage'))
def setUp(self): self.thread = ThreadFactory() posts = UserPostFactory.create_batch(500, thread=self.thread)
def setUp(self): self.thread = ThreadFactory() self.post = UserPostFactory()
def test_no_sage(self): self.post2 = UserPostFactory(thread=self.thread1) self.assertGreater(self.thread1.bumb_order, self.thread2.bumb_order)
def setUp(self): self.thread = ThreadFactory(reported=True) self.post = UserPostFactory(reported=True)
def setUp(self): self.thread = ThreadFactory(pinned=True) self.posts = UserPostFactory.create_batch(500, thread=self.thread) self.thread.refresh_from_db()
def setUp(self): mod = ModeratorFactory.create_mod() self.client.force_login(mod) self.post = UserPostFactory(reported=True) self.resp_get = self.client.get(self.post.get_report_dismiss_url()) self.resp_post = self.client.post(self.post.get_report_dismiss_url())
def setUp(self): self.post = UserPostFactory() self.resp = self.client.get( reverse('imageboard_userpost_ajax', kwargs={'post_number': self.post.post_number}))
def test_user_on_cooldown(self): UserPostFactory(ip_address=self.ip_address) resp = self.client.post(self.url, self.data) self.assertEqual(resp.status_code, 400)