Example #1
0
    def test_reply_is_updated_from_entity(self):
        author = ProfileFactory(fid=self.comment.actor_id)
        ContentFactory(fid=self.comment.id, author=author)
        process_entity_comment(self.comment, author)
        content = Content.objects.get(fid=self.comment.id, parent=self.content)
        self.assertEqual(content.text, self.comment.raw_content)

        # Don't allow updating if the author is different
        invalid_entity = base.Comment(
            id=self.comment.id,
            raw_content="barfoo",
            actor_id="https://example.com/notthesameperson",
            target_id=self.content.fid,
        )
        process_entity_comment(invalid_entity,
                               ProfileFactory(fid=invalid_entity.actor_id))
        content.refresh_from_db()
        self.assertEqual(content.text, self.comment.raw_content)
        self.assertEqual(content.author, author)

        # Don't allow changing parent
        invalid_entity = base.Comment(
            id=self.comment.id,
            raw_content="barfoo",
            actor_id="https://example.com/notthesameperson",
            target_id=ContentFactory().fid,
        )

        process_entity_comment(invalid_entity, author)
        content.refresh_from_db()
        self.assertEqual(content.text, self.comment.raw_content)
        self.assertEqual(content.author, author)
Example #2
0
    def test_reply_is_updated_from_entity(self):
        author = ProfileFactory(handle=self.comment.handle)
        ContentFactory(guid=self.comment.guid, author=author)
        process_entity_comment(self.comment, author)
        content = Content.objects.get(guid=self.comment.guid,
                                      parent=self.content)
        self.assertEqual(content.text, self.comment.raw_content)

        # Don't allow updating if the author is different
        invalid_entity = base.Comment(guid=self.comment.guid,
                                      raw_content="barfoo",
                                      handle="*****@*****.**",
                                      target_guid=self.content.guid)
        process_entity_comment(invalid_entity,
                               ProfileFactory(handle=invalid_entity.handle))
        content.refresh_from_db()
        self.assertEqual(content.text, self.comment.raw_content)
        self.assertEqual(content.author, author)

        # Don't allow changing parent
        invalid_entity = base.Comment(guid=self.comment.guid,
                                      raw_content="barfoo",
                                      handle="*****@*****.**",
                                      target_guid=ContentFactory().guid)
        process_entity_comment(invalid_entity, author)
        content.refresh_from_db()
        self.assertEqual(content.text, self.comment.raw_content)
        self.assertEqual(content.author, author)
Example #3
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.post = entities.PostFactory()
     cls.comment = base.Comment()
     cls.retraction = base.Retraction()
     cls.relationship = base.Relationship()
     cls.follow = base.Follow()
Example #4
0
 def setUp(self):
     super().setUp()
     self.comment = base.Comment(
         id="https://example.com/comment",
         target_id=self.content.fid,
         raw_content="foobar",
         actor_id="https://example.com/profile",
     )
Example #5
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.post = entities.PostFactory()
     cls.comment = base.Comment()
     cls.retraction = base.Retraction()
     cls.follow = base.Follow()
     cls.profile = BaseProfileFactory()
     cls.share = BaseShareFactory()
     cls.receiving_user = UserFactory()
     cls.receiving_profile = cls.receiving_user.profile
Example #6
0
def _make_comment(content):
    try:
        return base.Comment(
            raw_content=content.text,
            guid=str(content.guid),
            target_guid=str(content.parent.guid),
            handle=content.author.handle,
            created_at=content.effective_created,
        )
    except Exception as ex:
        logger.exception("_make_comment - Failed to convert %s: %s",
                         content.guid, ex)
        return None
Example #7
0
 def test_visibility_is_not_added_if_public_parent_content(self):
     comment = base.Comment(
         id="https://example.com/comment2",
         target_id=self.public_content.fid,
         raw_content="foobar",
         actor_id="https://example.com/profile2",
     )
     process_entity_comment(comment,
                            ProfileFactory(),
                            receiving_profile=self.receiving_profile)
     content = Content.objects.get(fid=comment.id,
                                   parent=self.public_content)
     self.assertEqual(content.limited_visibilities.count(), 0)
Example #8
0
def _make_comment(content: Content) -> Optional[base.Comment]:
    try:
        return base.Comment(
            raw_content=content.text,
            id=content.fid,
            actor_id=content.author.fid,
            target_id=content.parent.fid,
            created_at=content.effective_modified,
            guid=str(content.uuid),
            handle=content.author.handle,
            target_guid=content.parent.guid,
        )
    except Exception as ex:
        logger.exception("_make_comment - Failed to convert %s: %s",
                         content.fid, ex)
Example #9
0
 def test_visibility__not_added_if_public_parent_content_if_no_visibility_on_comment(
         self):
     comment = base.Comment(
         id="https://example.com/comment2",
         target_id=self.public_content.fid,
         raw_content="foobar",
         actor_id="https://example.com/profile2",
     )
     comment._receivers = [
         UserType(id=self.receiving_profile.fid,
                  receiver_variant=ReceiverVariant.ACTOR)
     ]
     process_entity_comment(comment, ProfileFactory())
     content = Content.objects.get(fid=comment.id,
                                   parent=self.public_content)
     self.assertEqual(content.limited_visibilities.count(), 0)
Example #10
0
 def setUp(self):
     super().setUp()
     self.comment = base.Comment(guid="guid" * 4,
                                 target_guid=self.content.guid,
                                 raw_content="foobar",
                                 handle="*****@*****.**")
Example #11
0
 def setUp(self):
     super().setUp()
     self.comment = base.Comment(target_guid=self.content.guid, raw_content="foobar")