def test_indexableContent_pdf(self): from Products.CMFCore.CatalogTool import IndexableObjectWrapper from Products.CMFDefault.File import File pdf_path = os.path.join(_DATA_DIR, 'test.pdf') d = File('foo', title='Foo', file=file(pdf_path, 'rb'), content_type='application/pdf') d.setLanguage('de') try: w = IndexableObjectWrapper(ob=d, catalog=None) except TypeError: w = IndexableObjectWrapper({}, d) # BBB: for CMF < 2.2 a = self._makeOne(w) icc = a.indexableContent(['Title', 'Description']) self.assertEqual(icc.getFields(), ['Description', 'Title']) self.assertEqual(icc.getFieldData('Title')[0], {'content': u'Foo', 'language': 'de'}) self.assertEqual(icc.getFieldData('Description')[0], {'content': u'', 'language': 'de'}) icc = a.indexableContent(['SearchableText']) self.assertEqual(icc.getFields(), ['SearchableText']) self.assertEqual(icc.getFieldData('SearchableText')[0], {'content': u'Foo', 'language': 'de'}) self.assertEqual(icc.getFieldData('SearchableText')[1], {'content': u'', 'language': 'de'}) body = icc.getFieldData('SearchableText')[2] self.assertEqual(body['content'].strip(), u'Viel Vögel sprangen artig ' u'in den Tüpel und über Feld und Wüste') self.assertEqual(body['language'], 'de')
def test_indexableContent_plain(self): from Products.CMFCore.CatalogTool import IndexableObjectWrapper from Products.CMFDefault.File import File d = File('foo', title='Foo', file='foo content', content_type='text/plain') d.setLanguage('en') try: w = IndexableObjectWrapper(ob=d, catalog=None) except TypeError: w = IndexableObjectWrapper({}, d) # BBB: for CMF < 2.2 a = self._makeOne(w) icc = a.indexableContent(['Title', 'Description']) self.assertEqual(icc.getFields(), ['Description', 'Title']) self.assertEqual(icc.getFieldData('Title')[0], {'content': u'Foo', 'language': 'en'}) self.assertEqual(icc.getFieldData('Description')[0], {'content': u'', 'language': 'en'}) icc = a.indexableContent(['SearchableText']) self.assertEqual(icc.getFields(), ['SearchableText']) self.assertEqual(icc.getFieldData('SearchableText')[0], {'content': u'Foo', 'language': 'en'}) self.assertEqual(icc.getFieldData('SearchableText')[1], {'content': u'', 'language': 'en'}) self.assertEqual(icc.getFieldData('SearchableText')[2], {'content': u'foo content', 'language': 'en'})
def __init__(self, *args, **kw): CNXMLFile.__init__(self, *args, **kw) File.__init__(self, *args, **kw) # Manually set the ID because File is currently broken and deleting __name__, # which is where the id is actually stored. We should probably migrate this to # using the ATCT File, which does work. self.__name__ = args[0]
def test_File_setFormat(self): # Setting the DC.format must also set the content_type property file = File('testfile', format='image/jpeg') self.assertEqual(file.Format(), 'image/jpeg') self.assertEqual(file.content_type, 'image/jpeg') file.setFormat('image/gif') self.assertEqual(file.Format(), 'image/gif') self.assertEqual(file.content_type, 'image/gif')
def test_FileContentTypeUponConstruction(self): # Test the content type after calling the constructor with the # file object being passed in (http://www.zope.org/Collectors/CMF/370) testfile = open(TEST_JPG, 'rb') # Notice the cheat? File objects lack the extra intelligence that # picks content types from the actual file data, so it needs to be # helped along with a file extension... file = File('testfile.jpg', file=testfile) testfile.close() self.assertEqual(file.Format(), 'image/jpeg') self.assertEqual(file.content_type, 'image/jpeg')
def __init__( self, id, title='', description='', relativeFilePath='', ): CVSFile.__init__(self, id, title, description, relativeFilePath) File.__init__(self, id, title, relativeFilePath) OMF.__init__(self) self.data = ''
def test_getId_on_old_File_instance(self): file = self.site._setObject('testfile', File('testfile')) self.assertEqual(file.getId(), 'testfile') self.assertEqual(file.id, 'testfile') # Mimick old instance when base classes had OFS.Image.File first file.__name__ = 'testfile' delattr(file, 'id') self.assertEqual(file.getId(), 'testfile') self.assertEqual(file.id(), 'testfile')
def test_File_setFormat(self): # Setting the format must also set the content_type property file = File('testfile', format='image/jpeg') self.assertEqual(file.Format(), 'image/jpeg') self.assertEqual(file.content_type, 'image/jpeg') file.setFormat('image/gif') self.assertEqual(file.Format(), 'image/gif') self.assertEqual(file.content_type, 'image/gif')
def PUT(self, REQUEST, RESPONSE): CMFFile.PUT(self, REQUEST, RESPONSE)
def _setFile(self, data, precondition=None): if data is not None and self.hasData() and \ str(data.read()) == str(self.getData()): # Same data as previous, no need to change it's content return CMFFile._edit(self, precondition=precondition, file=data)
def manage_beforeDelete(self, item, container): """Both of my parents have a beforeDelete method""" File.manage_beforeDelete(self, item, container) CNXMLFile.manage_beforeDelete(self, item, container)
def manage_afterAdd(self, item, container): """Both of my parents have an afterAdd method""" CNXMLFile.manage_afterAdd(self, item, container) File.manage_afterAdd(self, item, container)