Beispiel #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)
Beispiel #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},
     )
Beispiel #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');"
Beispiel #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
Beispiel #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)
Beispiel #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},
     )
Beispiel #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
Beispiel #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');"
Beispiel #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},
     )
Beispiel #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},
     )
Beispiel #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)
Beispiel #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)
Beispiel #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
Beispiel #14
0
 def test_post_is_created_from_entity(self):
     entity = entities.PostFactory()
     process_entity_post(entity, ProfileFactory())
     Content.objects.get(guid=entity.guid)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)