Ignore:
Timestamp:
4 Apr 2012, 06:19:20 (12 years ago)
Author:
Henrik Bettermann
Message:

Verify firstname when registering for application in update mode.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/applicants
Files:
3 edited

Legend:

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

    r8033 r8037  
    3232    IApplicantsContainer, IApplicantsContainerAdd,
    3333    MAX_UPLOAD_SIZE, IApplicantOnlinePayment, IApplicantsUtils,
    34     IApplicantUpdateByRegNo
     34    IApplicantRegisterUpdate
    3535    )
    3636from waeup.kofa.applicants.workflow import INITIALIZED, STARTED, PAID, SUBMITTED
     
    869869            form_fields['phone'].custom_widget = PhoneWidget
    870870        elif self.context.mode == 'update':
    871             form_fields = grok.AutoFields(IApplicantUpdateByRegNo).select(
    872                 'reg_number','email')
     871            form_fields = grok.AutoFields(IApplicantRegisterUpdate).select(
     872                'firstname','reg_number','email')
    873873        return form_fields
    874874
     
    898898    def register(self, **data):
    899899        if not self.captcha_result.is_valid:
    900             # captcha will display error messages automatically.
     900            # Captcha will display error messages automatically.
    901901            # No need to flash something.
    902902            return
     
    908908        elif self.context.mode == 'update':
    909909            # Update applicant
    910             reg_number = data['reg_number']
     910            reg_number = data.get('reg_number','')
     911            firstname = data.get('firstname','')
    911912            cat = getUtility(ICatalog, name='applicants_catalog')
    912913            results = list(
     
    915916                applicant = results[0]
    916917                if applicant.password is not None:
    917                     self.flash(_('Your password has already been set.'))
     918                    self.flash(_('Your password has already been set. '
     919                                  'You can proceed to the login page.'))
     920                    return
     921                elif getattr(applicant,'firstname',None) is None:
     922                    self.flash(_('An error occurred.'))
     923                    return
     924                elif applicant.firstname.lower() != firstname.lower():
     925                    self.flash(_('No application record found.'))
    918926                    return
    919927                applicant.email = data['email']
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/interfaces.py

    r8033 r8037  
    489489        )
    490490
     491class IApplicantRegisterUpdate(IApplicant):
     492    """Representation of an applicant for first-time registration.
     493
     494    This interface is used when apllicants use the registration page to
     495    update their records.
     496    """
     497    reg_number = schema.TextLine(
     498        title = u'Registration Number',
     499        required = True,
     500        )
     501
     502    firstname = schema.TextLine(
     503        title = _(u'First Name'),
     504        required = True,
     505        )
     506
     507    email = schema.ASCIILine(
     508        title = _(u'Email Address'),
     509        required = True,
     510        constraint=validate_email,
     511        )
     512
    491513class IApplicantOnlinePayment(IOnlinePayment):
    492514    """An applicant payment via payment gateways.
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r8033 r8037  
    806806        self.assertEqual(self.browser.url,
    807807            self.container_path + '/registration_complete?email=xx%40yy.zz')
    808         # Now we change the application mode and check if applicants
     808        return
     809
     810    def test_register_applicant_update(self):
     811        # We change the application mode and check if applicants
    809812        # can find and update imported records instead of creating new records.
    810813        # First we check what happens if record can't be found.
    811814        self.applicantscontainer.mode = 'update'
    812815        self.browser.open(self.container_path + '/register')
    813         #self.browser.getControl(name="form.firstname").value = 'John'
     816        self.browser.getControl(name="form.firstname").value = 'John'
    814817        self.browser.getControl(name="form.reg_number").value = 'anynumber'
    815818        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
     
    817820        self.assertTrue('No application record found.'
    818821            in self.browser.contents)
    819         # Now we check if password has already been set.
    820         #self.browser.getControl(name="form.firstname").value = 'John'
     822        # We can't register if password has already been set.
     823        self.browser.getControl(name="form.firstname").value = 'John'
    821824        self.browser.getControl(name="form.reg_number").value = '1234'
    822825        self.browser.getControl("Get login credentials").click()
     
    828831            self.applicant.application_number]).context.password = None
    829832        self.browser.open(self.container_path + '/register')
    830         #self.browser.getControl(name="form.firstname").value = 'John'
     833        self.browser.getControl(name="form.firstname").value = 'John'
    831834        self.browser.getControl(name="form.reg_number").value = '1234'
    832835        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
     836        self.browser.getControl("Get login credentials").click()
     837        self.assertTrue('An error occurred.'in self.browser.contents)
     838        # The firstname attribute was None. Let's set this attribute manually
     839        # and try to register with a wrong name.
     840        self.applicant.firstname = u'John'
     841        self.browser.open(self.container_path + '/register')
     842        self.browser.getControl(name="form.firstname").value = 'Johnny'
     843        self.browser.getControl(name="form.reg_number").value = '1234'
     844        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
     845        self.browser.getControl("Get login credentials").click()
     846        self.assertTrue('No application record found.'
     847            in self.browser.contents)
     848        # Now we use the correct name. For verification
     849        # the name is not case-sensitive.
     850        self.browser.getControl(name="form.firstname").value = 'jOhn'
    833851        self.browser.getControl("Get login credentials").click()
    834852        self.assertTrue('Your registration was successful.'
Note: See TracChangeset for help on using the changeset viewer.