Changeset 6525 for main


Ignore:
Timestamp:
15 Jul 2011, 10:56:53 (13 years ago)
Author:
uli
Message:

Update tests: reintroduce file retrieval tests as they are going to be
used again.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/image/README.txt

    r6310 r6525  
    3333  'test data'
    3434
     35Tramline Support
     36----------------
     37
    3538The WAeUPImageFile object normally stores the file data using ZODB
    36 persistence. For better efficiency, each file is stored in a Blob.
    37 `ImageFile` field
     39persistence. Files can however also be stored by tramline.  If
     40tramline is installed in Apache, the Tramline takes care of generating
     41ids for files and storing the file on the filesystem directly. The ids
     42are then passed as file data to be stored in the ZODB.
     43
     44Let's first enable tramline.
     45
     46The tramline directory structure is a directory with two subdirectories,
     47one called 'repository' and the other called 'upload'::
     48
     49  >>> import tempfile, os
     50  >>> dirpath = tempfile.mkdtemp()
     51  >>> repositorypath = os.path.join(dirpath, 'repository')
     52  >>> uploadpath = os.path.join(dirpath, 'upload')
     53  >>> os.mkdir(repositorypath)
     54  >>> os.mkdir(uploadpath)
     55
     56We create a TramlineFileRetrieval object knowing about this directory,
     57and register it as a utility::
     58
     59  >>> from hurry.file.file import TramlineFileRetrievalBase
     60  >>> class TramlineFileRetrieval(TramlineFileRetrievalBase):
     61  ...    def getTramlinePath(self):
     62  ...        return dirpath
     63  >>> retrieval = TramlineFileRetrieval()
     64  >>> component.provideUtility(retrieval, IFileRetrieval)
     65
     66Now let's store a file the way tramline would during upload::
     67
     68  >>> f = open(os.path.join(repositorypath, '1'), 'wb')
     69  >>> f.write('test data')
     70  >>> f.close()
     71
     72The file with underlying name '1' (the data stored in the ZODB will be
     73just '1') will now be created::
     74
     75  >>> file = WAeUPImageFile('foo.jpg', '1')
     76
     77The data is now '1', referring to the real file::
     78
     79  >>> file.data
     80  '1'
     81
     82Retrieving the file results in the real file::
     83
     84  >>> f = file.file
     85  >>> f.read()
     86  'test data'
     87
     88We can also retrieve its size::
     89
     90  >>> file.size
     91  9L
     92
     93Now let's disable tramline in our utility::
     94
     95  >>> class TramlineFileRetrieval(TramlineFileRetrievalBase):
     96  ...     def getTramlinePath(self):
     97  ...        return dirpath
     98  ...     def isTramlineEnabled(self):
     99  ...        return False
     100  >>> component.provideUtility(TramlineFileRetrieval(), IFileRetrieval)
     101
     102We expect the same behavior as when tramline is not installed::
     103
     104  >>> file = WAeUPImageFile('foo.jpg', 'data')
     105  >>> f = file.file
     106  >>> f.read()
     107  'data'
     108  >>> file.size
     109  4
     110
     111Support for :mod:`waeup.sirp.imagestorage`
     112------------------------------------------
     113
     114The behaviour shown above can be used for any Zope3 application. With
     115:mod:`waeup.sirp` we use a special file retrieval utility defined in
     116:mod:`waeup.sirp.imagestorage`. As this utility is based on
     117:mod:`waeup.sirp` internal stuff we do not show it here but in the
     118tests that come with that storage type.
     119
     120Put roughly, an imagestorage stores file data in containers of blobs
     121belonging to a certain site. See the module itself for details.
     122
     123`ImageFile` Field
    38124-----------------
    39125
Note: See TracChangeset for help on using the changeset viewer.