Fixes tests and incorrect class method reference

This commit is contained in:
Mouse Reeve 2023-05-22 06:39:23 -07:00
parent b3a519c082
commit affaf3d0ba
2 changed files with 25 additions and 9 deletions

View file

@ -78,8 +78,8 @@ class ReportViews(TestCase):
validate_html(result.render())
self.assertEqual(result.status_code, 200)
def test_report_comment(self):
"""comment on a report"""
def test_report_action(self):
"""action on a report"""
view = views.ReportAdmin.as_view()
request = self.factory.post("", {"note": "hi"})
request.user = self.local_user
@ -87,15 +87,17 @@ class ReportViews(TestCase):
view(request, report.id)
comment = models.ReportComment.objects.get()
self.assertEqual(comment.user, self.local_user)
self.assertEqual(comment.note, "hi")
self.assertEqual(comment.report, report)
action = models.ReportAction.objects.get()
self.assertEqual(action.user, self.local_user)
self.assertEqual(action.note, "hi")
self.assertEqual(action.report, report)
self.assertEqual(action.action_type, "comment")
def test_resolve_report(self):
"""toggle report resolution status"""
report = models.Report.objects.create(reporter=self.local_user, user=self.rat)
self.assertFalse(report.resolved)
self.assertFalse(models.ReportAction.objects.exists())
request = self.factory.post("")
request.user = self.local_user
@ -104,11 +106,25 @@ class ReportViews(TestCase):
report.refresh_from_db()
self.assertTrue(report.resolved)
# check that the action was noted
self.assertTrue(
models.ReportAction.objects.filter(
report=report, action_type="resolve", user=self.local_user
).exists()
)
# un-resolve
views.resolve_report(request, report.id)
report.refresh_from_db()
self.assertFalse(report.resolved)
# check that the action was noted
self.assertTrue(
models.ReportAction.objects.filter(
report=report, action_type="reopen", user=self.local_user
).exists()
)
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.suggested_users.remove_user_task.delay")

View file

@ -97,7 +97,7 @@ def suspend_user(request, user_id, report_id=None):
# this isn't a full deletion, so we don't want to tell the world
user.save(broadcast=False)
models.ReportAction.record_action(report_id, USER_SUSPENSION, request.user)
models.Report.record_action(report_id, USER_SUSPENSION, request.user)
return redirect_to_referer(request, "settings-user", user.id)
@ -111,7 +111,7 @@ def unsuspend_user(request, user_id, report_id=None):
# this isn't a full deletion, so we don't want to tell the world
user.save(broadcast=False)
models.ReportAction.record_action(report_id, USER_UNSUSPENSION, request.user)
models.Report.record_action(report_id, USER_UNSUSPENSION, request.user)
return redirect_to_referer(request, "settings-user", user.id)
@ -134,7 +134,7 @@ def moderator_delete_user(request, user_id, report_id=None):
user.delete()
# make a note of the fact that we did this
models.ReportAction.record_action(report_id, USER_DELETION, request.user)
models.Report.record_action(report_id, USER_DELETION, request.user)
return redirect_to_referer(request, "settings-user", user.id)
form.errors["password"] = ["Invalid password"]