Index: main/kofacustom.dspg/trunk/src/kofacustom/dspg/applicants/tests/test_browser.py
===================================================================
--- main/kofacustom.dspg/trunk/src/kofacustom/dspg/applicants/tests/test_browser.py	(revision 14716)
+++ main/kofacustom.dspg/trunk/src/kofacustom/dspg/applicants/tests/test_browser.py	(revision 14721)
@@ -19,21 +19,136 @@
 Test the applicant-related UI components.
 """
+import shutil
+import tempfile
+import datetime
+import pytz
 import os
-import datetime
+from zope.component.hooks import setSite, clearSite
 from zope.component import createObject, getUtility
 from zope.catalog.interfaces import ICatalog
 from zope.intid.interfaces import IIntIds
-from hurry.workflow.interfaces import IWorkflowState
+from zope.testbrowser.testing import Browser
 from kofacustom.dspg.testing import FunctionalLayer
-from waeup.kofa.browser.tests.test_pdf import samples_dir
-from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
+from waeup.kofa.app import University
+from waeup.kofa.university.faculty import Faculty
+from waeup.kofa.university.department import Department
+from waeup.kofa.testing import FunctionalTestCase
 from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup
-from kofacustom.dspg.applicants.export import CustomApplicantExporter
-from kofacustom.dspg.applicants.batching import CustomApplicantProcessor
+from waeup.kofa.applicants.container import ApplicantsContainer
 
-class CustomApplicantUITests(ApplicantsFullSetup):
-    # Tests for uploading/browsing the passport image of appplicants
+session = datetime.datetime.now().year - 2
+ndftcontainer_name = u'ndft%s' % session
 
+class ApplicantUITest(FunctionalTestCase):
+    """Perform some browser tests.
+    """
     layer = FunctionalLayer
+
+    def setUp(self):
+        super(ApplicantUITest, self).setUp()
+        # Setup a sample site for each test
+        app = University()
+        self.dc_root = tempfile.mkdtemp()
+        app['datacenter'].setStoragePath(self.dc_root)
+
+        # Prepopulate the ZODB...
+        self.getRootFolder()['app'] = app
+        # we add the site immediately after creation to the
+        # ZODB. Catalogs and other local utilities are not setup
+        # before that step.
+        self.app = self.getRootFolder()['app']
+        # Set site here. Some of the following setup code might need
+        # to access grok.getSite() and should get our new app then
+        setSite(app)
+
+        # Add ndft applicants container
+        self.ndftcontainer = ApplicantsContainer()
+        self.ndftcontainer.mode = 'create'
+        self.ndftcontainer.code = ndftcontainer_name
+        self.ndftcontainer.prefix = u'ndft'
+        self.ndftcontainer.application_category = u'ndft'
+        self.ndftcontainer.year = session
+        self.ndftcontainer.application_fee = 300.0
+        #self.ndftcontainer.title = u'This is the %s container' % ndftcontainer_name
+        self.app['applicants'][ndftcontainer_name] = self.ndftcontainer
+
+        delta = datetime.timedelta(days=10)
+        self.ndftcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
+        self.ndftcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
+
+        # Populate university
+        self.certificate = createObject('waeup.Certificate')
+        self.certificate.code = 'CERT1'
+        self.certificate.application_category = 'ndft'
+        self.certificate.start_level = 100
+        self.certificate.end_level = 500
+        self.certificate.study_mode = u'nce_ft'
+        self.app['faculties']['fac1'] = Faculty()
+        self.app['faculties']['fac1']['dep1'] = Department()
+        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
+            self.certificate)
+
+        # Add (customized) applicants
+        ndftapplicant = createObject(u'waeup.Applicant')
+        ndftapplicant.firstname = u'Anna'
+        ndftapplicant.lastname = u'Post'
+        self.app['applicants'][ndftcontainer_name].addApplicant(ndftapplicant)
+        self.ndftapplication_number = ndftapplicant.application_number
+        self.ndftapplicant = self.app['applicants'][ndftcontainer_name][
+            self.ndftapplication_number]
+        self.ndftapplicant_path = ('http://localhost/app/applicants/%s/%s'
+            % (ndftcontainer_name, self.ndftapplication_number))
+
+        self.browser = Browser()
+        self.browser.handleErrors = False
+
+    def tearDown(self):
+        super(ApplicantUITest, self).tearDown()
+        shutil.rmtree(self.dc_root)
+        clearSite()
+        return
+
+    def fill_correct_values(self):
+        self.browser.getControl(name="form.reg_number").value = '1234'
+        self.browser.getControl(name="form.firstname").value = 'John'
+        self.browser.getControl(name="form.lastname").value = 'Tester'
+        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
+        self.browser.getControl(name="form.lga").value = ['foreigner']
+        #self.browser.getControl(name="form.nationality").value = ['NG']
+        #self.browser.getControl(name="form.sex").value = ['m']
+        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
+
+    def test_manage_and_view_applicant(self):
+        # Managers can manage ndft applicants.
+        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+        self.browser.open(self.ndftapplicant_path)
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        self.assertTrue("'O' Level" in self.browser.contents)
+        self.assertFalse("Higher" in self.browser.contents)
+        self.browser.open(self.ndftapplicant_path + '/manage')
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        self.assertTrue("'O' Level" in self.browser.contents)
+        self.assertTrue("Higher" in self.browser.contents)
+        self.browser.open(self.ndftapplicant_path + '/edit')
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        self.assertTrue("'O' Level" in self.browser.contents)
+        self.assertFalse("Higher" in self.browser.contents)
+        self.browser.open(self.ndftapplicant_path + '/application_slip.pdf')
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        # Now we turn the ndft applicant into an hndft applicant.
+        self.ndftapplicant.applicant_id = u'hndft_anything'
+        self.browser.open(self.ndftapplicant_path)
+        self.assertTrue("Higher" in self.browser.contents)
+        self.assertTrue("'O' Level" in self.browser.contents)
+        self.browser.open(self.ndftapplicant_path + '/edit')
+        self.assertTrue("Higher" in self.browser.contents)
+        self.assertTrue("'O' Level" in self.browser.contents)
+
+        self.browser.open(self.ndftapplicant_path + '/manage')
+        # Manager can fill and save the form
+        self.fill_correct_values()
+        self.browser.getControl("Save").click()
+        self.assertMatches('...Form has been saved...', self.browser.contents)
+        return
 
 class ApplicantExporterTest(ApplicantImportExportSetup):
@@ -69,24 +184,2 @@
         applicant.password = 'any password'
         return applicant
-
-class ApplicantsContainerUITests(ApplicantsFullSetup):
-    # Tests for ApplicantsContainer class views and pages
-
-    layer = FunctionalLayer
-
-    def test_application_slip(self):
-        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
-        self.slip_path = self.view_path + '/application_slip.pdf'
-        self.browser.open(self.manage_path)
-        self.assertEqual(self.browser.headers['Status'], '200 Ok')
-        self.fill_correct_values()
-        self.browser.getControl("Save").click()
-        IWorkflowState(self.applicant).setState('submitted')
-        self.browser.open(self.manage_path)
-        self.browser.getLink("Download application slip").click()
-        self.assertEqual(self.browser.headers['Status'], '200 Ok')
-        self.assertEqual(self.browser.headers['Content-Type'],
-                         'application/pdf')
-        path = os.path.join(samples_dir(), 'application_slip.pdf')
-        open(path, 'wb').write(self.browser.contents)
-        print "Sample application_slip.pdf written to %s" % path
