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_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)
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)
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)
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)
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_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())
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( 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)
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 _make_share(content): try: return base.Share( raw_content=content.text, guid=str(content.guid), target_guid=str(content.share_of.guid), handle=content.author.handle, target_handle=content.share_of.author.handle, created_at=content.effective_modified, public=True if content.visibility == Visibility.PUBLIC else False, provider_display_name="Socialhome", ) except Exception as ex: logger.exception("_make_share - Failed to convert %s: %s", content.guid, ex)
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")
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_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")