Changeset 12097 for main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests
- Timestamp:
- 30 Nov 2014, 20:49:22 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py
r12096 r12097 96 96 self.product.product_id = u'SAM' 97 97 self.product.title = u'Our Samle Product' 98 self.product. application_category = u'sample'98 self.product.contract_category = u'sample' 99 99 self.app['products'].addProduct(self.product) 100 100 … … 114 114 document.title = u'My first document' 115 115 self.customer['documents'].addDocument(document) 116 application = createObject('waeup.SampleApplication')117 application.title = u'My first application'118 self.customer[' applications'].addApplication(application)116 contract = createObject('waeup.SampleContract') 117 contract.title = u'My first contract' 118 self.customer['contracts'].addContract(contract) 119 119 120 120 # Set password … … 131 131 self.history_path = self.customer_path + '/history' 132 132 self.documents_path = self.customer_path + '/documents' 133 self. applications_path = self.customer_path + '/applications'133 self.contracts_path = self.customer_path + '/contracts' 134 134 135 135 self.app['configuration'].carry_over = True … … 1052 1052 1053 1053 1054 class ApplicationUITests(CustomersFullSetup):1055 # Tests for CustomerSample Applicationrelates views and pages1056 1057 def test_manage_ application(self):1058 # Managers can access the pages of customer applicationsconter1054 class ContractUITests(CustomersFullSetup): 1055 # Tests for CustomerSampleContract relates views and pages 1056 1057 def test_manage_contract(self): 1058 # Managers can access the pages of customer contractsconter 1059 1059 # and can perform actions 1060 1060 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') … … 1063 1063 self.assertEqual(self.browser.url, self.customer_path) 1064 1064 self.browser.open(self.customer_path) 1065 self.browser.getLink(" Applications").click()1066 self.browser.getLink("Add application").click()1067 self.browser.getControl(name="apptype").value = ['Sample Application']1068 self.browser.getControl("Create application").click()1069 self.assertTrue('Sample Applicationcreated.' in self.browser.contents)1070 application = self.customer['applications']['a102']1071 1072 # Applicationcan be edited1065 self.browser.getLink("Contracts").click() 1066 self.browser.getLink("Add contract").click() 1067 self.browser.getControl(name="apptype").value = ['SampleContract'] 1068 self.browser.getControl("Create contract").click() 1069 self.assertTrue('Sample Contract created.' in self.browser.contents) 1070 contract = self.customer['contracts']['a102'] 1071 1072 # Contract can be edited 1073 1073 self.browser.getLink("a102").click() 1074 1074 self.browser.getLink("Manage").click() … … 1078 1078 self.assertTrue('Form has been saved.' in self.browser.contents) 1079 1079 self.browser.getLink("View").click() 1080 self.assertEqual(self.browser.url, self. applications_path + '/a102/index')1080 self.assertEqual(self.browser.url, self.contracts_path + '/a102/index') 1081 1081 1082 1082 # Transitions can be performed … … 1086 1086 self.browser.getControl(name="transition").value = ['approve'] 1087 1087 self.browser.getControl("Save").click() 1088 self.assertEqual( application.state, 'approved')1089 1090 # Applications can be removed1091 self.browser.getLink(" Applications").click()1088 self.assertEqual(contract.state, 'approved') 1089 1090 # Contracts can be removed 1091 self.browser.getLink("Contracts").click() 1092 1092 ctrl = self.browser.getControl(name='val_id') 1093 ctrl.getControl(value= application.application_id).selected = True1093 ctrl.getControl(value=contract.contract_id).selected = True 1094 1094 self.browser.getControl("Remove selected", index=0).click() 1095 1095 self.assertTrue('Successfully removed' in self.browser.contents) … … 1100 1100 logcontent = open(logfile).read() 1101 1101 self.assertTrue( 1102 'INFO - zope.mgr - customers.browser. ApplicationManageFormPage '1102 'INFO - zope.mgr - customers.browser.ContractManageFormPage ' 1103 1103 '- K1000000 - a102 - saved: title' 1104 1104 in logcontent) 1105 1105 self.assertTrue( 1106 'INFO - zope.mgr - customers.browser. ApplicationAddFormPage '1107 '- K1000000 - added: Sample Application%s'1108 % application.application_id in logcontent)1109 self.assertTrue( 1110 'INFO - zope.mgr - customers.browser. ApplicationsManageFormPage '1106 'INFO - zope.mgr - customers.browser.ContractAddFormPage ' 1107 '- K1000000 - added: Sample Contract %s' 1108 % contract.contract_id in logcontent) 1109 self.assertTrue( 1110 'INFO - zope.mgr - customers.browser.ContractsManageFormPage ' 1111 1111 '- K1000000 - removed: %s' 1112 % application.application_id in logcontent)1113 1114 def test_edit_sample_ application(self):1112 % contract.contract_id in logcontent) 1113 1114 def test_edit_sample_contract(self): 1115 1115 # We add a second product. 1116 1116 product = createObject('waeup.Product') 1117 1117 product.product_id = u'LIC' 1118 1118 product.title = u'Our License Product' 1119 product. application_category = u'license'1119 product.contract_category = u'license' 1120 1120 self.app['products'].addProduct(product) 1121 # Customers can manage applications under certain conditions1121 # Customers can manage contracts under certain conditions 1122 1122 self.browser.open(self.login_path) 1123 1123 self.browser.getControl(name="form.login").value = self.customer_id … … 1126 1126 self.assertMatches( 1127 1127 '...You logged in...', self.browser.contents) 1128 self.browser.getLink(" Applications").click()1129 self.browser.getLink("Add application").click()1130 self.browser.getControl(name="apptype").value = ['Sample Application']1131 self.browser.getControl("Create application").click()1132 self.assertTrue('Sample Applicationcreated.' in self.browser.contents)1133 application = self.customer['applications']['a102']1134 # Applicationcan be edited ...1128 self.browser.getLink("Contracts").click() 1129 self.browser.getLink("Add contract").click() 1130 self.browser.getControl(name="apptype").value = ['SampleContract'] 1131 self.browser.getControl("Create contract").click() 1132 self.assertTrue('Sample Contract created.' in self.browser.contents) 1133 contract = self.customer['contracts']['a102'] 1134 # Contract can be edited ... 1135 1135 self.browser.getLink("a102").click() 1136 self.browser.open(self. applications_path + '/a102/edit')1136 self.browser.open(self.contracts_path + '/a102/edit') 1137 1137 #self.browser.getLink("Edit").click() 1138 1138 self.assertTrue('The requested form is locked' in self.browser.contents) 1139 1139 # Customer is in wrong state 1140 1140 IWorkflowState(self.customer).setState(APPROVED) 1141 self.browser.open(self. applications_path + '/a102/edit')1141 self.browser.open(self.contracts_path + '/a102/edit') 1142 1142 self.browser.getControl(name="form.title").value = 'My second app' 1143 # SAM is in the correct application_category ...1143 # SAM is in the correct contract_category ... 1144 1144 self.assertTrue('<option value="SAM">' in self.browser.contents) 1145 1145 # ... but NOTSAM not. 1146 1146 self.assertFalse('<option value="LIC">' in self.browser.contents) 1147 1147 # So far last_product_id is None. 1148 self.assertTrue(self.customer[' applications']['a102'].last_product_id is None)1148 self.assertTrue(self.customer['contracts']['a102'].last_product_id is None) 1149 1149 self.browser.getControl(name="form.product").value = ['SAM'] 1150 1150 self.browser.getControl("Save").click() 1151 1151 # After saving the form, last_product_id is set. 1152 self.assertEqual(self.customer[' applications']['a102'].last_product_id, 'SAM')1152 self.assertEqual(self.customer['contracts']['a102'].last_product_id, 'SAM') 1153 1153 self.assertTrue('Form has been saved.' in self.browser.contents) 1154 1154 # Saving the form again does not unset last_product_id 1155 self.assertEqual( application.title, 'My second app')1156 self.browser.getControl("Save").click() 1157 self.assertEqual(self.customer[' applications']['a102'].last_product_id, 'SAM')1155 self.assertEqual(contract.title, 'My second app') 1156 self.browser.getControl("Save").click() 1157 self.assertEqual(self.customer['contracts']['a102'].last_product_id, 'SAM') 1158 1158 self.assertTrue('Form has been saved.' in self.browser.contents) 1159 1159 self.browser.getLink("View").click() 1160 self.assertEqual(self.browser.url, self. applications_path + '/a102/index')1160 self.assertEqual(self.browser.url, self.contracts_path + '/a102/index') 1161 1161 # Customer can submit the form. The form is also saved. 1162 1162 self.browser.getLink("Edit").click() 1163 1163 self.browser.getControl(name="form.title").value = 'My third app' 1164 1164 self.browser.getControl("Apply now").click() 1165 self.assertEqual( application.title, 'My third app')1166 self.assertEqual( application.state, 'submitted')1167 self.assertTrue(' ApplicationState: submitted for approval' in self.browser.contents)1168 # Customer can't edit the applicationonce it has been submitted1169 self.browser.open(self. applications_path + '/a102/edit')1165 self.assertEqual(contract.title, 'My third app') 1166 self.assertEqual(contract.state, 'submitted') 1167 self.assertTrue('Contract State: submitted for approval' in self.browser.contents) 1168 # Customer can't edit the contract once it has been submitted 1169 self.browser.open(self.contracts_path + '/a102/edit') 1170 1170 self.assertTrue('The requested form is locked' in self.browser.contents) 1171 1171 1172 1172 def test_view_slips(self): 1173 1173 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 1174 # Officers can open the applicationoverview1175 self.browser.open(self.customer_path + '/ applications')1176 self.browser.getLink("Download applications overview").click()1174 # Officers can open the contract overview 1175 self.browser.open(self.customer_path + '/contracts') 1176 self.browser.getLink("Download contracts overview").click() 1177 1177 self.assertEqual(self.browser.headers['Status'], '200 Ok') 1178 1178 self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') 1179 path = os.path.join(samples_dir(), ' applications_overview_slip.pdf')1179 path = os.path.join(samples_dir(), 'contracts_overview_slip.pdf') 1180 1180 open(path, 'wb').write(self.browser.contents) 1181 1181 print "Sample PDF overview_slip.pdf written to %s" % path 1182 # Officers can open applicationslips1183 self.browser.open(self.customer_path + '/ applications/a101')1184 self.browser.getLink("Download applicationslip").click()1182 # Officers can open contract slips 1183 self.browser.open(self.customer_path + '/contracts/a101') 1184 self.browser.getLink("Download contract slip").click() 1185 1185 self.assertEqual(self.browser.headers['Status'], '200 Ok') 1186 1186 self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') 1187 path = os.path.join(samples_dir(), ' application_slip.pdf')1187 path = os.path.join(samples_dir(), 'contract_slip.pdf') 1188 1188 open(path, 'wb').write(self.browser.contents) 1189 print "Sample application_slip.pdf written to %s" % path1190 1189 print "Sample contract_slip.pdf written to %s" % path 1190 -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_catalog.py
r12095 r12097 27 27 from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase 28 28 from waeup.ikoba.customers.customer import Customer 29 from waeup.ikoba.customers. applications import SampleApplication29 from waeup.ikoba.customers.contracts import SampleContract 30 30 31 31 … … 61 61 product.product_id = u'SAM' 62 62 product.title = u'Our Samle Product' 63 product. application_category = u'sample'63 product.contract_category = u'sample' 64 64 self.app['products'].addProduct(product) 65 65 self.product_id = product.product_id 66 66 self.product = self.app['products'][self.product_id] 67 67 68 application = createObject('waeup.SampleApplication')69 application.title = u'My Samle Application'70 application.product = product71 application.last_product_id = product.product_id72 self.customer[' applications'].addApplication(application)73 self. application_id = application.application_id74 self. application = self.customer['applications'][self.application_id]68 contract = createObject('waeup.SampleContract') 69 contract.title = u'My Samle Contract' 70 contract.product = product 71 contract.last_product_id = product.product_id 72 self.customer['contracts'].addContract(contract) 73 self.contract_id = contract.contract_id 74 self.contract = self.customer['contracts'][self.contract_id] 75 75 76 76 document = createObject('waeup.CustomerSampleDocument') … … 125 125 126 126 def test_search_by_id(self): 127 # We can find a certain applicationid127 # We can find a certain contract id 128 128 cat = queryUtility(ICatalog, name='documents_catalog') 129 129 results = cat.searchResults(document_id=(self.document_id, … … 134 134 135 135 136 class ApplicationsCatalogTests(CatalogTestSetup):136 class ContractsCatalogTests(CatalogTestSetup): 137 137 138 138 layer = FunctionalLayer … … 140 140 def test_get_catalog(self): 141 141 # We can get an customers catalog if we wish 142 cat = queryUtility(ICatalog, name=' applications_catalog')142 cat = queryUtility(ICatalog, name='contracts_catalog') 143 143 assert cat is not None 144 144 145 145 def test_search_by_id(self): 146 # We can find a certain applicationid147 cat = queryUtility(ICatalog, name=' applications_catalog')148 results = cat.searchResults( application_id=(self.application_id,149 self. application_id))146 # We can find a certain contract id 147 cat = queryUtility(ICatalog, name='contracts_catalog') 148 results = cat.searchResults(contract_id=(self.contract_id, 149 self.contract_id)) 150 150 results = [x for x in results] # Turn results generator into list 151 151 assert len(results) == 1 152 assert results[0] is self.customer[' applications'][self.application_id]152 assert results[0] is self.customer['contracts'][self.contract_id] 153 153 154 154 def test_search_by_category(self): 155 155 # We can find a certain name 156 cat = queryUtility(ICatalog, name=' applications_catalog')157 results = cat.searchResults( application_category=('sample', 'sample'))156 cat = queryUtility(ICatalog, name='contracts_catalog') 157 results = cat.searchResults(contract_category=('sample', 'sample')) 158 158 results = [x for x in results] # Turn results generator into list 159 159 assert len(results) == 1 160 assert results[0] is self.customer[' applications'][self.application_id]160 assert results[0] is self.customer['contracts'][self.contract_id] 161 161 162 162 def test_search_by_last_product_id(self): 163 163 # We can find a certain name 164 cat = queryUtility(ICatalog, name=' applications_catalog')164 cat = queryUtility(ICatalog, name='contracts_catalog') 165 165 results = cat.searchResults(last_product_id=('SAM', 'SAM')) 166 166 results = [x for x in results] # Turn results generator into list 167 167 assert len(results) == 1 168 assert results[0] is self.customer[' applications'][self.application_id]168 assert results[0] is self.customer['contracts'][self.contract_id] 169 169 assert results[0].product is self.product 170 170 171 171 def test_product_removal(self): 172 172 # This test does not only test catalog components, it also ensures 173 # that the product attribute of an applicationis cleared173 # that the product attribute of an contract is cleared 174 174 # but the last_product_id is not. 175 175 del self.app['products'][self.product_id] 176 self.assertTrue(self. application.product is None)177 self.assertEqual(self. application.last_product_id, 'SAM')178 cat = queryUtility(ICatalog, name=' applications_catalog')176 self.assertTrue(self.contract.product is None) 177 self.assertEqual(self.contract.last_product_id, 'SAM') 178 cat = queryUtility(ICatalog, name='contracts_catalog') 179 179 results = cat.searchResults(last_product_id=('SAM', 'SAM')) 180 180 results = [x for x in results] 181 181 assert len(results) == 1 182 assert results[0] is self.customer[' applications'][self.application_id]182 assert results[0] is self.customer['contracts'][self.contract_id] 183 183 assert results[0].product is None 184 184 # Product removal is being logged in customers.log -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_contract.py
r12096 r12097 17 17 ## 18 18 """ 19 Tests for applications.19 Tests for contracts. 20 20 """ 21 21 from zope.interface.verify import verifyClass, verifyObject … … 24 24 IWorkflowInfo, IWorkflowState, InvalidTransitionError) 25 25 from waeup.ikoba.customers.interfaces import ( 26 I ApplicationsContainer, IApplication)26 IContractsContainer, IContract) 27 27 from waeup.ikoba.interfaces import IObjectHistory 28 from waeup.ikoba.customers. applications import (29 ApplicationsContainer, SampleApplication)28 from waeup.ikoba.customers.contracts import ( 29 ContractsContainer, SampleContract) 30 30 from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase) 31 31 32 class ApplicationsContainerTestCase(FunctionalTestCase):32 class ContractsContainerTestCase(FunctionalTestCase): 33 33 34 34 layer = FunctionalLayer … … 38 38 self.assertTrue( 39 39 verifyClass( 40 I ApplicationsContainer, ApplicationsContainer)40 IContractsContainer, ContractsContainer) 41 41 ) 42 42 self.assertTrue( 43 43 verifyObject( 44 I ApplicationsContainer, ApplicationsContainer())44 IContractsContainer, ContractsContainer()) 45 45 ) 46 46 self.assertTrue( 47 47 verifyClass( 48 I Application, SampleApplication)48 IContract, SampleContract) 49 49 ) 50 50 self.assertTrue( 51 51 verifyObject( 52 I Application, SampleApplication())52 IContract, SampleContract()) 53 53 ) 54 54 return 55 55 56 def test_add Application(self):57 container = ApplicationsContainer()58 application = createObject(u'waeup.SampleApplication')59 id = application.application_id60 container.add Application(application)61 self.assertEqual(container[id], application)62 self.assertRaises(TypeError, container.add Application, object())63 self.assertEqual( application.class_name, 'SampleApplication')56 def test_addContract(self): 57 container = ContractsContainer() 58 contract = createObject(u'waeup.SampleContract') 59 id = contract.contract_id 60 container.addContract(contract) 61 self.assertEqual(container[id], contract) 62 self.assertRaises(TypeError, container.addContract, object()) 63 self.assertEqual(contract.class_name, 'SampleContract') 64 64 self.assertEqual(id, 'a123') 65 65 return 66 66 67 def test_ application_workflow(self):68 application = createObject(u'waeup.SampleApplication')69 IWorkflowInfo( application).fireTransition('create')70 self.assertEqual(IWorkflowState( application).getState(), 'created')71 IWorkflowInfo( application).fireTransition('submit')72 self.assertEqual(IWorkflowState( application).getState(), 'submitted')73 IWorkflowInfo( application).fireTransition('approve')74 self.assertEqual(IWorkflowState( application).getState(), 'approved')75 IWorkflowInfo( application).fireTransition('expire')76 self.assertEqual(IWorkflowState( application).getState(), 'expired')77 IWorkflowInfo( application).fireTransition('reset4')78 self.assertEqual(IWorkflowState( application).getState(), 'created')67 def test_contract_workflow(self): 68 contract = createObject(u'waeup.SampleContract') 69 IWorkflowInfo(contract).fireTransition('create') 70 self.assertEqual(IWorkflowState(contract).getState(), 'created') 71 IWorkflowInfo(contract).fireTransition('submit') 72 self.assertEqual(IWorkflowState(contract).getState(), 'submitted') 73 IWorkflowInfo(contract).fireTransition('approve') 74 self.assertEqual(IWorkflowState(contract).getState(), 'approved') 75 IWorkflowInfo(contract).fireTransition('expire') 76 self.assertEqual(IWorkflowState(contract).getState(), 'expired') 77 IWorkflowInfo(contract).fireTransition('reset4') 78 self.assertEqual(IWorkflowState(contract).getState(), 'created') 79 79 self.assertRaises(InvalidTransitionError, 80 IWorkflowInfo( application).fireTransition, 'approve')81 IWorkflowInfo( application).fireTransition('submit')82 IWorkflowInfo( application).fireTransition('reset3')83 self.assertEqual(IWorkflowState( application).getState(), 'created')80 IWorkflowInfo(contract).fireTransition, 'approve') 81 IWorkflowInfo(contract).fireTransition('submit') 82 IWorkflowInfo(contract).fireTransition('reset3') 83 self.assertEqual(IWorkflowState(contract).getState(), 'created') 84 84 return 85 85 86 def test_ application_history(self):87 doc = createObject(u'waeup.Sample Application')86 def test_contract_history(self): 87 doc = createObject(u'waeup.SampleContract') 88 88 IWorkflowInfo(doc).fireTransition('create') 89 89 messages = ' '.join(doc.history.messages) 90 self.assertTrue(' Applicationrecord created by system' in messages)90 self.assertTrue('Contract record created by system' in messages) 91 91 return
Note: See TracChangeset for help on using the changeset viewer.