Ignore:
Timestamp:
11 Nov 2011, 07:47:13 (13 years ago)
Author:
uli
Message:

Update tests to reflect interface change. The new test shows how to
store and retrieve multiple files for a single context!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/tests/test_imagestorage.py

    r7066 r7072  
    259259        return
    260260
    261     def test_get_file_by_context(self):
     261    def test_get_file_by_context_w_attr(self):
    262262        # if we register a file name chooser, we can also get a file
    263         # by context
     263        # by context and attribute
    264264        fs = ExtFileStore()
    265265        context = CustomContext()
    266         file_id = IFileStoreNameChooser(context).chooseName()
    267         fs = ExtFileStore()
    268         fs.createFile(file_id, StringIO('my sample'))
    269         result = fs.getFileByContext(context)
    270         self.assertEqual(
    271             file_id, '__mymarker__mysample.txt')
    272         self.assertEqual(
    273             result.read(), 'my sample')
     266        file_id1 = IFileStoreNameChooser(context).chooseName()
     267        file_id2 = IFileStoreNameChooser(context).chooseName(attr='img')
     268        file_id3 = IFileStoreNameChooser(context).chooseName(attr='doc')
     269        fs = ExtFileStore()
     270        # create three files for a single context, each which
     271        # different content
     272        fs.createFile(file_id1, StringIO('my sample 1'))
     273        fs.createFile(file_id2, StringIO('my sample 2'))
     274        fs.createFile(file_id3, StringIO('my sample 3'))
     275        # now get back all files indicated by different `attr` markers
     276        result1 = fs.getFileByContext(context)
     277        result2 = fs.getFileByContext(context, attr='img')
     278        result3 = fs.getFileByContext(context, attr='doc')
     279        # each file has a different file id
     280        self.assertEqual(file_id1, '__mymarker__mysample.txt')
     281        self.assertEqual(file_id2, '__mymarker__mysample.jpg')
     282        self.assertEqual(file_id3, '__mymarker__mysample.doc')
     283        # each file has different content
     284        self.assertEqual(result1.read(), 'my sample 1')
     285        self.assertEqual(result2.read(), 'my sample 2')
     286        self.assertEqual(result3.read(), 'my sample 3')
    274287        return
    275288
Note: See TracChangeset for help on using the changeset viewer.