Skip to content

Commit

Permalink
Expands tests and fixes logic error in report recipients
Browse files Browse the repository at this point in the history
  • Loading branch information
mouse-reeve committed Jan 3, 2024
1 parent 0612930 commit 94409e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bookwyrm/models/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def broadcast(self, activity, sender, *args, **kwargs):

def get_recipients(self, software=None):
"""Send this to the public inbox of the offending instance"""
if self.user.local:
return None
return [self.user.shared_inbox or self.user.inbox]
if self.reported_user.local:
return []
return [self.reported_user.shared_inbox or self.reported_user.inbox]

def get_remote_id(self):
return f"https://{DOMAIN}/settings/reports/{self.id}"
Expand Down
14 changes: 14 additions & 0 deletions bookwyrm/tests/models/test_report_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,17 @@ def test_report_local_user(self):
self.assertEqual(activity["type"], "Flag")
self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["to"], self.another_local_user.remote_id)
#self.assertEqual(activity["object"], [self.another_local_user.remote_id])
self.assertEqual(report.get_recipients(), [])

def test_report_remote_user_with_broadcast(self):
"""a report to the outside needs to broadcast"""
with patch("bookwyrm.models.report.Report.broadcast") as broadcast_mock:
report = models.Report.objects.create(
user=self.local_user,
note="oh no bad",
reported_user=self.remote_user,
allow_broadcast=True,
)
self.assertEqual(broadcast_mock.call_count, 1)
self.assertEqual(report.get_recipients(), [self.remote_user.inbox])

0 comments on commit 94409e4

Please sign in to comment.