Esempio n. 1
0
 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)
Esempio n. 2
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},
     )
Esempio n. 3
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 == "&lt;script&gt;alert('yup');&lt;/script&gt;"
     assert content.service_label == "alert('yup');"
Esempio n. 4
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(guid=entity.guid)
     assert content.text.index("![](foobar) ![](zoodee) \n\n%s" %
                               entity.raw_content) == 0
Esempio n. 5
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)
Esempio n. 6
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},
     )
Esempio n. 7
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
Esempio n. 8
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 == "&lt;script&gt;alert('yup');&lt;/script&gt;"
     assert content.service_label == "alert('yup');"
Esempio n. 9
0
 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},
     )
Esempio n. 10
0
 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},
     )
Esempio n. 11
0
    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)
Esempio n. 12
0
    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)
Esempio n. 13
0
 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
Esempio n. 14
0
 def test_post_is_created_from_entity(self):
     entity = entities.PostFactory()
     process_entity_post(entity, ProfileFactory())
     Content.objects.get(guid=entity.guid)
Esempio n. 15
0
 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)
Esempio n. 16
0
 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)
Esempio n. 17
0
 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)
Esempio n. 18
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)
Esempio n. 19
0
 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)