def test_does_not_forward_share_if_not_local_content(self, mock_rq):
     entity = base.Share(
         id="https://example.com/share", actor_id=self.remote_profile.fid,
         target_id=self.remote_content.fid, public=True,
     )
     process_entity_share(entity, self.remote_profile)
     self.assertFalse(mock_rq.called)
Exemple #2
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 test_share_is_not_created_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/doesnotexistatall", public=True,
     )
     process_entity_share(entity, self.remote_profile)
     self.assertFalse(Content.objects.filter(fid=entity.id, share_of=self.local_content).exists())
 def test_forwards_share_if_local_content(self, mock_rq):
     entity = base.Share(
         id="https://example.com/share", actor_id=self.remote_profile.fid,
         target_id=self.local_content.fid, public=True,
     )
     process_entity_share(entity, self.remote_profile)
     mock_rq.assert_called_once_with(forward_entity, entity, self.local_content.id)
Exemple #5
0
 def test_does_not_forward_share_if_not_local_content(self, mock_rq):
     entity = base.Share(
         id="https://example.com/share",
         actor_id=self.remote_profile.fid,
         target_id=self.remote_content.fid,
         public=True,
     )
     process_entity_share(entity, self.remote_profile)
     self.assertFalse(mock_rq.called)
Exemple #6
0
 def test_forwards_share_if_local_content(self, mock_rq):
     entity = base.Share(
         id="https://example.com/share",
         actor_id=self.remote_profile.fid,
         target_id=self.local_content.fid,
         public=True,
     )
     process_entity_share(entity, self.remote_profile)
     mock_rq.assert_called_once_with(forward_entity, entity,
                                     self.local_content.id)
Exemple #7
0
 def test_does_not_forward_share_if_not_local_content(self, mock_rq):
     entity = base.Share(
         guid=str(uuid4()),
         handle=self.remote_profile.handle,
         target_guid=self.remote_content.guid,
         target_handle=self.remote_content.author.handle,
         public=True,
     )
     process_entity_share(entity, self.remote_profile)
     self.assertFalse(mock_rq.called)
Exemple #8
0
 def test_share_is_not_created_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/doesnotexistatall",
         public=True,
     )
     process_entity_share(entity, self.remote_profile)
     self.assertFalse(
         Content.objects.filter(fid=entity.id,
                                share_of=self.local_content).exists())
Exemple #9
0
 def test_forwards_share_if_local_content(self, mock_rq):
     entity = base.Share(
         guid=str(uuid4()),
         handle=self.remote_profile.handle,
         target_guid=self.local_content.guid,
         target_handle=self.local_content.author.handle,
         public=True,
     )
     process_entity_share(entity, self.remote_profile)
     mock_rq.assert_called_once_with(forward_entity, entity,
                                     self.local_content.id)
Exemple #10
0
 def test_share_is_not_created_if_no_target_found(self, mock_retrieve):
     entity = base.Share(
         guid=str(uuid4()),
         handle=self.remote_profile.handle,
         target_guid="notexistingguid",
         target_handle=self.local_content.author.handle,
         public=True,
     )
     process_entity_share(entity, self.remote_profile)
     self.assertFalse(
         Content.objects.filter(guid=entity.guid,
                                share_of=self.local_content).exists())
Exemple #11
0
 def test_share_is_not_created_if_target_handle_and_local_owner_differ(
         self):
     entity = base.Share(
         guid=str(uuid4()),
         handle=self.remote_profile.handle,
         target_guid=self.local_content.guid,
         target_handle="*****@*****.**",
         public=True,
     )
     process_entity_share(entity, self.remote_profile)
     self.assertFalse(
         Content.objects.filter(guid=entity.guid,
                                share_of=self.local_content).exists())
 def test_share_cant_hijack_local_content(self):
     entity = base.Share(
         id=self.local_content2.fid, actor_id=self.local_content2.author.fid,
         target_id=self.local_content.fid, public=True,
         raw_content="this should never get saved",
     )
     current_text = self.local_content2.text
     with self.assertRaises(IntegrityError):
         with transaction.atomic():
             process_entity_share(entity, self.remote_profile)
     self.local_content2.refresh_from_db()
     self.assertIsNone(self.local_content2.share_of)
     self.assertEqual(self.local_content2.text, current_text)
Exemple #13
0
 def test_share_cant_hijack_local_content(self):
     entity = base.Share(
         guid=self.local_content2.guid,
         handle=self.local_content2.author.handle,
         target_guid=self.local_content.guid,
         target_handle=self.local_content.author.handle,
         public=True,
         raw_content="this should never get saved",
     )
     current_text = self.local_content2.text
     with self.assertRaises(IntegrityError):
         process_entity_share(entity, self.remote_profile)
     self.local_content2.refresh_from_db()
     self.assertIsNone(self.local_content2.share_of)
     self.assertEqual(self.local_content2.text, current_text)
Exemple #14
0
 def test_share_cant_hijack_local_content(self):
     entity = base.Share(
         id=self.local_content2.fid,
         actor_id=self.local_content2.author.fid,
         target_id=self.local_content.fid,
         public=True,
         raw_content="this should never get saved",
     )
     current_text = self.local_content2.text
     with self.assertRaises(IntegrityError):
         with transaction.atomic():
             process_entity_share(entity, self.remote_profile)
     self.local_content2.refresh_from_db()
     self.assertIsNone(self.local_content2.share_of)
     self.assertEqual(self.local_content2.text, current_text)
    def test_share_is_created(self):
        entity = base.Share(
            id="https://example.com/share", actor_id=self.remote_profile.fid,
            target_id=self.local_content.fid, public=True,
        )
        process_entity_share(entity, self.remote_profile)
        share = Content.objects.fed(entity.id, share_of=self.local_content).get()
        self.assertEqual(share.text, "")
        self.assertEqual(share.author, self.remote_profile)
        self.assertEqual(share.visibility, Visibility.PUBLIC)
        self.assertEqual(share.service_label, "")
        self.assertEqual(share.fid, entity.id)

        # Update
        entity.raw_content = "now we have text"
        process_entity_share(entity, self.remote_profile)
        share.refresh_from_db()
        self.assertEqual(share.text, "now we have text")
Exemple #16
0
    def test_share_is_created(self):
        entity = base.Share(
            id="https://example.com/share",
            actor_id=self.remote_profile.fid,
            target_id=self.local_content.fid,
            public=True,
        )
        process_entity_share(entity, self.remote_profile)
        share = Content.objects.fed(entity.id,
                                    share_of=self.local_content).get()
        self.assertEqual(share.text, "")
        self.assertEqual(share.author, self.remote_profile)
        self.assertEqual(share.visibility, Visibility.PUBLIC)
        self.assertEqual(share.service_label, "")
        self.assertEqual(share.fid, entity.id)

        # Update
        entity.raw_content = "now we have text"
        process_entity_share(entity, self.remote_profile)
        share.refresh_from_db()
        self.assertEqual(share.text, "now we have text")
Exemple #17
0
 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())
Exemple #18
0
    def test_share_is_created(self):
        entity = base.Share(
            guid=str(uuid4()),
            handle=self.remote_profile.handle,
            target_guid=self.local_content.guid,
            target_handle=self.local_content.author.handle,
            public=True,
        )
        process_entity_share(entity, self.remote_profile)
        share = Content.objects.get(guid=entity.guid,
                                    share_of=self.local_content)
        self.assertEqual(share.text, "")
        self.assertEqual(share.author, self.remote_profile)
        self.assertEqual(share.visibility, Visibility.PUBLIC)
        self.assertEqual(share.service_label, "")
        self.assertEqual(share.guid, entity.guid)

        # Update
        entity.raw_content = "now we have text"
        process_entity_share(entity, self.remote_profile)
        share.refresh_from_db()
        self.assertEqual(share.text, "now we have text")
 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,
     )
     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()
     )