Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
class ThreadDatePagination(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.thread.get_archive_year_url())
        self.second_page = self.client.get('{}?page=2'.format(
            self.thread.get_archive_year_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')
Ejemplo n.º 5
0
 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())
Ejemplo n.º 6
0
class ThreadReportDismissView(TestCase):
    def setUp(self):
        mod = ModeratorFactory.create_mod()
        self.client.force_login(mod)
        self.thread = ThreadFactory(reported=True)
        self.resp_get = self.client.get(self.thread.get_report_dismiss_url())
        self.resp_post = self.client.post(self.thread.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.thread)

    def test_report_dismiss_contains(self):
        self.assertContains(self.resp_get, self.thread.thread_number)

    def test_report_dismiss_redirect(self):
        self.assertRedirects(
            self.resp_post,
            expected_url=reverse('dj-mod:moderation_thread_report_list'),
            status_code=302)

    def test_report_dismissed(self):
        self.thread.refresh_from_db()
        self.assertFalse(self.thread.reported)
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 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
Ejemplo n.º 9
0
 def test_hide_thread(self):
     thread = ThreadFactory(public=True)
     data = {'action': 'hide_thread',
             '_selected_action': [thread.pk, ]}
     change_url = reverse('admin:messaging_thread_changelist')
     self.client.post(change_url, data)
     thread.refresh_from_db()
     self.assertFalse(thread.public)
Ejemplo n.º 10
0
class Pinned(TestCase):
    def setUp(self):
        self.thread = ThreadFactory(pinned=True)
        self.posts = UserPostFactory.create_batch(500, thread=self.thread)
        self.thread.refresh_from_db()

    def test_no_archiving_when_pinned(
            self):  #Test that thread isn't archived when it is pinned
        self.assertFalse(self.thread.archived)
Ejemplo n.º 11
0
 def test_pagination(self):
     thread = PublicSerializer(instance=ThreadFactory(public=True))
     ThreadFactory.create_batch(settings.REST_FRAMEWORK['PAGE_SIZE'],
                                public=True)
     resp = self.client.get(reverse('messaging_public_threads'), {
         'page': 2,
         'offset': 100,
         'limit': 100
     })
     self.assertEqual(thread.data, resp.data['results'][0])
Ejemplo n.º 12
0
 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())
Ejemplo n.º 13
0
 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())
Ejemplo n.º 14
0
 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'})
Ejemplo n.º 15
0
 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))
Ejemplo n.º 16
0
class ArchivalOnThreadLimit(
        TestCase
):  #Test that old threads are "bumbed off" when a new thread is made
    def setUp(self):
        self.board = BoardFactory()
        self.old_thread = ThreadFactory(board=self.board)
        threads = ThreadFactory.create_batch(
            100, board=self.board)  #Make enough new threads to archive the old
        self.old_thread.refresh_from_db()  #Get the refreshed data

    def test_bumping_off(self):
        self.assertTrue(self.old_thread.archived)
Ejemplo n.º 17
0
 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.thread.get_archive_year_url())
     self.second_page = self.client.get('{}?page=2'.format(
         self.thread.get_archive_year_url()))
Ejemplo n.º 18
0
class SageTestCase(TestCase):
    def setUp(self):
        self.thread1 = ThreadFactory()
        self.thread2 = ThreadFactory()
        self.post1 = UserPostFactory(thread=self.thread1, sage=True)
        self.thread1.refresh_from_db()

    def test_sage(self):
        self.assertGreater(self.thread2.bumb_order, self.thread1.bumb_order)

    def test_no_sage(self):
        self.post2 = UserPostFactory(thread=self.thread1)
        self.assertGreater(self.thread1.bumb_order, self.thread2.bumb_order)
Ejemplo n.º 19
0
 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))
Ejemplo n.º 20
0
 def setUp(self):
     self.ban1 = self.ip_addr = '127.0.0.1'
     self.board1 = Board.objects.create(name='Test board', slug='test')
     self.thread1 = ThreadFactory()
     self.post1 = UserPost.objects.create(post='JOHNNY GUITAR',
                                          thread=self.thread1,
                                          ip_address=self.ip_addr)
     self.ban1 = Transgression.objects.create(banned_until=timezone.now() +
                                              timedelta(seconds=0.1),
                                              reason='Not liking the mods!',
                                              ip_address=self.ip_addr)
     self.old_THREAD_COOLDOWN = settings.THREAD_COOLDOWN
     settings.THREAD_COOLDOWN = 0.05
     self.old_POST_COOLDOWN = settings.POST_COOLDOWN
     settings.POST_COOLDOWN = 0.05
Ejemplo n.º 21
0
 def test_message_ordering(self):
     thread = ThreadFactory()
     message = MessageFactory(thread=thread)
     MessageFactory(thread=thread)
     thread_serializer = ThreadSerializer(instance=thread)
     self.assertEqual(thread_serializer.data['messages'][0]['id'],
                      message.id)
Ejemplo n.º 22
0
 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)
Ejemplo n.º 23
0
 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)
Ejemplo n.º 24
0
 def test_message_nested(self):
     thread = ThreadFactory()
     message = MessageFactory(thread=thread)
     thread_serializer = ThreadSerializer(instance=thread)
     message_serializer = MessageSerializer(instance=message)
     self.assertEqual(thread_serializer.data['messages'][0],
                      message_serializer.data)
Ejemplo n.º 25
0
class BanProperRedirectTestCase(
        TestCase
):  #Test that there is no redirect when user was banned in the past but it has expired
    def setUp(self):
        self.ban1 = self.ip_addr = '127.0.0.1'
        self.board1 = Board.objects.create(name='Test board', slug='test')
        self.thread1 = ThreadFactory()
        self.post1 = UserPost.objects.create(post='JOHNNY GUITAR',
                                             thread=self.thread1,
                                             ip_address=self.ip_addr)
        self.ban1 = Transgression.objects.create(banned_until=timezone.now() +
                                                 timedelta(seconds=0.1),
                                                 reason='Not liking the mods!',
                                                 ip_address=self.ip_addr)
        self.old_THREAD_COOLDOWN = settings.THREAD_COOLDOWN
        settings.THREAD_COOLDOWN = 0.05
        self.old_POST_COOLDOWN = settings.POST_COOLDOWN
        settings.POST_COOLDOWN = 0.05

    def tearDown(self):
        settings.THREAD_COOLDOWN = self.old_THREAD_COOLDOWN
        settings.POST_COOLDOWN = self.old_POST_COOLDOWN

    def test_no_thread_redirect(self):
        sleep(0.1)
        resp = self.client.post(
            reverse('imageboard_thread_create',
                    kwargs={'board': self.board1.slug}), {
                        'post': 'Im not breaking the rules!',
                        'name': 'Anon',
                        'image': ImageFactory(),
                        'captcha_0': 'dummy',
                        'captcha_1': 'PASSED'
                    })
        self.assertRedirects(resp,
                             expected_url=reverse('imageboard_thread_page',
                                                  kwargs={
                                                      'board':
                                                      self.board1.slug,
                                                      'thread_number': 1
                                                  }),
                             status_code=302)

    def test_no_post_redirect(self):
        sleep(0.1)
        resp = self.client.post(
            reverse('imageboard_userpost_create',
                    kwargs={
                        'board': self.board1.slug,
                        'thread_number': self.thread1.thread_number
                    }), {
                        'post': 'Im not breaking the rules!',
                        'name': 'Anon',
                        'captcha_0': 'dummy',
                        'captcha_1': 'PASSED'
                    })
        self.assertRedirects(resp,
                             expected_url=self.thread1.get_absolute_url(),
                             status_code=302)
Ejemplo n.º 26
0
class ThreadModel(TestCase):
    def setUp(self):
        self.thread = ThreadFactory()

    def test_str(self):
        self.assertEqual(
            self.thread.__str__(), "{}: {}".format(self.thread.thread_id,
                                                   self.thread.subject))
Ejemplo n.º 27
0
 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:]
Ejemplo n.º 28
0
 def test_thread_closed(self):
     thread = ThreadFactory(closed=True)
     data = MessageSerializer(instance=MessageFactory(
         thread=thread)).data.copy()
     data['thread'] = thread.thread_id
     del data["id"]
     del data["media"]
     resp = self.client.post(reverse('message-list'), data)
     self.assertEqual(resp.status_code, 400)
Ejemplo n.º 29
0
 def test_no_media_provided_post(self):
     msg = MessageSerializer(instance=MessageFactory())
     thread = ThreadFactory()
     data = msg.data.copy()
     data['thread'] = thread.thread_id
     del data['id']
     del data['media']
     resp = self.client.post(reverse('message-list'), data)
     self.assertEqual(resp.status_code, 201)
Ejemplo n.º 30
0
 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