Index: main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/browser.py
===================================================================
--- main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/browser.py	(revision 14448)
+++ main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/browser.py	(revision 14499)
@@ -28,4 +28,6 @@
 from waeup.kofa.interfaces import IKofaUtils
 from waeup.kofa.browser.interfaces import IPDFCreator
+from waeup.kofa.applicants.workflow import (
+    SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED)
 
 from kofacustom.nigeria.applicants.browser import (
@@ -194,2 +196,23 @@
         form_fields['reg_number'].for_display = True
         return form_fields
+
+    @property
+    def _student_per_school_exceeded(self):
+        container = self.context.__parent__
+        counter = 0
+        if self.context.school1:
+            for appl in container.values():
+                if appl.state in (SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED) \
+                    and appl.school1 == self.context.school1:
+                    counter += 1
+                    if counter == 20:
+                        return True
+        return False
+
+    def dataNotComplete(self):
+        if self._student_per_school_exceeded:
+            return ("1st Choice TPZ and School: "
+                    "Maximum number of applications per school exceeded. "
+                    "Please select another first choice school.")
+        super(CustomApplicantEditFormPage, self).dataNotComplete()
+        return
Index: main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/interfaces.py
===================================================================
--- main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/interfaces.py	(revision 14448)
+++ main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/interfaces.py	(revision 14499)
@@ -57,5 +57,5 @@
 
 class SchoolSource(BasicSourceFactory):
-    """A source that delivers all kinds of registrations.
+    """A source that delivers all kinds of schools.
     """
     def getValues(self):
@@ -65,4 +65,7 @@
         return [item[0] for item in sorted_items]
 
+    def getToken(self, value):
+        return value
+
     def getTitle(self, value):
         return u"%s: %s -- %s" % (
@@ -153,5 +156,5 @@
         title = _(u'1st Choice TPZ and School'),
         source = SchoolSource(),
-        required = False,
+        required = True,
         )
 
Index: main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/tests/test_browser.py
===================================================================
--- main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/tests/test_browser.py	(revision 14448)
+++ main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/tests/test_browser.py	(revision 14499)
@@ -20,15 +20,20 @@
 import datetime
 import pytz
+import os
 from zope.component.hooks import setSite, clearSite
 from zope.component import createObject
 from zope.testbrowser.testing import Browser
+from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
 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.interfaces import (
+    IExtFileStore, IFileStoreNameChooser, IUserAccount, IJobManager)
 from waeup.kofa.applicants.container import ApplicantsContainer
 from waeup.fceokene.testing import FunctionalLayer
 
 session = datetime.datetime.now().year - 2
+SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg')
 
 class ApplicantUITest(FunctionalTestCase):
@@ -53,4 +58,6 @@
         # to access grok.getSite() and should get our new app then
         setSite(app)
+
+        self.login_path = 'http://localhost/app/login'
 
         # Add bec applicants container
@@ -82,4 +89,18 @@
         self.putmecontainer.enddate = datetime.datetime.now(pytz.utc) + delta
 
+        # Add tpu applicants container
+        self.tpucontainer = ApplicantsContainer()
+        self.tpucontainer.mode = 'create'
+        self.tpucontainer.code = u'tpu%s' % session
+        self.tpucontainer.prefix = u'tpu'
+        self.tpucontainer.application_category = u'no'
+        self.tpucontainer.year = session
+        self.tpucontainer.application_fee = 300.0
+        self.tpucontainer.title = u'This is the tpu%s container' % session
+        self.app['applicants'][self.tpucontainer.code] = self.tpucontainer
+        delta = datetime.timedelta(days=10)
+        self.tpucontainer.startdate = datetime.datetime.now(pytz.utc) - delta
+        self.tpucontainer.enddate = datetime.datetime.now(pytz.utc) + delta
+
         # Populate university
         self.certificate = createObject('waeup.Certificate')
@@ -115,4 +136,17 @@
             % (session, self.putmeapplication_number))
 
+        tpuapplicant = createObject(u'waeup.Applicant')
+        tpuapplicant.firstname = u'Michelle'
+        tpuapplicant.lastname = u'Obama'
+        self.app['applicants'][self.tpucontainer.code].addApplicant(tpuapplicant)
+        self.tpuapplication_number = tpuapplicant.application_number
+        self.tpuapplicant = self.app['applicants'][self.tpucontainer.code][
+            self.tpuapplication_number]
+        self.tpuapplicant_path = ('http://localhost/app/applicants/tpu%s/%s'
+            % (session, self.tpuapplication_number))
+        IUserAccount(
+            self.app['applicants'][self.tpucontainer.code][
+            self.tpuapplicant.application_number]).setPassword('apwd')
+
         self.browser = Browser()
         self.browser.handleErrors = False
@@ -124,14 +158,4 @@
         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_bec_applicant(self):
         # Managers can manage bec applicants.
@@ -164,3 +188,41 @@
         self.browser.open(self.putmeapplicant_path + '/application_slip.pdf')
         self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        
+
+    def test_final_submit_tpu(self):
+        IWorkflowState(self.tpuapplicant).setState('paid')
+        self.browser.open(self.login_path)
+        self.browser.getControl(
+            name="form.login").value = self.tpuapplicant.applicant_id
+        self.browser.getControl(name="form.password").value = 'apwd'
+        self.browser.getControl("Login").click()
+        self.browser.open(self.tpuapplicant_path + '/edit')
+        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
+        self.browser.getControl(name="form.school1").value = ['s0010']
+        image = open(SAMPLE_IMAGE, 'rb')
+        ctrl = self.browser.getControl(name='form.passport')
+        file_ctrl = ctrl.mech_control
+        file_ctrl.add_file(image, filename='myphoto.jpg')
+        self.browser.getControl(name="confirm_passport").value = True
+        self.browser.getControl("Save").click()
+        self.browser.getControl("Finally Submit").click()
+        self.assertTrue(
+            'Application submitted' in self.browser.contents)
+        # Create 20 applicants who already selected s0010
+        for i in range(1,21):
+            tpuapplicant = createObject(u'waeup.Applicant')
+            tpuapplicant.firstname = u'John'
+            tpuapplicant.lastname = u'Doe %s' %i
+            tpuapplicant.school1 = 's0010'
+            self.app['applicants'][
+                self.tpucontainer.code].addApplicant(tpuapplicant)
+            IWorkflowState(tpuapplicant).setState('submitted')
+        IWorkflowState(self.tpuapplicant).setState('paid')
+        self.tpuapplicant.locked = False
+        self.browser.open(self.tpuapplicant_path + '/edit')
+        self.browser.getControl("Finally Submit").click()
+        self.assertTrue("Maximum number of applications per school exceeded."
+            in self.browser.contents)
+        self.assertEqual(self.tpuapplicant.state, 'paid')
         return
+
