- Timestamp:
- 30 Mar 2012, 17:55:44 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset for help on using the changeset viewer.