예제 #1
0
 def test_visibility_is_added_to_receiving_profile(self):
     process_entity_comment(self.comment, ProfileFactory(), receiving_profile=self.receiving_profile)
     content = Content.objects.get(fid=self.comment.id, parent=self.content)
     self.assertEqual(
         set(content.limited_visibilities.all()),
         {self.receiving_profile},
     )
예제 #2
0
 def test_entity_images_are_prefixed_to_post_text(self):
     self.comment._children = [
         base.Image(remote_path="foo", remote_name="bar"),
         base.Image(remote_path="zoo", remote_name="dee"),
     ]
     process_entity_comment(self.comment, ProfileFactory())
     content = Content.objects.get(fid=self.comment.id, parent=self.content)
     self.assertEqual(content.text.index("![](foobar) ![](zoodee) \n\n%s" % self.comment.raw_content), 0)
예제 #3
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)
예제 #4
0
 def test_mentions_are_linked(self):
     self.comment._mentions = {self.profile.fid}
     process_entity_comment(self.comment, ProfileFactory())
     content = Content.objects.get(fid=self.comment.id)
     self.assertEqual(
         set(content.mentions.all()),
         {self.profile},
     )
예제 #5
0
 def test_forwards_relayable_if_local_content(self, mock_rq):
     user = UserFactory()
     self.content.author = user.profile
     self.content.save()
     self.content.refresh_from_db()
     mock_rq.reset_mock()
     process_entity_comment(self.comment, ProfileFactory())
     Content.objects.get(fid=self.comment.id, parent=self.content)
     call_args = [
         call(forward_entity, self.comment, self.content.id),
     ]
     self.assertEqual(mock_rq.call_args_list, call_args)
예제 #6
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)
예제 #7
0
 def test_local_reply_is_skipped(self, mock_update):
     user = UserFactory()
     ContentFactory(fid=self.comment.id, author=user.profile)
     process_entity_comment(self.comment, ProfileFactory())
     self.assertFalse(mock_update.called)
예제 #8
0
 def test_does_not_forward_relayable_if_not_local_content(self, mock_rq):
     process_entity_comment(self.comment, ProfileFactory())
     Content.objects.get(fid=self.comment.id, parent=self.content)
     self.assertFalse(mock_rq.called)
예제 #9
0
 def test_reply_text_fields_are_cleaned(self):
     self.comment.raw_content = "<script>alert('yup');</script>"
     process_entity_comment(self.comment, ProfileFactory())
     content = Content.objects.get(fid=self.comment.id, parent=self.content)
     self.assertEqual(content.text, "&lt;script&gt;alert('yup');&lt;/script&gt;")
예제 #10
0
 def test_reply_is_created_from_entity(self):
     process_entity_comment(self.comment, ProfileFactory())
     content = Content.objects.get(fid=self.comment.id, parent=self.content)
     self.assertEqual(content.limited_visibilities.count(), 0)
예제 #11
0
 def test_reply_text_fields_are_cleaned(self):
     self.comment.raw_content = "<script>alert('yup');</script>"
     process_entity_comment(self.comment, ProfileFactory())
     content = Content.objects.get(fid=self.comment.id, parent=self.content)
     self.assertEqual(content.text,
                      "&lt;script&gt;alert('yup');&lt;/script&gt;")
예제 #12
0
 def test_reply_is_created_from_entity(self):
     process_entity_comment(self.comment, ProfileFactory())
     content = Content.objects.get(fid=self.comment.id, parent=self.content)
     self.assertEqual(content.limited_visibilities.count(), 0)
예제 #13
0
 def test_local_reply_is_skipped(self, mock_update):
     user = UserFactory()
     ContentFactory(fid=self.comment.id, author=user.profile)
     process_entity_comment(self.comment, ProfileFactory())
     self.assertFalse(mock_update.called)
예제 #14
0
 def test_does_not_forward_relayable_if_not_local_content(self, mock_rq):
     process_entity_comment(self.comment, ProfileFactory())
     Content.objects.get(fid=self.comment.id, parent=self.content)
     self.assertFalse(mock_rq.called)