Ignore:
Timestamp:
13 Jul 2012, 06:09:32 (12 years ago)
Author:
Henrik Bettermann
Message:

For (re-)importing local roles we first need a reliable conversion checker.

File:
1 edited

Legend:

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

    r8920 r8994  
    1919# Tests for university related batching
    2020import unittest
    21 
     21import tempfile
     22import shutil
     23from zope.component.hooks import setSite, clearSite
    2224from zope.interface.verify import verifyClass, verifyObject
    2325from waeup.kofa.interfaces import IBatchProcessor
    2426from waeup.kofa.testing import FunctionalTestCase, FunctionalLayer
     27from waeup.kofa.app import University
    2528from waeup.kofa.university.batching import (
    2629    FacultyProcessor, DepartmentProcessor, CourseProcessor,
     
    2932from waeup.kofa.university.course import Course
    3033from waeup.kofa.university.department import Department
    31 
    32 
    33 class TestFacultyProcessor(unittest.TestCase):
     34from waeup.kofa.university.batching import FacultyProcessor
     35
     36
     37class TestFacultyProcessor(FunctionalTestCase):
     38
     39    layer = FunctionalLayer
    3440
    3541    def setUp(self):
     42        super(TestFacultyProcessor, self).setUp()
     43        self.dc_root = tempfile.mkdtemp()
     44        self.workdir = tempfile.mkdtemp()
     45        app = University()
     46        self.getRootFolder()['app'] = app
     47        self.app = self.getRootFolder()['app']
     48        setSite(app)
     49
     50        self.app['users'].addUser('bob', 'bobssecret')
     51
    3652        self.proc = FacultyProcessor()
    3753        self.site1 = dict(faculties=dict())
    3854        self.site2 = dict(faculties=dict(FAC='pseudo faculty'))
    3955        self.row = dict(code='FAC')
     56        self.processor = FacultyProcessor()
     57        return
     58
     59    def tearDown(self):
     60        super(TestFacultyProcessor, self).tearDown()
     61        shutil.rmtree(self.workdir)
     62        shutil.rmtree(self.dc_root)
     63        clearSite()
    4064        return
    4165
     
    5882        self.proc.delEntry(self.row, self.site2)
    5983        self.assertTrue('FAC' not in self.site2.keys())
     84        return
     85
     86    def test_checkConversion(self):
     87        # Make sure we can check conversions.
     88        errs, inv_errs, conv_dict = self.processor.checkConversion(
     89            dict(faculty_code='ABC', local_roles='[]'))
     90        self.assertEqual(len(errs),0)
     91
     92        errs, inv_errs, conv_dict = self.processor.checkConversion(
     93            dict(faculty_code='ABC',
     94            local_roles="['nonsense'"
     95            ))
     96        self.assertEqual(len(errs),1)
     97        self.assertEqual(errs, [('local_roles', 'Error')])
     98        errs, inv_errs, conv_dict = self.processor.checkConversion(
     99            dict(faculty_code='ABC',
     100            local_roles="('abc')"
     101            ))
     102        self.assertEqual(len(errs),1)
     103        self.assertEqual(errs, [('local_roles', 'no list')])
     104        errs, inv_errs, conv_dict = self.processor.checkConversion(
     105            dict(faculty_code='ABC',
     106            local_roles="[('ABC')]"
     107            ))
     108        self.assertEqual(len(errs),1)
     109        self.assertEqual(errs, [('local_roles', 'no dicts')])
     110        errs, inv_errs, conv_dict = self.processor.checkConversion(
     111            dict(faculty_code='ABC',
     112            local_roles="('abc')"
     113            ))
     114        self.assertEqual(len(errs),1)
     115        self.assertEqual(errs, [('local_roles', 'no list')])
     116        errs, inv_errs, conv_dict = self.processor.checkConversion(
     117            dict(faculty_code='ABC', local_roles=
     118            "[{'name':'bob','local_role':'waeup.local.DepartmentManager'},]"
     119            ))
     120        self.assertEqual(len(errs),1)
     121        self.assertEqual(errs, [('local_roles', 'user_name or local_role missing')])
     122        errs, inv_errs, conv_dict = self.processor.checkConversion(
     123            dict(faculty_code='ABC', local_roles=
     124            "[{'user_name':'bob','localrole':'waeup.local.DepartmentManager'},]"
     125            ))
     126        self.assertEqual(len(errs),1)
     127        self.assertEqual(errs, [('local_roles', 'user_name or local_role missing')])
     128        errs, inv_errs, conv_dict = self.processor.checkConversion(
     129            dict(faculty_code='ABC', local_roles=
     130            "[{'user_name':'bob','local_role':'waeup.local.Boss'},]"
     131            ))
     132        self.assertEqual(len(errs),1)
     133        self.assertEqual(errs, [('local_roles', 'waeup.local.Boss not allowed')])
     134        errs, inv_errs, conv_dict = self.processor.checkConversion(
     135            dict(faculty_code='ABC', local_roles=
     136            "[{'user_name':'john','local_role':'waeup.local.DepartmentManager'},]"
     137            ))
     138        self.assertEqual(len(errs),1)
     139        self.assertEqual(errs, [('local_roles', 'john does not exist')])
     140        errs, inv_errs, conv_dict = self.processor.checkConversion(
     141            dict(faculty_code='ABC', local_roles=
     142            "[{'user_name':'bob','local_role':'waeup.local.DepartmentManager'},]"
     143            ))
     144        self.assertEqual(len(errs),0)
    60145        return
    61146
Note: See TracChangeset for help on using the changeset viewer.