def delete_by_article_id(self, _id): """ Removes the article from the published collection. Removes published queue entries and media files. :param str _id: id of the document to be deleted. In mongo, it is the item_id """ lookup = {'item_id': _id} docs = list(self.get_from_mongo(req=None, lookup=lookup)) self.delete(lookup=lookup) get_resource_service('publish_queue').delete_by_article_id(_id) for doc in docs: remove_media_files(doc)
def test_remove_media_files_for_attachments(self): attachments = self.app.data.insert('attachments', [{'media': 'foo'}]) item = { '_id': 'test', 'type': 'text', 'attachments': [ {'attachment': attachments[0]}, ] } with patch.object(self.app.media, 'delete') as media_delete: remove_media_files(item) media_delete.assert_any_call('foo', 'attachments')
def test_remove_media_files_for_picture_associations(self): item = { '_id': 'testimage', 'type': 'text', 'associations': { 'featuremedia': { '_id': '123', 'renditions': self.media }, 'featurevideo': { '_id': '456', 'renditions': { 'viewImage': { 'media': 'testing_123', 'mimetype': 'image/jpeg', 'href': 'http://192.168.220.209/api/upload/abc/raw?_schema=http', 'height': 452, 'width': 640 }, 'thumbnail': { 'media': 'testing_456', 'mimetype': 'image/jpeg', 'href': 'http://192.168.220.209/api/upload/abc/raw?_schema=http', 'height': 120, 'width': 169 } } } } } original = item.copy() with patch.object(self.app.media, 'delete') as media_delete: CropService().update_media_references(item, original) references_service = get_resource_service('media_references') refs = references_service.get(req=None, lookup={'item_id': 'testimage'}) self.assertEqual(refs.count(), 6) for ref in refs: self.assertEqual(ref.get('published'), False) CropService().update_media_references(item, original, True) refs = references_service.get(req=None, lookup={'item_id': 'testimage'}) for ref in refs: self.assertEqual(ref.get('published'), True) remove_media_files(item) self.assertEqual(0, media_delete.call_count)
def test_remove_media_files_for_attachments(self): attachments = self.app.data.insert("attachments", [{"media": "foo"}]) item = { "_id": "test", "type": "text", "attachments": [ { "attachment": attachments[0] }, ], } with patch.object(self.app.media, "delete") as media_delete: remove_media_files(item) media_delete.assert_any_call("foo", "attachments")
def test_remove_media_files_for_picture_associations(self): item = { "_id": "testimage", "type": "text", "associations": { "featuremedia": { "_id": "123", "renditions": self.media }, "featurevideo": { "_id": "456", "renditions": { "viewImage": { "media": "testing_123", "mimetype": "image/jpeg", "href": "http://192.168.220.209/api/upload/abc/raw?_schema=http", "height": 452, "width": 640, }, "thumbnail": { "media": "testing_456", "mimetype": "image/jpeg", "href": "http://192.168.220.209/api/upload/abc/raw?_schema=http", "height": 120, "width": 169, }, }, }, }, } original = item.copy() with patch.object(self.app.media, "delete") as media_delete: CropService().update_media_references(item, original) references_service = get_resource_service("media_references") refs = references_service.get(req=None, lookup={"item_id": "testimage"}) self.assertEqual(refs.count(), 6) for ref in refs: self.assertEqual(ref.get("published"), False) CropService().update_media_references(item, original, True) refs = references_service.get(req=None, lookup={"item_id": "testimage"}) for ref in refs: self.assertEqual(ref.get("published"), True) remove_media_files(item) self.assertEqual(0, media_delete.call_count)
def test_query_removing_media_files_keeps(self): self.app.data.insert(ARCHIVE, [{ 'state': 'spiked', 'expiry': get_expiry_date(-10), 'type': 'picture', 'renditions': self.media }]) self.app.data.insert('ingest', [{ 'type': 'picture', 'renditions': self.media }]) self.app.data.insert('archive_versions', [{ 'type': 'picture', 'renditions': self.media }]) self.app.data.insert('legal_archive', [{ '_id': 1, 'type': 'picture', 'renditions': self.media }]) self.app.data.insert('legal_archive_versions', [{ '_id': 1, 'type': 'picture', 'renditions': self.media }]) archive_items = self.app.data.find_all('archive', None) self.assertEqual(archive_items.count(), 1) deleted = remove_media_files(archive_items[0]) self.assertFalse(deleted)
def test_query_removing_media_files_keeps(self): self.app.data.insert(ARCHIVE, [{'state': 'spiked', 'expiry': get_expiry_date(-10), 'type': 'picture', 'renditions': self.media}]) self.app.data.insert('ingest', [{'type': 'picture', 'renditions': self.media}]) self.app.data.insert('archive_versions', [{'type': 'picture', 'renditions': self.media}]) self.app.data.insert('legal_archive', [{'_id': 1, 'type': 'picture', 'renditions': self.media}]) self.app.data.insert('legal_archive_versions', [{'_id': 1, 'type': 'picture', 'renditions': self.media}]) archive_items = self.app.data.find_all('archive', None) self.assertEqual(archive_items.count(), 1) deleted = remove_media_files(archive_items[0]) self.assertFalse(deleted)
def test_query_removing_media_files_keeps(self): with self.app.app_context(): self.app.data.insert( ARCHIVE, [{"state": "spiked", "expiry": get_expiry_date(-10), "type": "picture", "renditions": self.media}], ) self.app.data.insert("ingest", [{"type": "picture", "renditions": self.media}]) self.app.data.insert("archive_versions", [{"type": "picture", "renditions": self.media}]) self.app.data.insert("legal_archive", [{"_id": 1, "type": "picture", "renditions": self.media}]) self.app.data.insert("legal_archive_versions", [{"_id": 1, "type": "picture", "renditions": self.media}]) archive_items = self.app.data.find_all("archive", None) self.assertEqual(archive_items.count(), 1) deleted = remove_media_files(archive_items[0]) self.assertFalse(deleted)
def delete_by_article_id(self, _id, doc=None): if doc is None: doc = self.find_one(req=None, item_id=_id) self.delete(lookup={config.ID_FIELD: doc[config.ID_FIELD]}) remove_media_files(doc)