Changeset 12205 for main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests
- Timestamp:
- 12 Dec 2014, 22:14:37 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_document.py
r12057 r12205 19 19 Tests for documents. 20 20 """ 21 import shutil 22 import tempfile 23 import grok 24 from StringIO import StringIO 21 25 from zope.interface.verify import verifyClass, verifyObject 22 from zope.component import createObject 26 from zope.component import createObject, queryUtility 23 27 from hurry.workflow.interfaces import ( 24 28 IWorkflowInfo, IWorkflowState, InvalidTransitionError) 29 from waeup.ikoba.interfaces import ( 30 IObjectHistory, IFileStoreNameChooser, IFileStoreHandler) 31 from waeup.ikoba.imagestorage import DefaultStorage 25 32 from waeup.ikoba.customers.interfaces import ( 26 33 ICustomerDocumentsContainer, ICustomerDocument) 27 34 from waeup.ikoba.interfaces import IObjectHistory 35 from waeup.ikoba.customers.customer import Customer 28 36 from waeup.ikoba.customers.documents import ( 29 CustomerDocumentsContainer, CustomerSampleDocument) 37 CustomerDocumentsContainer, CustomerSampleDocument, 38 CustomerDocumentFileStoreHandler, CustomerDocumentFileNameChooser) 30 39 from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase) 31 40 … … 87 96 self.assertTrue('Document created by system' in messages) 88 97 return 98 99 100 class CustomerDocumentFileTests(FunctionalTestCase): 101 102 layer = FunctionalLayer 103 104 def setUp(self): 105 super(CustomerDocumentFileTests, self).setUp() 106 self.workdir = tempfile.mkdtemp() 107 return 108 109 def tearDown(self): 110 super(CustomerDocumentFileTests, self).tearDown() 111 shutil.rmtree(self.workdir) 112 return 113 114 def test_file_store_handler_util_accessible(self): 115 # we can get an IFileStoreHandler utility for documents 116 handler = queryUtility(IFileStoreHandler, name='file-customerdocument') 117 self.assertTrue( 118 isinstance(handler, CustomerDocumentFileStoreHandler)) 119 return 120 121 def test_file_store_handler(self): 122 store = DefaultStorage() 123 handler = queryUtility(IFileStoreHandler, name='file-customerdocument') 124 result = handler.pathFromFileID( 125 store, '/fake-root', '__anything__345/c999/nice_image_d123_c999.jpeg') 126 self.assertEqual( 127 result, '/fake-root/customers/345/c999/nice_image_d123_c999') 128 return 129 130 def test_file_store_handler_create(self): 131 # we can create files in image store with the document file 132 # store handler 133 store = DefaultStorage(self.workdir) 134 handler = queryUtility(IFileStoreHandler, name='file-customerdocument') 135 file_obj, path, waeup_file = handler.createFile( 136 store, store.root, 'sample.jpg', '__anything__345/c999/nice_image_d123_c999.jpeg', 137 StringIO('I am a JPG file')) 138 self.assertEqual(path[-43:], 'customers/345/c999/nice_image_d123_c999.jpg') 139 return 140 141 def test_iface(self): 142 # make sure we implement promised interfaces 143 obj = CustomerDocumentFileNameChooser(None) # needs a context normally 144 verifyClass(IFileStoreNameChooser, CustomerDocumentFileNameChooser) 145 verifyObject(IFileStoreNameChooser, obj) 146 return 147 148 def test_name_chooser_available(self): 149 # we can get a name chooser for document objects as adapter 150 doc = CustomerSampleDocument() 151 chooser = IFileStoreNameChooser(doc) 152 self.assertTrue(chooser is not None) 153 return 154 155 def test_name_chooser_document(self): 156 # we can't get an image filename for documents not owned by a customer 157 doc = CustomerSampleDocument() 158 chooser = IFileStoreNameChooser(doc) 159 # no customer can be found 160 self.assertRaises(AttributeError, chooser.chooseName, 'sample.jpg') 161 # we add a fake customer and fake documents container and can get 162 # an image name 163 fake_customer = Customer() 164 fake_customer.customer_id = u'K1000001' 165 fake_container = grok.Container() 166 fake_container.__parent__ = fake_customer 167 doc.__parent__ = fake_container 168 result = chooser.chooseName('sample.jpg') 169 self.assertEqual( 170 result, '__file-customerdocument__01000/K1000001/sample_d123_K1000001.jpg') 171 return
Note: See TracChangeset for help on using the changeset viewer.