Changeset 8012
- Timestamp:
- 30 Mar 2012, 17:55:44 (13 years ago)
- Location:
- main/waeup.custom/trunk/src/waeup/custom/applicants
- Files:
-
- 1 added
- 3 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.custom/trunk/src/waeup/custom/applicants/applicant.py
r7866 r8012 20 20 from zope.interface import implementedBy 21 21 from waeup.kofa.applicants.applicant import Applicant, ApplicantFactory 22 from waeup.custom.applicants.interfaces import IPGApplicant, IPGApplicantEdit 22 from waeup.kofa.applicants.interfaces import IApplicantEdit 23 from waeup.kofa.utils.helpers import attrs_to_fields 24 from waeup.custom.applicants.interfaces import( 25 IApplicant, IUGApplicantEdit, IPGApplicantEdit) 23 26 24 class PGApplicant(Applicant): 25 grok.implements(IPGApplicant,IPGApplicantEdit) 26 grok.provides(IPGApplicant) 27 class Applicant(Applicant): 27 28 28 class PGApplicantFactory(ApplicantFactory): 29 """A factory for pg applicants. 29 grok.implements(IApplicant, IUGApplicantEdit, IPGApplicantEdit) 30 grok.provides(IApplicant) 31 32 # Set all attributes of Applicant required in IApplicant as field 33 # properties. Doing this, we do not have to set initial attributes 34 # ourselves and as a bonus we get free validation when an attribute is 35 # set. 36 Applicant = attrs_to_fields(Applicant) 37 38 class ApplicantFactory(ApplicantFactory): 39 """A factory for customized applicants. 30 40 """ 31 grok.name(u'waeup.PGApplicant')32 title = u"Create a new pg applicant.",33 description = u"This factory instantiates new pg applicant instances."34 41 35 42 def __call__(self, *args, **kw): 36 return PGApplicant()43 return Applicant() 37 44 38 45 def getInterfaces(self): 39 return implementedBy( PGApplicant)46 return implementedBy(Applicant) -
main/waeup.custom/trunk/src/waeup/custom/applicants/interfaces.py
r7866 r8012 19 19 """ 20 20 21 from waeup.kofa.applicants.interfaces import IApplicant, IApplicantEdit 21 from zope import schema 22 from waeup.kofa.applicants.interfaces import IApplicant, IApplicantProcessData 23 from waeup.custom.interfaces import MessageFactory as _ 24 25 class IUGApplicant(IApplicant): 26 """An undergraduate applicant. 27 28 """ 22 29 23 30 class IPGApplicant(IApplicant): … … 26 33 """ 27 34 28 class IPGApplicantEdit(IApplicantEdit): 35 employer = schema.TextLine( 36 title = _(u'Employer'), 37 required = False, 38 readonly = False, 39 ) 40 41 class IApplicant(IUGApplicant,IPGApplicant): 42 """An interface for both types of applicants. 43 44 """ 45 46 class IUGApplicantEdit(IApplicantProcessData): 47 """An undergraduate applicant interface for editing. 48 49 Here we can repeat the fields from base data and set the 50 `required` and `readonly` attributes to True to further restrict 51 the data access. Or we can allow only certain certificates to be 52 selected by choosing the appropriate source. 53 54 We cannot omit fields here. This has to be done in the 55 respective form page. 56 """ 57 58 class IPGApplicantEdit(IApplicantProcessData): 29 59 """A postgraduate applicant interface for editing. 30 60 -
main/waeup.custom/trunk/src/waeup/custom/applicants/tests.py
r7934 r8012 22 22 from zope.component.hooks import setSite, clearSite 23 23 from zope.component import createObject 24 from zope.testbrowser.testing import Browser 24 25 from waeup.kofa.app import University 25 26 from waeup.kofa.university.faculty import Faculty 26 27 from waeup.kofa.university.department import Department 27 28 from waeup.kofa.testing import FunctionalTestCase 29 from waeup.kofa.applicants.container import ApplicantsContainer 28 30 from waeup.custom.testing import FunctionalLayer 29 31 from waeup.kofa.interfaces import IBatchProcessor 30 from waeup.kofa.applicants.applicant import Applicant31 from waeup.custom.applicants.container import PGApplicantsContainer32 from waeup.custom.applicants.applicant import PGApplicant33 from waeup.custom.applicants.batching import PGApplicantProcessor34 from waeup.custom.applicants.interfaces import IPGApplicant, IPGApplicantEdit35 32 36 APPLICANT_SAMPLE_DATA = open( 37 os.path.join(os.path.dirname(__file__), 'sample_applicant_data.csv'), 38 'rb').read() 39 APPLICANT_HEADER_FIELDS = APPLICANT_SAMPLE_DATA.split( 40 '\n')[0].split(',') 41 42 class PGApplicantProcessorTest(FunctionalTestCase): 43 """Perform some batching tests. 33 class ApplicantUITest(FunctionalTestCase): 34 """Perform some browser tests. 44 35 """ 45 36 layer = FunctionalLayer 46 37 47 38 def setUp(self): 48 super( PGApplicantProcessorTest, self).setUp()39 super(ApplicantUITest, self).setUp() 49 40 # Setup a sample site for each test 50 41 app = University() … … 62 53 setSite(app) 63 54 64 # Add an applicants container 65 self.container = PGApplicantsContainer() 66 self.container.code = u'pg2011' 67 self.app['applicants']['pg2011'] = self.container 55 # Add an two different applicants containers 56 self.pgcontainer = ApplicantsContainer() 57 self.pgcontainer.code = u'pg2011' 58 self.pgcontainer.prefix = u'pg' 59 self.app['applicants']['pg2011'] = self.pgcontainer 60 self.ugcontainer = ApplicantsContainer() 61 self.ugcontainer.code = u'app2011' 62 self.ugcontainer.prefix = u'app' 63 self.app['applicants']['app2011'] = self.ugcontainer 68 64 69 65 # Populate university … … 78 74 self.certificate) 79 75 80 # Add applicant with subobjects 81 applicant = PGApplicant() 82 applicant.firstname = u'Anna' 83 applicant.lastname = u'Tester' 84 self.app['applicants']['pg2011'].addApplicant(applicant) 85 self.application_number = applicant.application_number 86 self.applicant = self.app['applicants']['pg2011'][ 87 self.application_number] 88 self.processor = PGApplicantProcessor() 89 self.workdir = tempfile.mkdtemp() 90 self.csv_file = os.path.join(self.workdir, 'sample_applicant_data.csv') 91 open(self.csv_file, 'wb').write(APPLICANT_SAMPLE_DATA) 76 # Add (customized) applicants 77 pgapplicant = createObject(u'waeup.Applicant') 78 pgapplicant.firstname = u'Anna' 79 pgapplicant.lastname = u'Post' 80 self.app['applicants']['pg2011'].addApplicant(pgapplicant) 81 self.pgapplication_number = pgapplicant.application_number 82 self.pgapplicant = self.app['applicants']['pg2011'][ 83 self.pgapplication_number] 84 85 ugapplicant = createObject(u'waeup.Applicant') 86 ugapplicant.firstname = u'Klaus' 87 ugapplicant.lastname = u'Under' 88 self.app['applicants']['app2011'].addApplicant(ugapplicant) 89 self.ugapplication_number = ugapplicant.application_number 90 self.ugapplicant = self.app['applicants']['app2011'][ 91 self.ugapplication_number] 92 93 self.browser = Browser() 94 self.browser.handleErrors = False 92 95 93 96 def tearDown(self): 94 super(PGApplicantProcessorTest, self).tearDown() 95 shutil.rmtree(self.workdir) 97 super(ApplicantUITest, self).tearDown() 96 98 shutil.rmtree(self.dc_root) 97 99 clearSite() 98 100 return 99 101 100 def test_interfaces(self): 101 # Make sure we fulfill the interface contracts. 102 assert verifyObject(IBatchProcessor, self.processor) is True 103 assert verifyClass( 104 IBatchProcessor, PGApplicantProcessor) is True 105 assert verifyObject(IPGApplicant, self.applicant) is True 106 assert verifyClass( 107 IPGApplicant, PGApplicant) is True 108 assert verifyObject(IPGApplicantEdit, self.applicant) is True 109 assert verifyClass( 110 IPGApplicantEdit, PGApplicant) is True 102 def test_manage_and_view_applicant(self): 103 # Managers can manage pg applicants 104 pgapplicant_path = ('http://localhost/app/applicants/pg2011/%s' 105 % self.pgapplication_number) 106 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 107 self.browser.open(pgapplicant_path) 108 self.assertEqual(self.browser.headers['Status'], '200 Ok') 109 # The IPGApplicant interface is really used 110 self.assertTrue('Employer' in self.browser.contents) 111 # If we move the applicant to the container, 112 # the Employer field disappears 113 ugapplicant_path = ('http://localhost/app/applicants/app2011/%s' 114 % self.ugapplication_number) 115 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 116 self.browser.open(ugapplicant_path) 117 self.assertEqual(self.browser.headers['Status'], '200 Ok') 111 118 112 def test_wrong_child(self): 113 applicant = Applicant() 114 applicant.firstname = u'Klaus' 115 applicant.lastname = u'Tester' 116 self.assertRaises( 117 TypeError, self.app['applicants']['pg2011'].addApplicant, applicant) 118 119 def test_import(self): 120 num, num_warns, fin_file, fail_file = self.processor.doImport( 121 self.csv_file, APPLICANT_HEADER_FIELDS) 122 self.assertEqual(num_warns,0) 123 keys = self.app['applicants']['pg2011'].keys() 124 assert len(keys) == 4 125 container = self.app['applicants']['pg2011'] 126 assert container.__implemented__.__name__ == ( 127 'waeup.custom.applicants.container.PGApplicantsContainer') 128 applicant = container[keys[0]] 129 assert applicant.__implemented__.__name__ == ( 130 'waeup.custom.applicants.applicant.PGApplicant') 131 shutil.rmtree(os.path.dirname(fin_file)) 119 self.assertFalse('Employer' in self.browser.contents) 120 return -
main/waeup.custom/trunk/src/waeup/custom/applicants/utils.py
r7845 r8012 36 36 'ct': ['Certificate Programmes', 'CTP'], 37 37 'dp': ['Diploma Programmes', 'DPP'], 38 'pce': ['PCE Screening', 'PCE'] 38 'pce': ['PCE Screening', 'PCE'], 39 'pg': ['Postgraduate Programmes', 'PCE'] 39 40 }
Note: See TracChangeset for help on using the changeset viewer.