def test_replies(self, *_): """get a list of replies""" parent = models.Status(content="hi", user=self.local_user) parent.save(broadcast=False) child = models.Status(content="hello", reply_parent=parent, user=self.local_user) child.save(broadcast=False) sibling = models.Review(content="hey", reply_parent=parent, user=self.local_user, book=self.book) sibling.save(broadcast=False) grandchild = models.Status(content="hi hello", reply_parent=child, user=self.local_user) grandchild.save(broadcast=False) replies = models.Status.replies(parent) self.assertEqual(replies.count(), 2) self.assertEqual(replies.first(), child) # should select subclasses self.assertIsInstance(replies.last(), models.Review) self.assertEqual(parent.thread_id, parent.id) self.assertEqual(child.thread_id, parent.id) self.assertEqual(sibling.thread_id, parent.id) self.assertEqual(grandchild.thread_id, parent.id)
def test_status_type(self, *_): """class name""" self.assertEqual(models.Status().status_type, "Note") self.assertEqual(models.Review().status_type, "Review") self.assertEqual(models.Quotation().status_type, "Quotation") self.assertEqual(models.Comment().status_type, "Comment") self.assertEqual(models.Boost().status_type, "Announce")
def test_status_type(self, _): ''' class name ''' self.assertEqual(models.Status().status_type, 'Note') self.assertEqual(models.Review().status_type, 'Review') self.assertEqual(models.Quotation().status_type, 'Quotation') self.assertEqual(models.Comment().status_type, 'Comment') self.assertEqual(models.Boost().status_type, 'Boost')
def test_handle_discarded_boost(self): """ test a boost of a mastodon status that will be discarded """ status = models.Status( content="hi", user=self.remote_user, ) status.save(broadcast=False) activity = { "type": "Announce", "id": "http://www.faraway.com/boost/12", "actor": self.remote_user.remote_id, "object": status.remote_id, } responses.add(responses.GET, status.remote_id, json=status.to_activity(), status=200) views.inbox.activity_task(activity) self.assertEqual(models.Boost.objects.count(), 0)
def test_discarded_boost(self): """test a boost of a mastodon status that will be discarded""" status = models.Status( content="hi", user=self.remote_user, ) with patch("bookwyrm.activitystreams.add_status_task.delay"): status.save(broadcast=False) activity = { "type": "Announce", "id": "http://www.faraway.com/boost/12", "actor": self.remote_user.remote_id, "object": status.remote_id, "to": ["https://www.w3.org/ns/activitystreams#public"], "cc": ["https://example.com/user/mouse/followers"], "published": "Mon, 25 May 2020 19:31:20 GMT", } responses.add(responses.GET, status.remote_id, json=status.to_activity(), status=200) views.inbox.activity_task(activity) self.assertEqual(models.Boost.objects.count(), 0)
def test_boostable(self, *_): """can a status be boosted, based on privacy""" self.assertTrue(models.Status(privacy="public").boostable) self.assertTrue(models.Status(privacy="unlisted").boostable) self.assertFalse(models.Status(privacy="followers").boostable) self.assertFalse(models.Status(privacy="direct").boostable)
def test_boostable(self, _): ''' can a status be boosted, based on privacy ''' self.assertTrue(models.Status(privacy='public').boostable) self.assertTrue(models.Status(privacy='unlisted').boostable) self.assertFalse(models.Status(privacy='followers').boostable) self.assertFalse(models.Status(privacy='direct').boostable)