- Timestamp:
- 19 Jul 2017, 19:16:36 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/kofacustom.dspg/trunk/src/kofacustom/dspg/applicants/tests/test_browser.py
r14716 r14721 19 19 Test the applicant-related UI components. 20 20 """ 21 import shutil 22 import tempfile 23 import datetime 24 import pytz 21 25 import os 22 import datetime26 from zope.component.hooks import setSite, clearSite 23 27 from zope.component import createObject, getUtility 24 28 from zope.catalog.interfaces import ICatalog 25 29 from zope.intid.interfaces import IIntIds 26 from hurry.workflow.interfaces import IWorkflowState30 from zope.testbrowser.testing import Browser 27 31 from kofacustom.dspg.testing import FunctionalLayer 28 from waeup.kofa.browser.tests.test_pdf import samples_dir 29 from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup 32 from waeup.kofa.app import University 33 from waeup.kofa.university.faculty import Faculty 34 from waeup.kofa.university.department import Department 35 from waeup.kofa.testing import FunctionalTestCase 30 36 from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup 31 from kofacustom.dspg.applicants.export import CustomApplicantExporter 32 from kofacustom.dspg.applicants.batching import CustomApplicantProcessor 37 from waeup.kofa.applicants.container import ApplicantsContainer 33 38 34 class CustomApplicantUITests(ApplicantsFullSetup): 35 # Tests for uploading/browsing the passport image of appplicants 39 session = datetime.datetime.now().year - 2 40 ndftcontainer_name = u'ndft%s' % session 36 41 42 class ApplicantUITest(FunctionalTestCase): 43 """Perform some browser tests. 44 """ 37 45 layer = FunctionalLayer 46 47 def setUp(self): 48 super(ApplicantUITest, self).setUp() 49 # Setup a sample site for each test 50 app = University() 51 self.dc_root = tempfile.mkdtemp() 52 app['datacenter'].setStoragePath(self.dc_root) 53 54 # Prepopulate the ZODB... 55 self.getRootFolder()['app'] = app 56 # we add the site immediately after creation to the 57 # ZODB. Catalogs and other local utilities are not setup 58 # before that step. 59 self.app = self.getRootFolder()['app'] 60 # Set site here. Some of the following setup code might need 61 # to access grok.getSite() and should get our new app then 62 setSite(app) 63 64 # Add ndft applicants container 65 self.ndftcontainer = ApplicantsContainer() 66 self.ndftcontainer.mode = 'create' 67 self.ndftcontainer.code = ndftcontainer_name 68 self.ndftcontainer.prefix = u'ndft' 69 self.ndftcontainer.application_category = u'ndft' 70 self.ndftcontainer.year = session 71 self.ndftcontainer.application_fee = 300.0 72 #self.ndftcontainer.title = u'This is the %s container' % ndftcontainer_name 73 self.app['applicants'][ndftcontainer_name] = self.ndftcontainer 74 75 delta = datetime.timedelta(days=10) 76 self.ndftcontainer.startdate = datetime.datetime.now(pytz.utc) - delta 77 self.ndftcontainer.enddate = datetime.datetime.now(pytz.utc) + delta 78 79 # Populate university 80 self.certificate = createObject('waeup.Certificate') 81 self.certificate.code = 'CERT1' 82 self.certificate.application_category = 'ndft' 83 self.certificate.start_level = 100 84 self.certificate.end_level = 500 85 self.certificate.study_mode = u'nce_ft' 86 self.app['faculties']['fac1'] = Faculty() 87 self.app['faculties']['fac1']['dep1'] = Department() 88 self.app['faculties']['fac1']['dep1'].certificates.addCertificate( 89 self.certificate) 90 91 # Add (customized) applicants 92 ndftapplicant = createObject(u'waeup.Applicant') 93 ndftapplicant.firstname = u'Anna' 94 ndftapplicant.lastname = u'Post' 95 self.app['applicants'][ndftcontainer_name].addApplicant(ndftapplicant) 96 self.ndftapplication_number = ndftapplicant.application_number 97 self.ndftapplicant = self.app['applicants'][ndftcontainer_name][ 98 self.ndftapplication_number] 99 self.ndftapplicant_path = ('http://localhost/app/applicants/%s/%s' 100 % (ndftcontainer_name, self.ndftapplication_number)) 101 102 self.browser = Browser() 103 self.browser.handleErrors = False 104 105 def tearDown(self): 106 super(ApplicantUITest, self).tearDown() 107 shutil.rmtree(self.dc_root) 108 clearSite() 109 return 110 111 def fill_correct_values(self): 112 self.browser.getControl(name="form.reg_number").value = '1234' 113 self.browser.getControl(name="form.firstname").value = 'John' 114 self.browser.getControl(name="form.lastname").value = 'Tester' 115 self.browser.getControl(name="form.date_of_birth").value = '09/09/1988' 116 self.browser.getControl(name="form.lga").value = ['foreigner'] 117 #self.browser.getControl(name="form.nationality").value = ['NG'] 118 #self.browser.getControl(name="form.sex").value = ['m'] 119 self.browser.getControl(name="form.email").value = 'xx@yy.zz' 120 121 def test_manage_and_view_applicant(self): 122 # Managers can manage ndft applicants. 123 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 124 self.browser.open(self.ndftapplicant_path) 125 self.assertEqual(self.browser.headers['Status'], '200 Ok') 126 self.assertTrue("'O' Level" in self.browser.contents) 127 self.assertFalse("Higher" in self.browser.contents) 128 self.browser.open(self.ndftapplicant_path + '/manage') 129 self.assertEqual(self.browser.headers['Status'], '200 Ok') 130 self.assertTrue("'O' Level" in self.browser.contents) 131 self.assertTrue("Higher" in self.browser.contents) 132 self.browser.open(self.ndftapplicant_path + '/edit') 133 self.assertEqual(self.browser.headers['Status'], '200 Ok') 134 self.assertTrue("'O' Level" in self.browser.contents) 135 self.assertFalse("Higher" in self.browser.contents) 136 self.browser.open(self.ndftapplicant_path + '/application_slip.pdf') 137 self.assertEqual(self.browser.headers['Status'], '200 Ok') 138 # Now we turn the ndft applicant into an hndft applicant. 139 self.ndftapplicant.applicant_id = u'hndft_anything' 140 self.browser.open(self.ndftapplicant_path) 141 self.assertTrue("Higher" in self.browser.contents) 142 self.assertTrue("'O' Level" in self.browser.contents) 143 self.browser.open(self.ndftapplicant_path + '/edit') 144 self.assertTrue("Higher" in self.browser.contents) 145 self.assertTrue("'O' Level" in self.browser.contents) 146 147 self.browser.open(self.ndftapplicant_path + '/manage') 148 # Manager can fill and save the form 149 self.fill_correct_values() 150 self.browser.getControl("Save").click() 151 self.assertMatches('...Form has been saved...', self.browser.contents) 152 return 38 153 39 154 class ApplicantExporterTest(ApplicantImportExportSetup): … … 69 184 applicant.password = 'any password' 70 185 return applicant 71 72 class ApplicantsContainerUITests(ApplicantsFullSetup):73 # Tests for ApplicantsContainer class views and pages74 75 layer = FunctionalLayer76 77 def test_application_slip(self):78 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')79 self.slip_path = self.view_path + '/application_slip.pdf'80 self.browser.open(self.manage_path)81 self.assertEqual(self.browser.headers['Status'], '200 Ok')82 self.fill_correct_values()83 self.browser.getControl("Save").click()84 IWorkflowState(self.applicant).setState('submitted')85 self.browser.open(self.manage_path)86 self.browser.getLink("Download application slip").click()87 self.assertEqual(self.browser.headers['Status'], '200 Ok')88 self.assertEqual(self.browser.headers['Content-Type'],89 'application/pdf')90 path = os.path.join(samples_dir(), 'application_slip.pdf')91 open(path, 'wb').write(self.browser.contents)92 print "Sample application_slip.pdf written to %s" % path
Note: See TracChangeset for help on using the changeset viewer.