Changeset 12204 for main/waeup.ikoba/trunk/src/waeup/ikoba/documents/tests
- Timestamp:
- 12 Dec 2014, 18:28:54 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/tests/test_document.py
r12203 r12204 19 19 Tests for documents. 20 20 """ 21 import shutil 22 import tempfile 23 from StringIO import StringIO 21 24 from zope.interface.verify import verifyClass, verifyObject 22 from zope.component import createObject 25 from zope.component import createObject, queryUtility 23 26 from hurry.workflow.interfaces import ( 24 27 IWorkflowInfo, IWorkflowState, InvalidTransitionError) 28 from waeup.ikoba.interfaces import ( 29 IObjectHistory, IFileStoreNameChooser, IFileStoreHandler) 30 from waeup.ikoba.imagestorage import DefaultStorage 25 31 from waeup.ikoba.documents.interfaces import ( 26 32 IDocumentsContainer, IDocument, IPDFDocument, IHTMLDocument) 27 from waeup.ikoba.interfaces import IObjectHistory28 33 from waeup.ikoba.documents.container import DocumentsContainer 29 34 from waeup.ikoba.documents.document import ( 30 Document, PDFDocument, HTMLDocument) 35 Document, PDFDocument, HTMLDocument, 36 DocumentFileNameChooser, DocumentFileStoreHandler) 31 37 from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase) 32 38 … … 108 114 self.assertTrue('Document created by system' in messages) 109 115 return 116 117 118 class DocumentFileTests(FunctionalTestCase): 119 120 layer = FunctionalLayer 121 122 def setUp(self): 123 super(DocumentFileTests, self).setUp() 124 self.workdir = tempfile.mkdtemp() 125 return 126 127 def tearDown(self): 128 super(DocumentFileTests, self).tearDown() 129 shutil.rmtree(self.workdir) 130 return 131 132 def test_file_store_handler_util_accessible(self): 133 # we can get an IFileStoreHandler utility for documents 134 handler = queryUtility(IFileStoreHandler, name='file-document') 135 self.assertTrue( 136 isinstance(handler, DocumentFileStoreHandler)) 137 return 138 139 def test_file_store_handler(self): 140 store = DefaultStorage() 141 handler = queryUtility(IFileStoreHandler, name='file-document') 142 result = handler.pathFromFileID( 143 store, '/fake-root', '__any_marker__sample.jpg') 144 self.assertEqual( 145 result, '/fake-root/documents/sample') 146 return 147 148 def test_file_store_handler_create(self): 149 # we can create files in image store with the document file 150 # store handler 151 store = DefaultStorage(self.workdir) 152 handler = queryUtility(IFileStoreHandler, name='file-document') 153 file_obj, path, waeup_file = handler.createFile( 154 store, store.root, 'sample.jpg', '__file_document__sample', 155 StringIO('I am a JPG file')) 156 self.assertEqual(path[-20:], 'documents/sample.jpg') 157 return 158 159 def test_iface(self): 160 # make sure we implement promised interfaces 161 obj = DocumentFileNameChooser(None) # needs a context normally 162 verifyClass(IFileStoreNameChooser, DocumentFileNameChooser) 163 verifyObject(IFileStoreNameChooser, obj) 164 return 165 166 def test_name_chooser_available(self): 167 # we can get a name chooser for document objects as adapter 168 doc = Document() 169 chooser = IFileStoreNameChooser(doc) 170 self.assertTrue(chooser is not None) 171 return 172 173 def test_name_chooser_document(self): 174 # we can get an image filename for documents not in a container 175 doc = Document() 176 chooser = IFileStoreNameChooser(doc) 177 result = chooser.chooseName('sample.jpg') 178 # the file would be stored in a ``_default`` directory. 179 self.assertEqual( 180 result, '__file-document__documents/sample_d123.jpg') 181 return
Note: See TracChangeset for help on using the changeset viewer.