def make_report(request): """a user reports something""" form = forms.ReportForm(request.POST) if not form.is_valid(): raise ValueError(form.errors) form.save() return redirect(request.headers.get("Referer", "/"))
def test_make_report(self): """a user reports another user""" form = forms.ReportForm() form.data["reporter"] = self.local_user.id form.data["user"] = self.rat.id request = self.factory.post("", form.data) request.user = self.local_user views.make_report(request) report = models.Report.objects.get() self.assertEqual(report.reporter, self.local_user) self.assertEqual(report.user, self.rat)
def post(self, request): """a user reports something""" form = forms.ReportForm(request.POST) if not form.is_valid(): raise ValueError(form.errors) report = form.save() if report.links.exists(): # revert the domain to pending domain = report.links.first().domain domain.status = "pending" domain.save() emailing.moderation_report_email(report) return redirect("/")
def test_report_link(self): """a user reports a link as spam""" book = models.Edition.objects.create(title="hi") link = models.FileLink.objects.create(book=book, added_by=self.local_user, url="https://skdjfs.sdf") domain = link.domain domain.status = "approved" domain.save() form = forms.ReportForm() form.data["reporter"] = self.local_user.id form.data["user"] = self.rat.id form.data["links"] = link.id request = self.factory.post("", form.data) request.user = self.local_user views.Report.as_view()(request) report = models.Report.objects.get() domain.refresh_from_db() self.assertEqual(report.links.first().id, link.id) self.assertEqual(domain.status, "pending")