Ignore:
Timestamp:
13 Jul 2012, 10:54:40 (12 years ago)
Author:
Henrik Bettermann
Message:

Use UniversityProcessorSetup? base class for setting up a site. Use this site in CourseProcessorTests?. (work in progress)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_batching.py

    r8995 r8997  
    2323import os
    2424from zope.component.hooks import setSite, clearSite
     25from zope.component import createObject
    2526from zope.securitypolicy.interfaces import IPrincipalRoleMap
    2627from zope.interface.verify import verifyClass, verifyObject
     
    3334from waeup.kofa.university.certificate import Certificate, CertificateCourse
    3435from waeup.kofa.university.course import Course
    35 from waeup.kofa.university.department import Department
     36from waeup.kofa.university import Faculty, Department
    3637from waeup.kofa.university.batching import FacultyProcessor
    3738
     
    4344    '\n')[0].split(',')
    4445
    45 class TestFacultyProcessor(FunctionalTestCase):
     46class UniversityProcessorSetup(FunctionalTestCase):
    4647
    4748    layer = FunctionalLayer
    4849
    4950    def setUp(self):
    50         super(TestFacultyProcessor, self).setUp()
     51        super(UniversityProcessorSetup, self).setUp()
    5152        self.dc_root = tempfile.mkdtemp()
    5253        self.workdir = tempfile.mkdtemp()
     
    5859        self.app['users'].addUser('bob', 'bobssecret')
    5960
     61        # Populate university
     62        self.certificate = createObject('waeup.Certificate')
     63        self.certificate.code = 'CERT1'
     64        self.app['faculties']['FAC1'] = Faculty(code='FAC1')
     65        self.app['faculties']['FAC1']['DEP1'] = Department(code='DEP1')
     66        self.app['faculties']['FAC1']['DEP1'].certificates.addCertificate(
     67            self.certificate)
     68        self.course = createObject('waeup.Course')
     69        self.course.code = 'CRS1'
     70        self.app['faculties']['FAC1']['DEP1'].courses.addCourse(
     71            self.course)
     72        #self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
     73        #    self.course, level=100)
     74        return
     75
     76    def tearDown(self):
     77        super(UniversityProcessorSetup, self).tearDown()
     78        shutil.rmtree(self.workdir)
     79        shutil.rmtree(self.dc_root)
     80        clearSite()
     81        return
     82
     83class TestFacultyProcessor(UniversityProcessorSetup):
     84
     85    def setUp(self):
     86        super(TestFacultyProcessor, self).setUp()
     87
    6088        self.proc = FacultyProcessor()
    6189        self.site1 = dict(faculties=dict())
     
    6391        self.row = dict(code='FAC')
    6492
    65         self.processor = FacultyProcessor()
    6693        self.csv_file_faculty = os.path.join(self.workdir, 'sample_faculty_data.csv')
    6794        open(self.csv_file_faculty, 'wb').write(FACULTY_SAMPLE_DATA)
    68         return
    69 
    70     def tearDown(self):
    71         super(TestFacultyProcessor, self).tearDown()
    72         shutil.rmtree(self.workdir)
    73         shutil.rmtree(self.dc_root)
    74         clearSite()
    7595        return
    7696
     
    97117    def test_checkConversion(self):
    98118        # Make sure we can check conversions.
    99         errs, inv_errs, conv_dict = self.processor.checkConversion(
     119        errs, inv_errs, conv_dict = self.proc.checkConversion(
    100120            dict(faculty_code='ABC', local_roles='[]'))
    101121        self.assertEqual(len(errs),0)
    102122
    103         errs, inv_errs, conv_dict = self.processor.checkConversion(
     123        errs, inv_errs, conv_dict = self.proc.checkConversion(
    104124            dict(faculty_code='ABC',
    105125            local_roles="['nonsense'"
     
    107127        self.assertEqual(len(errs),1)
    108128        self.assertEqual(errs, [('local_roles', 'Error')])
    109         errs, inv_errs, conv_dict = self.processor.checkConversion(
     129        errs, inv_errs, conv_dict = self.proc.checkConversion(
    110130            dict(faculty_code='ABC',
    111131            local_roles="('abc')"
     
    113133        self.assertEqual(len(errs),1)
    114134        self.assertEqual(errs, [('local_roles', 'no list')])
    115         errs, inv_errs, conv_dict = self.processor.checkConversion(
     135        errs, inv_errs, conv_dict = self.proc.checkConversion(
    116136            dict(faculty_code='ABC',
    117137            local_roles="[('ABC')]"
     
    119139        self.assertEqual(len(errs),1)
    120140        self.assertEqual(errs, [('local_roles', 'no dicts')])
    121         errs, inv_errs, conv_dict = self.processor.checkConversion(
     141        errs, inv_errs, conv_dict = self.proc.checkConversion(
    122142            dict(faculty_code='ABC',
    123143            local_roles="('abc')"
     
    125145        self.assertEqual(len(errs),1)
    126146        self.assertEqual(errs, [('local_roles', 'no list')])
    127         errs, inv_errs, conv_dict = self.processor.checkConversion(
     147        errs, inv_errs, conv_dict = self.proc.checkConversion(
    128148            dict(faculty_code='ABC', local_roles=
    129149            "[{'name':'bob','local_role':'waeup.local.DepartmentManager'},]"
     
    131151        self.assertEqual(len(errs),1)
    132152        self.assertEqual(errs, [('local_roles', 'user_name or local_role missing')])
    133         errs, inv_errs, conv_dict = self.processor.checkConversion(
     153        errs, inv_errs, conv_dict = self.proc.checkConversion(
    134154            dict(faculty_code='ABC', local_roles=
    135155            "[{'user_name':'bob','localrole':'waeup.local.DepartmentManager'},]"
     
    137157        self.assertEqual(len(errs),1)
    138158        self.assertEqual(errs, [('local_roles', 'user_name or local_role missing')])
    139         errs, inv_errs, conv_dict = self.processor.checkConversion(
     159        errs, inv_errs, conv_dict = self.proc.checkConversion(
    140160            dict(faculty_code='ABC', local_roles=
    141161            "[{'user_name':'bob','local_role':'waeup.local.Boss'},]"
     
    143163        self.assertEqual(len(errs),1)
    144164        self.assertEqual(errs, [('local_roles', 'waeup.local.Boss not allowed')])
    145         errs, inv_errs, conv_dict = self.processor.checkConversion(
     165        errs, inv_errs, conv_dict = self.proc.checkConversion(
    146166            dict(faculty_code='ABC', local_roles=
    147167            "[{'user_name':'john','local_role':'waeup.local.DepartmentManager'},]"
     
    149169        self.assertEqual(len(errs),1)
    150170        self.assertEqual(errs, [('local_roles', 'john does not exist')])
    151         errs, inv_errs, conv_dict = self.processor.checkConversion(
     171        errs, inv_errs, conv_dict = self.proc.checkConversion(
    152172            dict(faculty_code='ABC', local_roles=
    153173            "[{'user_name':'bob','local_role':'waeup.local.DepartmentManager'},]"
     
    157177
    158178    def test_import(self):
    159         num, num_warns, fin_file, fail_file = self.processor.doImport(
     179        num, num_warns, fin_file, fail_file = self.proc.doImport(
    160180            self.csv_file_faculty, FACULTY_HEADER_FIELDS)
    161181        content = open(fail_file).read()
     
    181201        shutil.rmtree(os.path.dirname(fin_file))
    182202
    183 class TestDepartmentProcessors(unittest.TestCase):
    184 
    185     def setUp(self):
     203class TestDepartmentProcessor(UniversityProcessorSetup):
     204
     205    def setUp(self):
     206        super(TestDepartmentProcessor, self).setUp()
    186207        self.proc = DepartmentProcessor()
    187208        self.site0 = dict()
     
    236257        return
    237258
    238 class CourseProcessorTests(FunctionalTestCase):
    239 
    240     layer = FunctionalLayer
     259class CourseProcessorTests(UniversityProcessorSetup):
     260
     261    #layer = FunctionalLayer
    241262
    242263    def setUp(self):
    243264        super(CourseProcessorTests, self).setUp()
    244265        self.proc = CourseProcessor()
    245         self.site0 = dict()
    246         self.site1 = dict(faculties=dict())
    247         self.site2 = dict(faculties=dict(FAC=dict()))
    248         self.department1 = Department(code='DPT')
    249         self.department2 = Department(code='DPT')
    250         self.course = Course(code='CRS')
    251         self.department2.courses['CRS'] = self.course
    252         self.site3 = dict(faculties=dict(FAC=dict(DPT=self.department1)))
    253         self.site4 = dict(faculties=dict(FAC=dict(DPT=self.department2)))
    254         self.row = dict(department_code='DPT', faculty_code='FAC', code="CRS")
     266        self.row1 = dict(department_code='DEP2', faculty_code='FAC1', code="CRS1")
     267        self.row2 = dict(department_code='DEP1', faculty_code='FAC2', code="CRS1")
     268        self.row3 = dict(department_code='DEP1', faculty_code='FAC1', code="CRS2")
     269        self.row4 = dict(department_code='DEP1', faculty_code='FAC1', code="CRS1")
    255270        return
    256271
     
    263278    def test_parents_exist(self):
    264279        # make sure we lookup parents correctly
    265         result0 = self.proc.parentsExist(self.row, self.site0)
    266         result1 = self.proc.parentsExist(self.row, self.site1)
    267         result2 = self.proc.parentsExist(self.row, self.site2)
    268         result3 = self.proc.parentsExist(self.row, self.site3)
    269         result4 = self.proc.parentsExist(self.row, self.site4)
    270         self.assertTrue(result0 is False)
     280        result1 = self.proc.parentsExist(self.row1, self.app)
     281        result2 = self.proc.parentsExist(self.row2, self.app)
     282        result3 = self.proc.parentsExist(self.row3, self.app)
    271283        self.assertTrue(result1 is False)
    272284        self.assertTrue(result2 is False)
    273285        self.assertTrue(result3 is True)
    274         self.assertTrue(result4 is True)
    275286        return
    276287
    277288    def test_entry_exists(self):
    278289        # make sure we find an entry if it exists
    279         result0 = self.proc.entryExists(self.row, self.site0)
    280         result1 = self.proc.entryExists(self.row, self.site1)
    281         result2 = self.proc.entryExists(self.row, self.site2)
    282         result3 = self.proc.entryExists(self.row, self.site3)
    283         result4 = self.proc.entryExists(self.row, self.site4)
    284         self.assertTrue(result0 is False)
     290        result1 = self.proc.entryExists(self.row1, self.app)
     291        result2 = self.proc.entryExists(self.row2, self.app)
     292        result3 = self.proc.entryExists(self.row3, self.app)
     293        result4 = self.proc.entryExists(self.row4, self.app)
    285294        self.assertTrue(result1 is False)
    286295        self.assertTrue(result2 is False)
     
    291300    def test_get_entry(self):
    292301        # make sure we can get an entry if it exists
    293         result1 = self.proc.getEntry(self.row, self.site3)
    294         result2 = self.proc.getEntry(self.row, self.site4)
     302        result1 = self.proc.getEntry(self.row1, self.app)
     303        result2 = self.proc.getEntry(self.row4, self.app)
    295304        self.assertTrue(result1 is None)
    296305        self.assertTrue(result2 is self.course)
     
    299308    def test_del_entry(self):
    300309        # make sure we can delete entries
    301         self.assertTrue('CRS' in self.department2.courses.keys())
    302         self.proc.delEntry(self.row, self.site4)
    303         self.assertTrue('CRS' not in self.department2.courses.keys())
     310        self.assertTrue('CRS1' in self.app['faculties']['FAC1']['DEP1'].courses.keys())
     311        self.proc.delEntry(self.row4, self.app)
     312        self.assertTrue('CRS' not in self.app['faculties']['FAC1']['DEP1'].courses.keys())
    304313        return
    305314
Note: See TracChangeset for help on using the changeset viewer.