Ignore:
Timestamp:
8 Nov 2011, 14:13:30 (13 years ago)
Author:
uli
Message:

Finish default file store name chooser and related tests.

Location:
main/waeup.sirp/branches/ulif-extimgstore/src/waeup/sirp
Files:
2 edited

Legend:

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

    r7031 r7032  
    210210
    211211class FileStoreNameChooser(grok.Adapter):
     212    """Default file store name chooser.
     213
     214    File store name choosers pick a file id, a string, for a certain
     215    context object. They are normally registered as adapters for a
     216    certain content type and know how to build the file id for this
     217    special type of context.
     218
     219    Provides the :class:`waeup.sirp.interfaces.IFileStoreNameChooser`
     220    interface.
     221
     222    This default file name chosser accepts almost every name as long
     223    as it is a string or unicode object.
     224    """
    212225    grok.context(Interface)
    213226    grok.implements(IFileStoreNameChooser)
     
    217230
    218231        Raises a user error if the name is not valid.
    219         """
    220         pass
     232
     233        For the default file store name chooser any name is valid.
     234        """
     235        if isinstance(name, basestring):
     236            return True
     237        return False
    221238
    222239    def chooseName(self, name):
     
    228245        chooseName is expected to always choose a valid name (that
    229246        would pass the checkName test) and never raise an error.
    230         """
     247
     248        For this default name chooser we return the given name if it
     249        is valid or ``unknown_file`` else.
     250        """
     251        if self.checkName(name):
     252            return name
    231253        return u'unknown_file'
    232254
  • main/waeup.sirp/branches/ulif-extimgstore/src/waeup/sirp/tests/test_imagestorage.py

    r7002 r7032  
    310310        self.assertEqual(contents, 'Hi there!')
    311311
    312 class NameChooserTests(unittest.TestCase):
     312class FileStoreNameChooserTests(FunctionalTestCase):
     313
     314    layer = FunctionalLayer
    313315
    314316    def test_iface(self):
     317        # we provide the interfaces we promise to do
    315318        obj = FileStoreNameChooser(None)
    316319        verifyClass(IFileStoreNameChooser, FileStoreNameChooser)
    317320        verifyObject(IFileStoreNameChooser, obj)
     321        return
     322
     323    def test_accessible_as_adapter(self):
     324        # we can get a file name chooser via adapter
     325        chooser = IFileStoreNameChooser(object())
     326        self.assertTrue(
     327            isinstance(chooser, FileStoreNameChooser))
     328        return
     329
     330    def test_check_name(self):
     331        # default file name choosers accept any string
     332        chooser = FileStoreNameChooser(object())
     333        self.assertEqual(chooser.checkName('Hi there!'), True)
     334        self.assertEqual(chooser.checkName(None), False)
     335        return
     336
     337    def test_choose_name(self):
     338        # we get a simple string if we do not pass in a valid string
     339        chooser = FileStoreNameChooser(object())
     340        self.assertEqual(chooser.chooseName('myname'), 'myname')
     341        self.assertEqual(chooser.chooseName(None), u'unknown_file')
    318342        return
    319343
Note: See TracChangeset for help on using the changeset viewer.