示例#1
0
 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())
示例#2
0
 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'))
示例#3
0
 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)
示例#4
0
 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'))
示例#5
0
class ModelTestCase(TestCase):
    def setUp(self):
        future = timezone.now() + timedelta(days=1)
        self.board = BoardFactory()
        self.ban1 = TransgressionFactory(banned_from=self.board,
                                         banned_until=future)

    def test_no_global_ban(self):
        self.assertFalse(self.ban1.global_ban)

    def test_board_specific_ban(self):
        self.assertEqual(self.ban1.banned_from, self.board)

    def test_future(self):  #Test that ban is in future
        self.assertGreater(self.ban1.banned_until, timezone.now())

    def test_str(self):  #Test the str method
        self.assertEqual(
            self.ban1.__str__(), "{}: {}".format(self.ban1.ip_address,
                                                 self.ban1.banned_until))
示例#6
0
 def test_ban_in_another_board(self):
     ban = TransgressionFactory(ip_address=self.thread.ip_address,
                                banned_from=self.board2)
     self.assertFalse(self.user_is_banned(self.board))
示例#7
0
 def test_board_ban_true(self):
     ban = TransgressionFactory(ip_address=self.thread.ip_address,
                                banned_from=self.board)
     self.assertTrue(self.user_is_banned(self.board))
示例#8
0
 def test_global_ban_true(self):
     ban = TransgressionFactory(ip_address=self.thread.ip_address,
                                global_ban=True)
     self.assertTrue(self.user_is_banned(self.board))
示例#9
0
 def test_board_banned_user(self):
     TransgressionFactory(ip_address=self.ip_address, banned_from=self.thread.board)
     resp = self.client.post(self.url, self.data)
     self.assertEqual(resp.status_code, 400)
示例#10
0
 def test_global_banned_user(self):
    TransgressionFactory(ip_address=self.ip_address, global_ban=True)
    resp = self.client.post(self.url, self.data)
    self.assertEqual(resp.status_code, 400) 
示例#11
0
 def setUp(self):
     future = timezone.now() + timedelta(days=1)
     self.board = BoardFactory()
     self.ban1 = TransgressionFactory(banned_from=self.board,
                                      banned_until=future)