- Timestamp:
- 21 Dec 2014, 22:43:47 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/ikobacustom.skeleton/trunk/src/ikobacustom/skeleton/customers/tests/test_browser.py
r12286 r12291 26 26 from zope.event import notify 27 27 from zope.interface.verify import verifyObject, verifyClass 28 from zope.testbrowser.testing import Browser 29 from hurry.workflow.interfaces import IWorkflowState 28 30 from waeup.ikoba.customers.tests.test_batching import CustomerImportExportSetup 29 31 from ikobacustom.skeleton.customers.documents import SkeletonCustomerDocument 30 from ikobacustom.skeleton.customers.export import SkeletonCustomerDocumentExporter 31 from ikobacustom.skeleton.customers.batching import SkeletonCustomerDocumentProcessor 32 from ikobacustom.skeleton.customers.export import ( 33 SkeletonCustomerExporter, 34 SkeletonCustomerDocumentExporter, 35 SkeletonContractExporter) 36 from ikobacustom.skeleton.customers.batching import ( 37 SkeletonCustomerProcessor, 38 SkeletonCustomerDocumentProcessor, 39 SkeletonContractProcessor) 32 40 from ikobacustom.skeleton.testing import FunctionalLayer 33 41 … … 39 47 def setup_for_export(self): 40 48 customer = createObject(u'waeup.Customer') 49 customer.firstname = u'Beate' 50 customer.lastname = u'Mueller' 51 customer.reg_number = u'123' 52 customer.sex = u'f' 53 IWorkflowState(customer).setState('started') 41 54 self.app['customers'].addCustomer(customer) 42 55 document = createObject(u'waeup.SkeletonCustomerDocument') 43 56 document.title = u'My first document' 44 57 customer['documents'].addDocument(document) 58 contract = createObject(u'waeup.SkeletonContract') 59 contract .title = u'My first contract' 60 customer['contracts'].addContract(contract) 45 61 self.customer = customer 46 62 self.document = document 63 self.contract = contract 47 64 self.outfile = os.path.join(self.workdir, 'myoutput.csv') 48 65 return 49 66 50 def test_export_reimport_all(self): 67 def test_export_reimport_customers(self): 68 # we can export all customers in a portal 69 # set values we can expect in export file 70 self.setup_for_export() 71 exporter = SkeletonCustomerExporter() 72 exporter.export_all(self.app, self.outfile) 73 result = open(self.outfile, 'rb').read() 74 self.assertEqual(result, 75 'customer_id,email,firstname,lastname,middlename,phone,' 76 'reg_number,sex,suspended,suspended_comment,password,state,history\r\n' 77 'K1000000,,Beate,Mueller,,,123,f,0,,,started,[]\r\n') 78 # We can reimport the file ... 79 processor = SkeletonCustomerProcessor() 80 result = processor.doImport( 81 self.outfile, 82 ['customer_id','email','firstname','lastname','middlename','phone', 83 'reg_number','sex','suspended','suspended_comment','password','state'], 84 mode='create') 85 num, num_fail, finished_path, failed_path = result 86 self.assertEqual(num_fail,1) 87 # ... if we remove the original customer. 88 del self.app['customers']['K1000000'] 89 result = processor.doImport( 90 self.outfile, 91 ['customer_id','email','firstname','lastname','middlename','phone', 92 'reg_number','sex','suspended','suspended_comment','password','state'], 93 mode='create') 94 num_succ, num_fail, finished_path, failed_path = result 95 self.assertEqual(num_fail,0) 96 # We can import the same file in update mode if we ignore the reg_number. 97 result = processor.doImport( 98 self.outfile, 99 ['customer_id','email','firstname','lastname','middlename','phone', 100 'xx_reg_number','sex','suspended','suspended_comment','password','state'], 101 mode='update') 102 num_succ, num_fail, finished_path, failed_path = result 103 self.assertEqual(num_succ,1) 104 self.assertEqual(num_fail,0) 105 return 106 107 def test_export_reimport_documents(self): 51 108 # we can export all documents in a portal 52 109 # set values we can expect in export file … … 61 118 'created,My first document,K1000000\r\n' 62 119 % self.document.document_id) 63 # We can import the file if we change the header (user_id -> customer_id)120 # We can reimport the file if we change the header (user_id -> customer_id) 64 121 processor = SkeletonCustomerDocumentProcessor() 65 122 open(self.outfile, 'wb').write( … … 72 129 mode='create') 73 130 num, num_fail, finished_path, failed_path = result 74 #content = open(failed_path).read()75 131 # The object exists. 76 132 self.assertEqual(num_fail,1) … … 84 140 self.assertEqual(num_fail,0) 85 141 # We can import the same file in update mode. 86 processor = SkeletonCustomerDocumentProcessor()87 142 result = processor.doImport( 88 143 self.outfile, … … 93 148 self.assertEqual(num_fail,0) 94 149 return 150 151 def test_export_reimport_contracts(self): 152 # we can export all contracts in a portal 153 # set values we can expect in export file 154 self.setup_for_export() 155 exporter = SkeletonContractExporter() 156 exporter.export_all(self.app, self.outfile) 157 result = open(self.outfile, 'rb').read() 158 self.assertMatches(result, 159 'class_name,contract_category,contract_id,document_object,' 160 'history,last_product_id,product_object,state,title,user_id\r\n' 161 'SkeletonContract,sample,%s,,' 162 '[u\'2014-12-21 22:26:00 WAT - Contract created by system\']' 163 ',,,created,My first contract,K1000000\r\n' 164 % self.contract.contract_id) 165 # We can reimport the file if we change the header (user_id -> customer_id) 166 processor = SkeletonContractProcessor() 167 open(self.outfile, 'wb').write( 168 'class_name,contract_category,contract_id,document_object,' 169 'history,last_product_id,product_object,state,title,customer_id\r\n' 170 'SkeletonContract,sample,%s,,' 171 '[u\'2014-12-21 22:26:00 WAT - Contract created by system\']' 172 ',,,created,My first contract,K1000000\r\n' 173 % self.contract.contract_id) 174 result = processor.doImport( 175 self.outfile, 176 ['class_name','contract_category','contract_id','document_object', 177 'history','last_product_id','product_object','state','title','customer_id'], 178 mode='create') 179 num, num_fail, finished_path, failed_path = result 180 # The object exists. 181 self.assertEqual(num_fail,1) 182 # We remove the original contract. 183 del self.customer['contracts'][self.contract.contract_id] 184 result = processor.doImport( 185 self.outfile, 186 ['class_name','contract_category','contract_id','document_object', 187 'history','last_product_id','product_object','state','title','customer_id'], 188 mode='create') 189 num_succ, num_fail, finished_path, failed_path = result 190 self.assertEqual(num_fail,0) 191 # We can import the same file in update mode. 192 result = processor.doImport( 193 self.outfile, 194 ['class_name','contract_category','contract_id','document_object', 195 'history','last_product_id','product_object','state','title','customer_id'], 196 mode='update') 197 num_succ, num_fail, finished_path, failed_path = result 198 self.assertEqual(num_succ,1) 199 self.assertEqual(num_fail,0) 200 return
Note: See TracChangeset for help on using the changeset viewer.