Changeset 8042 for main/waeup.kofa/trunk


Ignore:
Timestamp:
4 Apr 2012, 21:28:16 (12 years ago)
Author:
Henrik Bettermann
Message:

Reorganize application record update order and notify the catalog after modifying attributes.

Everything is now perfectly tested.

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

Legend:

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

    r8039 r8042  
    2323from time import time
    2424from datetime import datetime, date
     25from zope.event import notify
    2526from zope.component import getUtility, createObject, getAdapter
    2627from zope.catalog.interfaces import ICatalog
     
    907908            self.applyData(applicant, **data)
    908909            self.context.addApplicant(applicant)
     910            applicant.reg_number = applicant.applicant_id
     911            notify(grok.ObjectModifiedEvent(applicant))
    909912        elif self.context.mode == 'update':
    910913            # Update applicant
     
    916919            if results:
    917920                applicant = results[0]
    918                 if applicant.password is not None:
    919                     self.flash(_('Your password has already been set. '
    920                                   'Please proceed to the login page.'))
    921                     return
    922                 elif getattr(applicant,'firstname',None) is None:
     921                if getattr(applicant,'firstname',None) is None:
    923922                    self.flash(_('An error occurred.'))
    924923                    return
    925924                elif applicant.firstname.lower() != firstname.lower():
     925                    # Don't tell the truth here. Anonymous must not
     926                    # know that a record was found and only the firstname
     927                    # verification failed.
    926928                    self.flash(_('No application record found.'))
    927929                    return
     930                elif applicant.password is not None:
     931                    self.flash(_('Your password has already been set. '
     932                                 'Please proceed to the login page.'))
     933                    return
     934                # Store email address but nothing else.
    928935                applicant.email = data['email']
     936                notify(grok.ObjectModifiedEvent(applicant))
    929937            else:
     938                # No record found, this is the truth.
    930939                self.flash(_('No application record found.'))
    931940                return
    932941        else:
     942            # Does not happen but anyway ...
    933943            return
    934944        kofa_utils = getUtility(IKofaUtils)
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r8039 r8042  
    2626from mechanize import LinkNotFoundError
    2727from zope.event import notify
     28from zope.catalog.interfaces import ICatalog
    2829from zope.component import createObject, getUtility
    2930from zope.component.hooks import setSite, clearSite
     
    799800        self.browser.getLink("Register for application").click()
    800801        # Fill the edit form with suitable values
    801         self.browser.getControl(name="form.firstname").value = 'John'
    802         self.browser.getControl(name="form.lastname").value = 'Tester'
     802        self.browser.getControl(name="form.firstname").value = 'Anna'
     803        self.browser.getControl(name="form.lastname").value = 'Kurios'
    803804        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
    804805        self.browser.getControl(name="form.phone.country").value = ['+234']
     
    808809        self.assertEqual(self.browser.url,
    809810            self.container_path + '/registration_complete?email=xx%40yy.zz')
     811        # The new applicant can be found in the catalog via the email address
     812        cat = getUtility(ICatalog, name='applicants_catalog')
     813        results = list(
     814            cat.searchResults(email=('xx@yy.zz', 'xx@yy.zz')))
     815        applicant = results[0]
     816        self.assertEqual(applicant.lastname,'Kurios')
     817        # The application_id has been copied to the reg_number
     818        self.assertEqual(applicant.applicant_id, applicant.reg_number)
     819        # The applicant can be found in the catalog via the reg_number
     820        results = list(
     821            cat.searchResults(
     822            reg_number=(applicant.reg_number, applicant.reg_number)))
     823        self.assertEqual(applicant,results[0])
    810824        return
    811825
     
    813827        # We change the application mode and check if applicants
    814828        # can find and update imported records instead of creating new records.
    815         # First we check what happens if record can't be found.
     829        # First we check what happens if record does not exist.
    816830        self.applicantscontainer.mode = 'update'
    817831        self.browser.open(self.container_path + '/register')
     
    822836        self.assertTrue('No application record found.'
    823837            in self.browser.contents)
    824         # We can't register if password has already been set.
     838        # Even with the correct reg_number we can't register
     839        # because firstname attribute is not set.
     840        self.applicantscontainer.mode = 'update'
     841        self.browser.open(self.container_path + '/register')
     842        self.browser.getControl(name="form.firstname").value = 'John'
     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('An error occurred.' in self.browser.contents)
     847        # Let's set this attribute manually
     848        # and try to register with a wrong name.
     849        self.applicant.firstname = u'John'
     850        self.browser.open(self.container_path + '/register')
     851        self.browser.getControl(name="form.firstname").value = 'Johnny'
     852        self.browser.getControl(name="form.reg_number").value = '1234'
     853        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
     854        self.browser.getControl("Get login credentials").click()
     855        # Anonymous is not informed that firstname verification failed.
     856        # It seems that the record doesn't exist.
     857        self.assertTrue('No application record found.'
     858            in self.browser.contents)
     859        # Even with the correct firstname we can't register because
     860        # password has already been set.
    825861        self.browser.getControl(name="form.firstname").value = 'John'
    826862        self.browser.getControl(name="form.reg_number").value = '1234'
     
    833869            self.applicant.application_number]).context.password = None
    834870        self.browser.open(self.container_path + '/register')
    835         self.browser.getControl(name="form.firstname").value = 'John'
     871        # The firstname field, used for verification, is not case-sensitive.
     872        self.browser.getControl(name="form.firstname").value = 'jOhn'
    836873        self.browser.getControl(name="form.reg_number").value = '1234'
    837874        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
    838875        self.browser.getControl("Get login credentials").click()
    839         self.assertTrue('An error occurred.'in self.browser.contents)
    840         # The firstname attribute was None. Let's set this attribute manually
    841         # and try to register with a wrong name.
    842         self.applicant.firstname = u'John'
    843         self.browser.open(self.container_path + '/register')
    844         self.browser.getControl(name="form.firstname").value = 'Johnny'
    845         self.browser.getControl(name="form.reg_number").value = '1234'
    846         self.browser.getControl(name="form.email").value = 'xx@yy.zz'
    847         self.browser.getControl("Get login credentials").click()
    848         self.assertTrue('No application record found.'
    849             in self.browser.contents)
    850         # Now we use the correct name. For verification
    851         # the name is not case-sensitive.
    852         self.browser.getControl(name="form.firstname").value = 'jOhn'
    853         self.browser.getControl("Get login credentials").click()
     876        # Yeah, we succeded ...
    854877        self.assertTrue('Your registration was successful.'
    855878            in self.browser.contents)
     879        # ... and  applicant can be found in the catalog via the email address
     880        cat = getUtility(ICatalog, name='applicants_catalog')
     881        results = list(
     882            cat.searchResults(
     883            email=('xx@yy.zz', 'xx@yy.zz')))
     884        self.assertEqual(self.applicant,results[0])
    856885        return
    857886
Note: See TracChangeset for help on using the changeset viewer.