def test_post_is_updated_from_entity(self): entity = entities.PostFactory() author = ProfileFactory(handle=entity.handle) ContentFactory(guid=entity.guid, author=author) process_entity_post(entity, author) content = Content.objects.get(guid=entity.guid) self.assertEqual(content.text, entity.raw_content) # Don't allow updating if the author is different invalid_entity = entities.PostFactory(guid=entity.guid) process_entity_post(invalid_entity, ProfileFactory(handle=invalid_entity.handle)) content.refresh_from_db() self.assertEqual(content.text, entity.raw_content) self.assertEqual(content.author, author)
def test_visibility_is_not_added_to_public_content(self): entity = entities.PostFactory(public=True) process_entity_post(entity, ProfileFactory(), receiving_profile=self.receiving_profile) content = Content.objects.get(fid=entity.id) self.assertEqual(content.limited_visibilities.count(), 0)
def test_share_target_is_fetched_if_no_target_found(self, mock_retrieve): entity = base.Share( id="https://example.com/share", actor_id=self.remote_profile.fid, target_id="https://example.com/notexistingatallll", public=True, ) mock_retrieve.return_value = entities.PostFactory( id=entity.target_id, actor_id=self.remote_profile2.fid, public=True, ) process_entity_share(entity, self.remote_profile) mock_retrieve.assert_called_once_with( entity.target_id, guid=entity.target_guid, handle=entity.target_handle, entity_type="Post", sender_key_fetcher=sender_key_fetcher, ) self.assertTrue( Content.objects.fed(entity.target_id, content_type=ContentType.CONTENT).exists()) self.assertTrue( Content.objects.fed(entity.id, share_of__fid=entity.target_id, content_type=ContentType.SHARE).exists())
def setUpTestData(cls): super().setUpTestData() cls.create_local_and_remote_user() cls.entity = entities.PostFactory() cls.content = ContentFactory() cls.profile2 = ProfileFactory() cls.content.mentions.add(cls.profile2)
def setUpTestData(cls): super(TestProcessEntities, cls).setUpTestData() cls.profile = Mock() cls.post = entities.PostFactory() cls.retraction = base.Retraction(handle=cls.post.handle, target_guid=cls.post.guid, entity_type="Post")
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()
def test_entity_images_are_prefixed_to_post_text(self): entity = entities.PostFactory(_children=[ base.Image(remote_path="foo", remote_name="bar"), base.Image(remote_path="zoo", remote_name="dee"), ], ) process_entity_post(entity, ProfileFactory()) content = Content.objects.get(guid=entity.guid) assert content.text.index("![](foobar) ![](zoodee) \n\n%s" % entity.raw_content) == 0
def test_post_text_fields_are_cleaned(self): entity = entities.PostFactory( raw_content="<script>alert('yup');</script>", provider_display_name="<script>alert('yup');</script>", guid="<script>alert('yup');</script>") process_entity_post(entity, ProfileFactory()) content = Content.objects.get(guid="alert('yup');") assert content.text == "<script>alert('yup');</script>" assert content.service_label == "alert('yup');"
def test_visibility_is_not_added_to_public_content(self): entity = entities.PostFactory(public=True) entity._receivers = [ UserType(id=self.receiving_profile.fid, receiver_variant=ReceiverVariant.ACTOR) ] process_entity_post(entity, ProfileFactory()) content = Content.objects.get(fid=entity.id) self.assertEqual(content.limited_visibilities.count(), 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
def test_visibility_is_added_to_receiving_profile(self): entity = entities.PostFactory() process_entity_post(entity, ProfileFactory(), receiving_profile=self.receiving_profile) content = Content.objects.get(fid=entity.id) self.assertEqual( set(content.limited_visibilities.all()), {self.receiving_profile}, )
def test_visibility_is_added_to_receiving_followers(self): entity = entities.PostFactory(actor_id=self.profile.fid) entity._receivers = [ UserType(id=entity.actor_id, receiver_variant=ReceiverVariant.FOLLOWERS) ] process_entity_post(entity, self.profile) content = Content.objects.get(fid=entity.id) self.assertEqual( set(content.limited_visibilities.all()), {self.local_user.profile, self.local_user2.profile}, )
def test_visibility_is_added_to_receiving_profile(self): entity = entities.PostFactory() entity._receivers = [ UserType(id=self.receiving_profile.fid, receiver_variant=ReceiverVariant.ACTOR) ] process_entity_post(entity, ProfileFactory()) content = Content.objects.get(fid=entity.id) self.assertEqual( set(content.limited_visibilities.all()), {self.receiving_profile}, )
def test_share_target_is_fetched_if_no_target_found(self, mock_retrieve): entity = base.Share( guid=str(uuid4()), handle=self.remote_profile.handle, target_guid="notexistingguid", target_handle=self.remote_profile2.handle, public=True, ) mock_retrieve.return_value = entities.PostFactory( guid=entity.target_guid, handle=self.remote_profile2.handle, ) process_entity_share(entity, self.remote_profile) mock_retrieve.assert_called_once_with( entity.target_id, sender_key_fetcher=sender_key_fetcher) self.assertTrue( Content.objects.filter(guid=entity.target_guid, content_type=ContentType.CONTENT).exists()) self.assertTrue( Content.objects.filter(guid=entity.guid, share_of__guid=entity.target_guid, content_type=ContentType.SHARE).exists())
def test_local_content_is_skipped(self, mock_update): entity = entities.PostFactory(guid=self.local_content.guid) process_entity_post(entity, ProfileFactory()) self.assertFalse(mock_update.called)
def test_post_is_updated_from_entity(self): entity = entities.PostFactory() ContentFactory(guid=entity.guid) process_entity_post(entity, ProfileFactory()) content = Content.objects.get(guid=entity.guid) assert content.text == entity.raw_content
def test_post_is_created_from_entity(self): entity = entities.PostFactory() process_entity_post(entity, ProfileFactory()) content = Content.objects.get(fid=entity.id) self.assertEqual(content.limited_visibilities.count(), 0)
def test_post_is_created_from_entity(self): entity = entities.PostFactory() process_entity_post(entity, ProfileFactory()) Content.objects.get(guid=entity.guid)