Ignore:
Timestamp:
29 Nov 2014, 12:39:00 (10 years ago)
Author:
Henrik Bettermann
Message:

Add browser tests and fix.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12069 r12091  
    107107        document.title = u'My first document'
    108108        self.customer['documents'].addDocument(document)
     109        application = createObject('waeup.SampleApplication')
     110        application.title = u'My first application'
     111        self.customer['applications'].addApplication(application)
    109112
    110113        # Set password
     
    121124        self.history_path = self.customer_path + '/history'
    122125        self.documents_path = self.customer_path + '/documents'
     126        self.applications_path = self.customer_path + '/applications'
    123127
    124128        self.app['configuration'].carry_over = True
     
    849853        self.assertTrue(
    850854            'INFO - zope.mgr - customers.browser.DocumentManageFormPage '
    851             '- K1000000 - saved: title'
     855            '- K1000000 - saved d102: title'
    852856            in logcontent)
    853 
    854857        self.assertTrue(
    855858            'INFO - zope.mgr - customers.browser.DocumentAddFormPage '
    856859            '- K1000000 - added: PDF Document %s'
    857860            % document.document_id in logcontent)
    858 
    859861        self.assertTrue(
    860862            'INFO - zope.mgr - customers.browser.DocumentsManageFormPage '
     
    10301032        self.assertEqual(self.browser.headers['Status'], '200 Ok')
    10311033        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
    1032         path = os.path.join(samples_dir(), 'overview_slip.pdf')
     1034        path = os.path.join(samples_dir(), 'documents_overview_slip.pdf')
    10331035        open(path, 'wb').write(self.browser.contents)
    10341036        print "Sample PDF overview_slip.pdf written to %s" % path
     
    10411043        open(path, 'wb').write(self.browser.contents)
    10421044        print "Sample document_slip.pdf written to %s" % path
     1045
     1046
     1047class ApplicationUITests(CustomersFullSetup):
     1048    # Tests for CustomerSampleApplication relates views and pages
     1049
     1050    def test_manage_application(self):
     1051        # Managers can access the pages of customer applicationsconter
     1052        # and can perform actions
     1053        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     1054        self.browser.open(self.customer_path)
     1055        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     1056        self.assertEqual(self.browser.url, self.customer_path)
     1057        self.browser.open(self.customer_path)
     1058        self.browser.getLink("Applications").click()
     1059        self.browser.getLink("Add application").click()
     1060        self.browser.getControl(name="apptype").value = ['SampleApplication']
     1061        self.browser.getControl("Create application").click()
     1062        self.assertTrue('Sample Application created.' in self.browser.contents)
     1063        application = self.customer['applications']['a102']
     1064
     1065        # Application can be edited
     1066        self.browser.getLink("a102").click()
     1067        self.browser.getLink("Manage").click()
     1068        self.browser.getControl(name="form.title").value = 'My second app'
     1069        self.browser.getControl("Save").click()
     1070        self.assertTrue('Form has been saved.' in self.browser.contents)
     1071        self.browser.getLink("View").click()
     1072        self.assertEqual(self.browser.url, self.applications_path + '/a102/index')
     1073
     1074        # Transitions can be performed
     1075        self.browser.getLink("Transition").click()
     1076        self.browser.getControl(name="transition").value = ['submit']
     1077        self.browser.getControl("Save").click()
     1078        self.browser.getControl(name="transition").value = ['approve']
     1079        self.browser.getControl("Save").click()
     1080        self.assertEqual(application.state, 'approved')
     1081
     1082        # Applications can be removed
     1083        self.browser.getLink("Applications").click()
     1084        ctrl = self.browser.getControl(name='val_id')
     1085        ctrl.getControl(value=application.application_id).selected = True
     1086        self.browser.getControl("Remove selected", index=0).click()
     1087        self.assertTrue('Successfully removed' in self.browser.contents)
     1088
     1089        # All actions are being logged
     1090        logfile = os.path.join(
     1091            self.app['datacenter'].storage, 'logs', 'customers.log')
     1092        logcontent = open(logfile).read()
     1093        self.assertTrue(
     1094            'INFO - zope.mgr - customers.browser.ApplicationManageFormPage '
     1095            '- K1000000 - saved a102: title'
     1096            in logcontent)
     1097        self.assertTrue(
     1098            'INFO - zope.mgr - customers.browser.ApplicationAddFormPage '
     1099            '- K1000000 - added: Sample Application %s'
     1100            % application.application_id in logcontent)
     1101        self.assertTrue(
     1102            'INFO - zope.mgr - customers.browser.ApplicationsManageFormPage '
     1103            '- K1000000 - removed: %s'
     1104            % application.application_id in logcontent)
     1105
     1106    def test_edit_sample_application(self):
     1107        # Customers can manage applications under certain conditions
     1108        self.browser.open(self.login_path)
     1109        self.browser.getControl(name="form.login").value = self.customer_id
     1110        self.browser.getControl(name="form.password").value = 'cpwd'
     1111        self.browser.getControl("Login").click()
     1112        self.assertMatches(
     1113            '...You logged in...', self.browser.contents)
     1114        self.browser.getLink("Applications").click()
     1115        self.browser.getLink("Add application").click()
     1116        self.browser.getControl(name="apptype").value = ['SampleApplication']
     1117        self.browser.getControl("Create application").click()
     1118        self.assertTrue('Sample Application created.' in self.browser.contents)
     1119        application = self.customer['applications']['a102']
     1120
     1121        # Application can be edited ...
     1122        self.browser.getLink("a102").click()
     1123        self.browser.open(self.applications_path + '/a102/edit')
     1124        #self.browser.getLink("Edit").click()
     1125        self.assertTrue('The requested form is locked' in self.browser.contents)
     1126        # Customer is in wrong state
     1127        IWorkflowState(self.customer).setState(APPROVED)
     1128        self.browser.open(self.applications_path + '/a102/edit')
     1129        self.browser.getControl(name="form.title").value = 'My second app'
     1130        self.browser.getControl("Save").click()
     1131        self.assertEqual(application.title, 'My second app')
     1132        self.assertTrue('Form has been saved.' in self.browser.contents)
     1133        self.browser.getLink("View").click()
     1134        self.assertEqual(self.browser.url, self.applications_path + '/a102/index')
     1135        # Customer can submit the form. The form is also saved.
     1136        self.browser.getLink("Edit").click()
     1137        self.browser.getControl(name="form.title").value = 'My third app'
     1138        self.browser.getControl("Final Submit").click()
     1139        self.assertEqual(application.title, 'My third app')
     1140        self.assertEqual(application.state, 'submitted')
     1141        self.assertTrue('Application State: submitted for approval' in self.browser.contents)
     1142        # Customer can't edit the application once it has been submitted
     1143        self.browser.open(self.applications_path + '/a102/edit')
     1144        self.assertTrue('The requested form is locked' in self.browser.contents)
     1145
     1146    def test_view_slips(self):
     1147        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     1148        # Officers can open the application overview
     1149        self.browser.open(self.customer_path + '/applications')
     1150        self.browser.getLink("Download applications overview").click()
     1151        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     1152        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
     1153        path = os.path.join(samples_dir(), 'applications_overview_slip.pdf')
     1154        open(path, 'wb').write(self.browser.contents)
     1155        print "Sample PDF overview_slip.pdf written to %s" % path
     1156        # Officers can open application slips
     1157        self.browser.open(self.customer_path + '/applications/a101')
     1158        self.browser.getLink("Download application slip").click()
     1159        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     1160        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
     1161        path = os.path.join(samples_dir(), 'application_slip.pdf')
     1162        open(path, 'wb').write(self.browser.contents)
     1163        print "Sample application_slip.pdf written to %s" % path
     1164
Note: See TracChangeset for help on using the changeset viewer.