Ignore:
Timestamp:
12 Jul 2015, 17:17:48 (9 years ago)
Author:
Henrik Bettermann
Message:

Require exactly 4 jamb subjects when saved with the edit form page.

Testing this is a nightmare because the testbrowser does not support Javascript.

Location:
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/applicants
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/applicants/interfaces.py

    r13161 r13163  
    6868    )
    6969
     70# Define a validation method for jamb subjects
     71class NotExactNumberOfItems(schema.ValidationError):
     72    __doc__ = u"Not exactly 4 items selected."
     73
     74def four_items(value):
     75    if len(value) != 4:
     76        raise NotExactNumberOfItems(value)
     77    return True
     78
    7079class JAMBSubjectSource(SubjectSource):
    7180    """A source for school subjects used in exam documentation.
     
    233242    jamb_subjects_list = schema.List(
    234243        title = _(u'JAMB Subjects'),
    235         default = ['english_language',],
    236         required = False,
     244        required = False,
     245        default = [],
    237246        value_type = schema.Choice(
    238247            vocabulary = jambsubjects
     
    578587        title = _(u'JAMB Subjects'),
    579588        description = _(u'Select four subjects.'),
    580         default = ['english_language',],
    581         required = True,
     589        required = True,
     590        constraint = four_items,
    582591        value_type = schema.Choice(
    583592            vocabulary = jambsubjects
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/applicants/tests/test_browser.py

    r13160 r13163  
    3838from waeup.kofa.applicants.container import ApplicantsContainer
    3939from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup
    40 from waeup.kofa.interfaces import IBatchProcessor
     40from waeup.kofa.interfaces import IBatchProcessor, IUserAccount
    4141from kofacustom.nigeria.testing import FunctionalLayer
    4242from kofacustom.nigeria.applicants.export import NigeriaApplicantExporter
     
    4646app_container_name = u'app%s' % session_1
    4747pgft_container_name = u'pgft%s' % session_1
     48cbt_container_name = u'cbt%s' % session_1
    4849
    4950class ApplicantUITest(FunctionalTestCase):
     
    6970        setSite(app)
    7071
    71         # Add an two different applicants containers
     72        # Add three different applicants containers
    7273        self.pgcontainer = ApplicantsContainer()
    7374        self.pgcontainer.code = pgft_container_name
     
    7879        self.pgcontainer.title = u'This is the %s container' % pgft_container_name
    7980        self.app['applicants'][pgft_container_name] = self.pgcontainer
     81
    8082        self.ugcontainer = ApplicantsContainer()
    8183        self.ugcontainer.code = app_container_name
     
    8688        self.ugcontainer.title = u'This is the %s container' % app_container_name
    8789        self.app['applicants'][app_container_name] = self.ugcontainer
    88 
    8990        self.ugcontainer.mode = 'update'
    9091        delta = datetime.timedelta(days=10)
    9192        self.ugcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
    9293        self.ugcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
     94
     95        self.cbtcontainer = ApplicantsContainer()
     96        self.cbtcontainer.code = cbt_container_name
     97        self.cbtcontainer.prefix = u'cbt'
     98        self.cbtcontainer.application_category = u'basic'
     99        self.cbtcontainer.year = session_1
     100        self.cbtcontainer.application_fee = 300.0
     101        self.cbtcontainer.title = u'This is the %s container' % cbt_container_name
     102        self.app['applicants'][cbt_container_name] = self.cbtcontainer
     103        self.cbtcontainer.mode = 'update'
     104        delta = datetime.timedelta(days=10)
     105        self.cbtcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
     106        self.cbtcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
    93107
    94108        # Populate university
     
    128142        self.ugapplicant = self.app['applicants'][app_container_name][
    129143            self.ugapplication_number]
     144
     145        cbtapplicant = createObject(u'waeup.Applicant')
     146        cbtapplicant.firstname = u'Anna'
     147        cbtapplicant.lastname = u'Cbt'
     148        self.app['applicants'][cbt_container_name].addApplicant(cbtapplicant)
     149        self.cbtapplication_number = cbtapplicant.application_number
     150        self.cbtapplicant = self.app['applicants'][cbt_container_name][
     151            self.cbtapplication_number]
     152        IUserAccount(self.cbtapplicant).setPassword('apwd')
     153
     154        self.login_path = 'http://localhost/app/login'
     155        self.logout_path = 'http://localhost/app/logout'
    130156        self.pgapplicant_path = ('http://localhost/app/applicants/%s/%s'
    131157            % (pgft_container_name, self.pgapplication_number))
    132158        self.ugapplicant_path = ('http://localhost/app/applicants/%s/%s'
    133159            % (app_container_name, self.ugapplication_number))
     160        self.cbtapplicant_path = ('http://localhost/app/applicants/%s/%s'
     161            % (cbt_container_name, self.cbtapplication_number))
    134162
    135163        self.browser = Browser()
     
    319347        self.assertEqual(student.nationality, 'NG')
    320348        return
     349
     350    def test_applicant_access(self):
     351        # Applicants can edit their record
     352        self.browser.open(self.login_path)
     353        self.browser.getControl(
     354            name="form.login").value = self.cbtapplicant.applicant_id
     355        self.browser.getControl(name="form.password").value = 'apwd'
     356        self.browser.getControl("Login").click()
     357        self.assertTrue(
     358            'You logged in.' in self.browser.contents)
     359        self.browser.getLink("Edit application record").click()
     360        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
     361        self.browser.getControl(name="form.lga").value = ['foreigner']
     362        self.browser.getControl(name="form.nationality").value = ['NG']
     363        self.browser.getControl(name="form.sex").value = ['m']
     364        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
     365        self.browser.getControl(name="form.course1").value = ['CERT1']
     366        self.browser.getControl("Save").click()
     367        self.assertMatches('...Not exactly 4 items selected...', self.browser.contents)
     368        # Since the testbrowser does not support Javascrip we can't test the
     369        # save action which clears jamb_subjects_list on the edit form page
     370        # An error would be raised.
     371
     372        # If we login as manager, we can use the manage form page.
     373        self.browser.open(self.logout_path)
     374        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     375        self.cbtapplicant.jamb_subjects_list = [
     376          'english_language', 'fine_art', 'mathematics', 'physics']
     377        self.browser.open(self.cbtapplicant_path + '/manage')
     378        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
     379        self.browser.getControl(name="form.lga").value = ['foreigner']
     380        self.browser.getControl(name="form.nationality").value = ['NG']
     381        self.browser.getControl(name="form.sex").value = ['m']
     382        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
     383        self.browser.getControl(name="form.course1").value = ['CERT1']
     384        self.browser.getControl(name="form.reg_number").value = '1234'
     385        self.browser.getControl("Save").click()
     386        self.assertMatches('...Form has been saved...', self.browser.contents)
     387        # The save action on this form pages, if called with the testbrowser,
     388        # replaces jamb_subjects_list by an empty list (and not by None).
     389        self.assertEqual(self.cbtapplicant.jamb_subjects_list, [])
    321390
    322391class ApplicantExporterTest(ApplicantImportExportSetup):
Note: See TracChangeset for help on using the changeset viewer.