- Timestamp:
- 9 Nov 2011, 05:50:11 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/branches/ulif-extimgstore/src/waeup/sirp/tests/test_imagestorage.py
r7036 r7052 6 6 from hurry.file import HurryFile 7 7 from hurry.file.interfaces import IFileRetrieval 8 from zope.component import getUtility, provideUtility, queryUtility 8 from zope.component import ( 9 getUtility, provideUtility, queryUtility, provideAdapter) 9 10 from zope.component.hooks import setSite 10 11 from zope.interface.verify import verifyClass, verifyObject … … 149 150 path = self.pathFromFileID(store, root, file_id) 150 151 return f, path, HurryFile(filename, file_id) 152 153 class CustomContext(object): 154 pass 155 156 class CustomContextFileChooser(object): 157 def __init__(self, context): 158 self.context = context 159 160 def chooseName(self, name=None): 161 return '__mymarker__mysample.txt' 151 162 152 163 class FunctionalExtFileStoreTests(FunctionalTestCase): … … 169 180 provideUtility( 170 181 CustomizedFileHandler(), IFileStoreHandler, name=u'mymarker') 182 # register a file chooser adapter for CustomContext 183 provideAdapter( 184 CustomContextFileChooser, 185 (CustomContext,), IFileStoreNameChooser) 171 186 return 172 187 … … 238 253 return 239 254 255 def test_get_file_by_context(self): 256 # if we register a file name chooser, we can also get a file 257 # by context 258 fs = ExtFileStore() 259 context = CustomContext() 260 file_id = IFileStoreNameChooser(context).chooseName() 261 fs = ExtFileStore() 262 fs.createFile(file_id, StringIO('my sample')) 263 result = fs.getFileByContext(context) 264 self.assertEqual( 265 file_id, '__mymarker__mysample.txt') 266 self.assertEqual( 267 result.read(), 'my sample') 268 return 269 240 270 def test_get_default_handler(self): 241 271 # we can get a default handler
Note: See TracChangeset for help on using the changeset viewer.