Changeset 8042
- Timestamp:
- 4 Apr 2012, 21:28:16 (13 years ago)
- 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 23 23 from time import time 24 24 from datetime import datetime, date 25 from zope.event import notify 25 26 from zope.component import getUtility, createObject, getAdapter 26 27 from zope.catalog.interfaces import ICatalog … … 907 908 self.applyData(applicant, **data) 908 909 self.context.addApplicant(applicant) 910 applicant.reg_number = applicant.applicant_id 911 notify(grok.ObjectModifiedEvent(applicant)) 909 912 elif self.context.mode == 'update': 910 913 # Update applicant … … 916 919 if results: 917 920 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: 923 922 self.flash(_('An error occurred.')) 924 923 return 925 924 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. 926 928 self.flash(_('No application record found.')) 927 929 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. 928 935 applicant.email = data['email'] 936 notify(grok.ObjectModifiedEvent(applicant)) 929 937 else: 938 # No record found, this is the truth. 930 939 self.flash(_('No application record found.')) 931 940 return 932 941 else: 942 # Does not happen but anyway ... 933 943 return 934 944 kofa_utils = getUtility(IKofaUtils) -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py
r8039 r8042 26 26 from mechanize import LinkNotFoundError 27 27 from zope.event import notify 28 from zope.catalog.interfaces import ICatalog 28 29 from zope.component import createObject, getUtility 29 30 from zope.component.hooks import setSite, clearSite … … 799 800 self.browser.getLink("Register for application").click() 800 801 # 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' 803 804 self.browser.getControl(name="form.email").value = 'xx@yy.zz' 804 805 self.browser.getControl(name="form.phone.country").value = ['+234'] … … 808 809 self.assertEqual(self.browser.url, 809 810 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]) 810 824 return 811 825 … … 813 827 # We change the application mode and check if applicants 814 828 # 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. 816 830 self.applicantscontainer.mode = 'update' 817 831 self.browser.open(self.container_path + '/register') … … 822 836 self.assertTrue('No application record found.' 823 837 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. 825 861 self.browser.getControl(name="form.firstname").value = 'John' 826 862 self.browser.getControl(name="form.reg_number").value = '1234' … … 833 869 self.applicant.application_number]).context.password = None 834 870 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' 836 873 self.browser.getControl(name="form.reg_number").value = '1234' 837 874 self.browser.getControl(name="form.email").value = 'xx@yy.zz' 838 875 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 ... 854 877 self.assertTrue('Your registration was successful.' 855 878 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]) 856 885 return 857 886
Note: See TracChangeset for help on using the changeset viewer.