Annotation of ExtFile/tests/testPhoto.py, revision 1.1

1.1     ! dwinter     1: #
        !             2: # Tests interaction with Photo product
        !             3: #
        !             4: 
        !             5: import os, sys
        !             6: if __name__ == '__main__':
        !             7:     execfile(os.path.join(sys.path[0], 'framework.py'))
        !             8: 
        !             9: from Testing import ZopeTestCase
        !            10: 
        !            11: have_photo = ZopeTestCase.hasProduct('Photo')
        !            12: 
        !            13: if have_photo:
        !            14:     ZopeTestCase.installProduct('SiteAccess')
        !            15:     ZopeTestCase.installProduct('ExtFile')
        !            16:     ZopeTestCase.installProduct('Photo')
        !            17: 
        !            18: from Products.ExtFile.tests.ExtFileTestCase import ExtFileTestCase
        !            19: from Products.ExtFile.tests.ExtFileTestCase import gifImage
        !            20: from Products.ExtFile import ExtFile, Config
        !            21: from Acquisition import aq_base
        !            22: 
        !            23: user_name = ZopeTestCase.user_name
        !            24: photo_perms = ['Add Photos', 'Change Photos', 'Add Documents, Images, and Files']
        !            25: 
        !            26: import base64
        !            27: auth_info = 'Basic %s' % base64.encodestring('%s:secret' % user_name)
        !            28: 
        !            29: 
        !            30: class TestPhoto(ExtFileTestCase):
        !            31: 
        !            32:     def testAddPhoto(self):
        !            33:         factory = self.folder.manage_addProduct['Photo']
        !            34:         factory.manage_addPhoto('foo', '', open(gifImage, 'rb'), 'image/gif', store='ExtImage', engine='PIL', pregen=0)
        !            35:         self.folder.foo._original._finish()
        !            36:         self.failUnless(self._exists('foo.gif'))
        !            37: 
        !            38:     def testAddPhotoWithDisplays(self):
        !            39:         factory = self.folder.manage_addProduct['Photo']
        !            40:         factory.manage_addPhoto('foo', '', open(gifImage, 'rb'), 'image/gif', store='ExtImage', engine='PIL', pregen=1)
        !            41:         self.folder.foo._original._finish()
        !            42:         self.failUnless(self._exists('foo.gif'))
        !            43: 
        !            44:         for id in self.folder.foo.displayIds(None):
        !            45:             self.folder.foo._photos[id]._finish()
        !            46:         self.failUnless(self._exists('foo_large.gif'))
        !            47:         self.failUnless(self._exists('foo_medium.gif'))
        !            48:         self.failUnless(self._exists('foo_small.gif'))
        !            49:         self.failUnless(self._exists('foo_thumbnail.gif'))
        !            50:         self.failUnless(self._exists('foo_xlarge.gif'))
        !            51:         self.failUnless(self._exists('foo_xsmall.gif'))
        !            52: 
        !            53: 
        !            54: class TestPUTPhoto(ExtFileTestCase):
        !            55: 
        !            56:     def afterSetUp(self):
        !            57:         ExtFileTestCase.afterSetUp(self)
        !            58: 
        !            59:         if not self.app.objectIds('Virtual Host Monster'):
        !            60:             factory = self.app.manage_addProduct['SiteAccess']
        !            61:             factory.manage_addVirtualHostMonster('VHM')
        !            62: 
        !            63:         request = self.app.REQUEST
        !            64:         request['PARENTS'] = [self.app]
        !            65: 
        !            66:         # Fake a dav PUT request
        !            67:         request['BODYFILE'] = open(gifImage, 'rb')
        !            68:         request.environ['CONTENT_TYPE'] = 'image/gif'
        !            69:         request.environ['REQUEST_METHOD'] = 'PUT'
        !            70:         request._auth = auth_info
        !            71: 
        !            72:     def afterClear(self):
        !            73:         ExtFileTestCase.afterClear(self)
        !            74:         ExtFile.REPOSITORY = Config.FLAT
        !            75:         ExtFile.ZODB_PATH = Config.VIRTUAL
        !            76: 
        !            77:     def testPUTPhoto(self):
        !            78: 
        !            79:         def PUT_factory(name, typ, body):
        !            80:             """Creates a Photo."""
        !            81:             from Products.Photo.Photo import Photo
        !            82:             return Photo(name, '', body, content_type=typ, store='ExtImage', engine='PIL', pregen=0)
        !            83: 
        !            84:         self.folder.PUT_factory = PUT_factory
        !            85:         self.setPermissions(photo_perms)
        !            86: 
        !            87:         request = self.app.REQUEST
        !            88:         put = request.traverse('/test_folder_1_/image')
        !            89:         put(request, request.RESPONSE)
        !            90:         self.failUnless(hasattr(aq_base(self.folder), 'image'))
        !            91:         self.folder.image._original._finish()
        !            92:         self.failUnless(self._exists('image.gif'))
        !            93: 
        !            94:     def testPUTPhotoWithDisplays(self):
        !            95: 
        !            96:         def PUT_factory(name, typ, body):
        !            97:             """Creates a Photo."""
        !            98:             from Products.Photo.Photo import Photo
        !            99:             return Photo(name, '', body, content_type=typ, store='ExtImage', engine='PIL', pregen=1)
        !           100: 
        !           101:         self.folder.PUT_factory = PUT_factory
        !           102:         self.setPermissions(photo_perms)
        !           103: 
        !           104:         request = self.app.REQUEST
        !           105:         put = request.traverse('/test_folder_1_/image')
        !           106:         put(request, request.RESPONSE)
        !           107:         self.failUnless(hasattr(aq_base(self.folder), 'image'))
        !           108:         self.folder.image._original._finish()
        !           109:         self.failUnless(self._exists('image.gif'))
        !           110: 
        !           111:         for id in self.folder.image.displayIds(None):
        !           112:             self.folder.image._photos[id]._finish()
        !           113:         self.failUnless(self._exists('image_large.gif'))
        !           114:         self.failUnless(self._exists('image_medium.gif'))
        !           115:         self.failUnless(self._exists('image_small.gif'))
        !           116:         self.failUnless(self._exists('image_thumbnail.gif'))
        !           117:         self.failUnless(self._exists('image_xlarge.gif'))
        !           118:         self.failUnless(self._exists('image_xsmall.gif'))
        !           119: 
        !           120:     def testPUTPhotoSyncZodbVirtual(self):
        !           121: 
        !           122:         def PUT_factory(name, typ, body):
        !           123:             """Creates a Photo."""
        !           124:             from Products.Photo.Photo import Photo
        !           125:             return Photo(name, '', body, content_type=typ, store='ExtImage', engine='PIL', pregen=0)
        !           126: 
        !           127:         self.folder.PUT_factory = PUT_factory
        !           128:         self.setPermissions(photo_perms)
        !           129: 
        !           130:         ExtFile.REPOSITORY = Config.SYNC_ZODB
        !           131:         ExtFile.ZODB_PATH = Config.VIRTUAL
        !           132:         request = self.app.REQUEST
        !           133:         put = request.traverse('/test_folder_1_/image')
        !           134:         put(request, request.RESPONSE)
        !           135:         self.failUnless(hasattr(aq_base(self.folder), 'image'))
        !           136: 
        !           137:         self.assertEqual(self.folder.image._original.filename, ['test_folder_1_', 'image', 'image.gif'])
        !           138: 
        !           139:     def testPUTPhotoSyncZodbPhysical(self):
        !           140: 
        !           141:         def PUT_factory(name, typ, body):
        !           142:             """Creates a Photo."""
        !           143:             from Products.Photo.Photo import Photo
        !           144:             return Photo(name, '', body, content_type=typ, store='ExtImage', engine='PIL', pregen=0)
        !           145: 
        !           146:         self.folder.PUT_factory = PUT_factory
        !           147:         self.setPermissions(photo_perms)
        !           148: 
        !           149:         ExtFile.REPOSITORY = Config.SYNC_ZODB
        !           150:         ExtFile.ZODB_PATH = Config.PHYSICAL
        !           151:         request = self.app.REQUEST
        !           152:         put = request.traverse('/test_folder_1_/image')
        !           153:         put(request, request.RESPONSE)
        !           154:         self.failUnless(hasattr(aq_base(self.folder), 'image'))
        !           155: 
        !           156:         self.assertEqual(self.folder.image._original.filename, ['test_folder_1_', 'image', 'image.gif'])
        !           157: 
        !           158:     def testPUTPhotoSyncZodbVHMVirtual(self):
        !           159: 
        !           160:         def PUT_factory(name, typ, body):
        !           161:             """Creates a Photo."""
        !           162:             from Products.Photo.Photo import Photo
        !           163:             return Photo(name, '', body, content_type=typ, store='ExtImage', engine='PIL', pregen=0)
        !           164: 
        !           165:         self.folder.PUT_factory = PUT_factory
        !           166:         self.setPermissions(photo_perms)
        !           167: 
        !           168:         ExtFile.REPOSITORY = Config.SYNC_ZODB
        !           169:         ExtFile.ZODB_PATH = Config.VIRTUAL
        !           170:         request = self.app.REQUEST
        !           171:         put = request.traverse('/VirtualHostBase/http/foo.com:80/VirtualHostRoot/test_folder_1_/image')
        !           172:         put(request, request.RESPONSE)
        !           173:         self.failUnless(hasattr(aq_base(self.folder), 'image'))
        !           174: 
        !           175:         self.assertEqual(self.folder.image._original.filename, ['test_folder_1_', 'image', 'image.gif'])
        !           176: 
        !           177:     def testPUTPhotoSyncZodbVHMPhysical(self):
        !           178: 
        !           179:         def PUT_factory(name, typ, body):
        !           180:             """Creates a Photo."""
        !           181:             from Products.Photo.Photo import Photo
        !           182:             return Photo(name, '', body, content_type=typ, store='ExtImage', engine='PIL', pregen=0)
        !           183: 
        !           184:         self.folder.PUT_factory = PUT_factory
        !           185:         self.setPermissions(photo_perms)
        !           186: 
        !           187:         ExtFile.REPOSITORY = Config.SYNC_ZODB
        !           188:         ExtFile.ZODB_PATH = Config.PHYSICAL
        !           189:         request = self.app.REQUEST
        !           190:         put = request.traverse('/VirtualHostBase/http/foo.com:80/VirtualHostRoot/test_folder_1_/image')
        !           191:         put(request, request.RESPONSE)
        !           192:         self.failUnless(hasattr(aq_base(self.folder), 'image'))
        !           193: 
        !           194:         # XXX: Photos always use VIRTUAL
        !           195:         self.assertEqual(self.folder.image._original.filename, ['test_folder_1_', 'image', 'image.gif'])
        !           196: 
        !           197:     def testPUTPhotoSyncZodbVHMSubfolderHostingVirtual(self):
        !           198: 
        !           199:         def PUT_factory(name, typ, body):
        !           200:             """Creates a Photo."""
        !           201:             from Products.Photo.Photo import Photo
        !           202:             return Photo(name, '', body, content_type=typ, store='ExtImage', engine='PIL', pregen=0)
        !           203: 
        !           204:         self.folder.PUT_factory = PUT_factory
        !           205:         self.setPermissions(photo_perms)
        !           206: 
        !           207:         ExtFile.REPOSITORY = Config.SYNC_ZODB
        !           208:         ExtFile.ZODB_PATH = Config.VIRTUAL
        !           209:         request = self.app.REQUEST
        !           210:         put = request.traverse('/VirtualHostBase/http/foo.com:80/test_folder_1_/VirtualHostRoot/image')
        !           211:         put(request, request.RESPONSE)
        !           212:         self.failUnless(hasattr(aq_base(self.folder), 'image'))
        !           213: 
        !           214:         self.assertEqual(self.folder.image._original.filename, ['image', 'image.gif'])
        !           215: 
        !           216:     def testPUTPhotoSyncZodbVHMSubfolderHostingPhysical(self):
        !           217: 
        !           218:         def PUT_factory(name, typ, body):
        !           219:             """Creates a Photo."""
        !           220:             from Products.Photo.Photo import Photo
        !           221:             return Photo(name, '', body, content_type=typ, store='ExtImage', engine='PIL', pregen=0)
        !           222: 
        !           223:         self.folder.PUT_factory = PUT_factory
        !           224:         self.setPermissions(photo_perms)
        !           225: 
        !           226:         ExtFile.REPOSITORY = Config.SYNC_ZODB
        !           227:         ExtFile.ZODB_PATH = Config.PHYSICAL
        !           228:         request = self.app.REQUEST
        !           229:         put = request.traverse('/VirtualHostBase/http/foo.com:80/test_folder_1_/VirtualHostRoot/image')
        !           230:         put(request, request.RESPONSE)
        !           231:         self.failUnless(hasattr(aq_base(self.folder), 'image'))
        !           232: 
        !           233:         # XXX: Photos always use VIRTUAL
        !           234:         self.assertEqual(self.folder.image._original.filename, ['image', 'image.gif'])
        !           235: 
        !           236:     def testPUTPhotoSyncZodbVHMInsideOutHostingVirtual(self):
        !           237: 
        !           238:         def PUT_factory(name, typ, body):
        !           239:             """Creates a Photo."""
        !           240:             from Products.Photo.Photo import Photo
        !           241:             return Photo(name, '', body, content_type=typ, store='ExtImage', engine='PIL', pregen=0)
        !           242: 
        !           243:         self.folder.PUT_factory = PUT_factory
        !           244:         self.setPermissions(photo_perms)
        !           245: 
        !           246:         ExtFile.REPOSITORY = Config.SYNC_ZODB
        !           247:         ExtFile.ZODB_PATH = Config.VIRTUAL
        !           248:         request = self.app.REQUEST
        !           249:         put = request.traverse('/VirtualHostBase/http/foo.com:80/VirtualHostRoot/_vh_foo/test_folder_1_/image')
        !           250:         put(request, request.RESPONSE)
        !           251:         self.failUnless(hasattr(aq_base(self.folder), 'image'))
        !           252: 
        !           253:         self.assertEqual(self.folder.image._original.filename, ['test_folder_1_', 'image', 'image.gif'])
        !           254: 
        !           255:     def testPUTPhotoSyncZodbVHMInsideOutHostingPhysical(self):
        !           256: 
        !           257:         def PUT_factory(name, typ, body):
        !           258:             """Creates a Photo."""
        !           259:             from Products.Photo.Photo import Photo
        !           260:             return Photo(name, '', body, content_type=typ, store='ExtImage', engine='PIL', pregen=0)
        !           261: 
        !           262:         self.folder.PUT_factory = PUT_factory
        !           263:         self.setPermissions(photo_perms)
        !           264: 
        !           265:         ExtFile.REPOSITORY = Config.SYNC_ZODB
        !           266:         ExtFile.ZODB_PATH = Config.PHYSICAL
        !           267:         request = self.app.REQUEST
        !           268:         put = request.traverse('/VirtualHostBase/http/foo.com:80/VirtualHostRoot/_vh_foo/test_folder_1_/image')
        !           269:         put(request, request.RESPONSE)
        !           270:         self.failUnless(hasattr(aq_base(self.folder), 'image'))
        !           271: 
        !           272:         # XXX: Photos always use VIRTUAL
        !           273:         self.assertEqual(self.folder.image._original.filename, ['test_folder_1_', 'image', 'image.gif'])
        !           274: 
        !           275:     def testPUTPhotoSyncZodbVHMSubfolderInsideOutHostingVirtual(self):
        !           276: 
        !           277:         def PUT_factory(name, typ, body):
        !           278:             """Creates a Photo."""
        !           279:             from Products.Photo.Photo import Photo
        !           280:             return Photo(name, '', body, content_type=typ, store='ExtImage', engine='PIL', pregen=0)
        !           281: 
        !           282:         self.folder.PUT_factory = PUT_factory
        !           283:         self.setPermissions(photo_perms)
        !           284: 
        !           285:         ExtFile.REPOSITORY = Config.SYNC_ZODB
        !           286:         ExtFile.ZODB_PATH = Config.VIRTUAL
        !           287:         request = self.app.REQUEST
        !           288:         put = request.traverse('/VirtualHostBase/http/foo.com:80/test_folder_1_/VirtualHostRoot/_vh_foo/image')
        !           289:         put(request, request.RESPONSE)
        !           290:         self.failUnless(hasattr(aq_base(self.folder), 'image'))
        !           291: 
        !           292:         self.assertEqual(self.folder.image._original.filename, ['image', 'image.gif'])
        !           293: 
        !           294:     def testPUTPhotoSyncZodbVHMSubfolderInsideOutHostingPhysical(self):
        !           295: 
        !           296:         def PUT_factory(name, typ, body):
        !           297:             """Creates a Photo."""
        !           298:             from Products.Photo.Photo import Photo
        !           299:             return Photo(name, '', body, content_type=typ, store='ExtImage', engine='PIL', pregen=0)
        !           300: 
        !           301:         self.folder.PUT_factory = PUT_factory
        !           302:         self.setPermissions(photo_perms)
        !           303: 
        !           304:         ExtFile.REPOSITORY = Config.SYNC_ZODB
        !           305:         ExtFile.ZODB_PATH = Config.PHYSICAL
        !           306:         request = self.app.REQUEST
        !           307:         put = request.traverse('/VirtualHostBase/http/foo.com:80/test_folder_1_/VirtualHostRoot/_vh_foo/image')
        !           308:         put(request, request.RESPONSE)
        !           309:         self.failUnless(hasattr(aq_base(self.folder), 'image'))
        !           310: 
        !           311:         # XXX: Photos always use VIRTUAL
        !           312:         self.assertEqual(self.folder.image._original.filename, ['image', 'image.gif'])
        !           313: 
        !           314: 
        !           315: def test_suite():
        !           316:     from unittest import TestSuite, makeSuite
        !           317:     suite = TestSuite()
        !           318:     if have_photo:
        !           319:         suite.addTest(makeSuite(TestPhoto))
        !           320:         suite.addTest(makeSuite(TestPUTPhoto))
        !           321:     return suite
        !           322: 
        !           323: if __name__ == '__main__':
        !           324:     framework()
        !           325: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>