Ignore:
Timestamp:
9 Nov 2011, 05:50:11 (13 years ago)
Author:
uli
Message:

Extend tests to show what we expect from the new ExtFileStore? method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/branches/ulif-extimgstore/src/waeup/sirp/tests/test_imagestorage.py

    r7036 r7052  
    66from hurry.file import HurryFile
    77from hurry.file.interfaces import IFileRetrieval
    8 from zope.component import getUtility, provideUtility, queryUtility
     8from zope.component import (
     9    getUtility, provideUtility, queryUtility, provideAdapter)
    910from zope.component.hooks import setSite
    1011from zope.interface.verify import verifyClass, verifyObject
     
    149150        path = self.pathFromFileID(store, root, file_id)
    150151        return f, path, HurryFile(filename, file_id)
     152
     153class CustomContext(object):
     154    pass
     155
     156class CustomContextFileChooser(object):
     157    def __init__(self, context):
     158        self.context = context
     159
     160    def chooseName(self, name=None):
     161        return '__mymarker__mysample.txt'
    151162
    152163class FunctionalExtFileStoreTests(FunctionalTestCase):
     
    169180        provideUtility(
    170181            CustomizedFileHandler(), IFileStoreHandler, name=u'mymarker')
     182        # register a file chooser adapter for CustomContext
     183        provideAdapter(
     184            CustomContextFileChooser,
     185            (CustomContext,), IFileStoreNameChooser)
    171186        return
    172187
     
    238253        return
    239254
     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
    240270    def test_get_default_handler(self):
    241271        # we can get a default handler
Note: See TracChangeset for help on using the changeset viewer.