Exemple #1
0
    def post(self, request, id, slug):
        manga = self.get_manga_for_view(id)
        form = MangaReportForm(request, manga=manga, data=request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, _('Thank you for reporting. Your report will be reviewed by a moderator shortly.'))
            return redirect('manga.list')

        return self.render_to_response({
            'form': form,
            'manga': manga,
        })
Exemple #2
0
    def test_manga_report_form(self):
        form = MangaReportForm(request=self.request, manga=self.manga, data={
            'type': ReportMangaType.REPOST,
            'comment': 'This is a repost.',
            'check': 'on',
        })
        self.assertTrue(form.is_valid())

        report_manga = form.save()
        self.assertEqual(report_manga.created_by, self.user)
        self.assertEqual(report_manga.ip_address, '127.0.0.1')
        self.assertEqual(report_manga.weight, self.user.report_weight)
        self.assertEqual(report_manga.manga, self.manga)
        self.assertEqual(report_manga.type, ReportMangaType.REPOST)
Exemple #3
0
    def test_manga_report_multiple_open(self):
        form = MangaReportForm(request=self.request, manga=self.manga, data={
            'type': ReportMangaType.REPOST,
            'comment': 'This is a repost.',
            'check': 'on',
        })
        form.save()

        form = MangaReportForm(request=self.request, manga=self.manga, data={
            'type': ReportMangaType.REPOST,
            'comment': 'This is a repost.',
            'check': 'on',
        })
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors['__all__'], ['You have already reported this manga.'])
Exemple #4
0
    def test_manga_report_form_pending(self):
        self.user.report_weight = 50
        self.user.save()

        form = MangaReportForm(request=self.request, manga=self.manga, data={
            'type': ReportMangaType.REPOST,
            'comment': 'This is a repost.',
            'check': 'on',
        })
        self.assertTrue(form.is_valid())

        report_manga = form.save()
        self.assertEqual(report_manga.created_by, self.user)
        self.assertEqual(report_manga.ip_address, '127.0.0.1')
        self.assertEqual(report_manga.weight, self.user.report_weight)
        self.assertEqual(report_manga.manga, self.manga)
        self.assertEqual(report_manga.type, ReportMangaType.REPOST)

        manga = Manga.objects.get(id=self.manga.id)
        self.assertEqual(manga.status, MangaStatus.PENDING)
Exemple #5
0
    def test_manga_report_form_anonymous_user(self):
        from captcha.conf import settings
        from captcha.models import CaptchaStore

        challenge, response = settings.get_challenge()()
        store = CaptchaStore.objects.create(challenge=challenge, response=response)

        self.request.user = AnonymousUser()

        form = MangaReportForm(request=self.request, manga=self.manga, data={
            'type': ReportMangaType.COPYRIGHT,
            'check': 'on',
            'captcha_0': store.hashkey,
            'captcha_1': store.response,
        })
        self.assertTrue(form.is_valid())

        report_manga = form.save()
        self.assertEqual(report_manga.created_by, None)
        self.assertEqual(report_manga.ip_address, '127.0.0.1')
        self.assertEqual(report_manga.weight, MangaReportForm.ANONYMOUS_USER_REPORT_WEIGHT)
        self.assertEqual(report_manga.manga, self.manga)
        self.assertEqual(report_manga.type, ReportMangaType.COPYRIGHT)