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'})
Esempio n. 3
0
 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]
Esempio n. 4
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')
Esempio n. 5
0
 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')
Esempio n. 6
0
 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 = ''
Esempio n. 7
0
 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')
Esempio n. 8
0
 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')
Esempio n. 9
0
File: File.py Progetto: poses/erp5
 def PUT(self, REQUEST, RESPONSE):
     CMFFile.PUT(self, REQUEST, RESPONSE)
Esempio n. 10
0
File: File.py Progetto: poses/erp5
 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)
Esempio n. 11
0
File: File.py Progetto: smetsjp/erp5
 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)
Esempio n. 12
0
 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)
Esempio n. 13
0
 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)