Ignore:
Timestamp:
3 Feb 2017, 07:54:44 (8 years ago)
Author:
Henrik Bettermann
Message:

Restrict maximum number of applications per school.

Location:
main/waeup.fceokene/trunk/src/waeup/fceokene/applicants
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/browser.py

    r13877 r14499  
    2828from waeup.kofa.interfaces import IKofaUtils
    2929from waeup.kofa.browser.interfaces import IPDFCreator
     30from waeup.kofa.applicants.workflow import (
     31    SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED)
    3032
    3133from kofacustom.nigeria.applicants.browser import (
     
    194196        form_fields['reg_number'].for_display = True
    195197        return form_fields
     198
     199    @property
     200    def _student_per_school_exceeded(self):
     201        container = self.context.__parent__
     202        counter = 0
     203        if self.context.school1:
     204            for appl in container.values():
     205                if appl.state in (SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED) \
     206                    and appl.school1 == self.context.school1:
     207                    counter += 1
     208                    if counter == 20:
     209                        return True
     210        return False
     211
     212    def dataNotComplete(self):
     213        if self._student_per_school_exceeded:
     214            return ("1st Choice TPZ and School: "
     215                    "Maximum number of applications per school exceeded. "
     216                    "Please select another first choice school.")
     217        super(CustomApplicantEditFormPage, self).dataNotComplete()
     218        return
  • main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/interfaces.py

    r14335 r14499  
    5757
    5858class SchoolSource(BasicSourceFactory):
    59     """A source that delivers all kinds of registrations.
     59    """A source that delivers all kinds of schools.
    6060    """
    6161    def getValues(self):
     
    6565        return [item[0] for item in sorted_items]
    6666
     67    def getToken(self, value):
     68        return value
     69
    6770    def getTitle(self, value):
    6871        return u"%s: %s -- %s" % (
     
    153156        title = _(u'1st Choice TPZ and School'),
    154157        source = SchoolSource(),
    155         required = False,
     158        required = True,
    156159        )
    157160
  • main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/tests/test_browser.py

    r10876 r14499  
    2020import datetime
    2121import pytz
     22import os
    2223from zope.component.hooks import setSite, clearSite
    2324from zope.component import createObject
    2425from zope.testbrowser.testing import Browser
     26from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
    2527from waeup.kofa.app import University
    2628from waeup.kofa.university.faculty import Faculty
    2729from waeup.kofa.university.department import Department
    2830from waeup.kofa.testing import FunctionalTestCase
     31from waeup.kofa.interfaces import (
     32    IExtFileStore, IFileStoreNameChooser, IUserAccount, IJobManager)
    2933from waeup.kofa.applicants.container import ApplicantsContainer
    3034from waeup.fceokene.testing import FunctionalLayer
    3135
    3236session = datetime.datetime.now().year - 2
     37SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg')
    3338
    3439class ApplicantUITest(FunctionalTestCase):
     
    5358        # to access grok.getSite() and should get our new app then
    5459        setSite(app)
     60
     61        self.login_path = 'http://localhost/app/login'
    5562
    5663        # Add bec applicants container
     
    8289        self.putmecontainer.enddate = datetime.datetime.now(pytz.utc) + delta
    8390
     91        # Add tpu applicants container
     92        self.tpucontainer = ApplicantsContainer()
     93        self.tpucontainer.mode = 'create'
     94        self.tpucontainer.code = u'tpu%s' % session
     95        self.tpucontainer.prefix = u'tpu'
     96        self.tpucontainer.application_category = u'no'
     97        self.tpucontainer.year = session
     98        self.tpucontainer.application_fee = 300.0
     99        self.tpucontainer.title = u'This is the tpu%s container' % session
     100        self.app['applicants'][self.tpucontainer.code] = self.tpucontainer
     101        delta = datetime.timedelta(days=10)
     102        self.tpucontainer.startdate = datetime.datetime.now(pytz.utc) - delta
     103        self.tpucontainer.enddate = datetime.datetime.now(pytz.utc) + delta
     104
    84105        # Populate university
    85106        self.certificate = createObject('waeup.Certificate')
     
    115136            % (session, self.putmeapplication_number))
    116137
     138        tpuapplicant = createObject(u'waeup.Applicant')
     139        tpuapplicant.firstname = u'Michelle'
     140        tpuapplicant.lastname = u'Obama'
     141        self.app['applicants'][self.tpucontainer.code].addApplicant(tpuapplicant)
     142        self.tpuapplication_number = tpuapplicant.application_number
     143        self.tpuapplicant = self.app['applicants'][self.tpucontainer.code][
     144            self.tpuapplication_number]
     145        self.tpuapplicant_path = ('http://localhost/app/applicants/tpu%s/%s'
     146            % (session, self.tpuapplication_number))
     147        IUserAccount(
     148            self.app['applicants'][self.tpucontainer.code][
     149            self.tpuapplicant.application_number]).setPassword('apwd')
     150
    117151        self.browser = Browser()
    118152        self.browser.handleErrors = False
     
    124158        return
    125159
    126     def fill_correct_values(self):
    127         self.browser.getControl(name="form.reg_number").value = '1234'
    128         self.browser.getControl(name="form.firstname").value = 'John'
    129         self.browser.getControl(name="form.lastname").value = 'Tester'
    130         self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
    131         self.browser.getControl(name="form.lga").value = ['foreigner']
    132         self.browser.getControl(name="form.nationality").value = ['NG']
    133         self.browser.getControl(name="form.sex").value = ['m']
    134         self.browser.getControl(name="form.email").value = 'xx@yy.zz'
    135 
    136160    def test_manage_and_view_bec_applicant(self):
    137161        # Managers can manage bec applicants.
     
    164188        self.browser.open(self.putmeapplicant_path + '/application_slip.pdf')
    165189        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     190       
     191
     192    def test_final_submit_tpu(self):
     193        IWorkflowState(self.tpuapplicant).setState('paid')
     194        self.browser.open(self.login_path)
     195        self.browser.getControl(
     196            name="form.login").value = self.tpuapplicant.applicant_id
     197        self.browser.getControl(name="form.password").value = 'apwd'
     198        self.browser.getControl("Login").click()
     199        self.browser.open(self.tpuapplicant_path + '/edit')
     200        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
     201        self.browser.getControl(name="form.school1").value = ['s0010']
     202        image = open(SAMPLE_IMAGE, 'rb')
     203        ctrl = self.browser.getControl(name='form.passport')
     204        file_ctrl = ctrl.mech_control
     205        file_ctrl.add_file(image, filename='myphoto.jpg')
     206        self.browser.getControl(name="confirm_passport").value = True
     207        self.browser.getControl("Save").click()
     208        self.browser.getControl("Finally Submit").click()
     209        self.assertTrue(
     210            'Application submitted' in self.browser.contents)
     211        # Create 20 applicants who already selected s0010
     212        for i in range(1,21):
     213            tpuapplicant = createObject(u'waeup.Applicant')
     214            tpuapplicant.firstname = u'John'
     215            tpuapplicant.lastname = u'Doe %s' %i
     216            tpuapplicant.school1 = 's0010'
     217            self.app['applicants'][
     218                self.tpucontainer.code].addApplicant(tpuapplicant)
     219            IWorkflowState(tpuapplicant).setState('submitted')
     220        IWorkflowState(self.tpuapplicant).setState('paid')
     221        self.tpuapplicant.locked = False
     222        self.browser.open(self.tpuapplicant_path + '/edit')
     223        self.browser.getControl("Finally Submit").click()
     224        self.assertTrue("Maximum number of applications per school exceeded."
     225            in self.browser.contents)
     226        self.assertEqual(self.tpuapplicant.state, 'paid')
    166227        return
     228
Note: See TracChangeset for help on using the changeset viewer.