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_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_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_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_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 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(fid=entity.id) 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>", id="https://example.com/foobar", ) process_entity_post(entity, ProfileFactory()) content = Content.objects.get(fid="https://example.com/foobar") assert content.text == "<script>alert('yup');</script>" assert content.service_label == "alert('yup');"
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_post_is_updated_from_entity(self): entity = entities.PostFactory() author = ProfileFactory(fid=entity.actor_id) ContentFactory(fid=entity.id, author=author) process_entity_post(entity, author) content = Content.objects.get(fid=entity.id) self.assertEqual(content.text, entity.raw_content) # Don't allow updating if the author is different invalid_entity = entities.PostFactory(id=entity.id) process_entity_post(invalid_entity, ProfileFactory(fid=invalid_entity.actor_id)) content.refresh_from_db() self.assertEqual(content.text, entity.raw_content) self.assertEqual(content.author, author)
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_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.objects.get(guid=entity.guid)
def test_local_content_is_skipped(self, mock_update): entity = entities.PostFactory(id=self.local_content.fid) process_entity_post(entity, ProfileFactory()) self.assertFalse(mock_update.called)
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_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)