Ignore:
Timestamp:
30 Mar 2012, 17:55:44 (13 years ago)
Author:
Henrik Bettermann
Message:

Remove all ApplicantsContainerProvider? components and use same form customization technique as in students. In contrast to the students package, postgraduate applicants are only defined in the custom package. Thus the implementation is slightly different.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.custom/trunk/src/waeup/custom/applicants/tests.py

    r7934 r8012  
    2222from zope.component.hooks import setSite, clearSite
    2323from zope.component import createObject
     24from zope.testbrowser.testing import Browser
    2425from waeup.kofa.app import University
    2526from waeup.kofa.university.faculty import Faculty
    2627from waeup.kofa.university.department import Department
    2728from waeup.kofa.testing import FunctionalTestCase
     29from waeup.kofa.applicants.container import ApplicantsContainer
    2830from waeup.custom.testing import FunctionalLayer
    2931from waeup.kofa.interfaces import IBatchProcessor
    30 from waeup.kofa.applicants.applicant import Applicant
    31 from waeup.custom.applicants.container import PGApplicantsContainer
    32 from waeup.custom.applicants.applicant import PGApplicant
    33 from waeup.custom.applicants.batching import PGApplicantProcessor
    34 from waeup.custom.applicants.interfaces import IPGApplicant, IPGApplicantEdit
    3532
    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.
     33class ApplicantUITest(FunctionalTestCase):
     34    """Perform some browser tests.
    4435    """
    4536    layer = FunctionalLayer
    4637
    4738    def setUp(self):
    48         super(PGApplicantProcessorTest, self).setUp()
     39        super(ApplicantUITest, self).setUp()
    4940        # Setup a sample site for each test
    5041        app = University()
     
    6253        setSite(app)
    6354
    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
    6864
    6965        # Populate university
     
    7874            self.certificate)
    7975
    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
    9295
    9396    def tearDown(self):
    94         super(PGApplicantProcessorTest, self).tearDown()
    95         shutil.rmtree(self.workdir)
     97        super(ApplicantUITest, self).tearDown()
    9698        shutil.rmtree(self.dc_root)
    9799        clearSite()
    98100        return
    99101
    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')
    111118
    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.