Ignore:
Timestamp:
1 Sep 2014, 12:05:55 (10 years ago)
Author:
Henrik Bettermann
Message:

Extend and fix CertCourseProcessorTests?. Improve logging.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/university
Files:
1 added
2 edited

Legend:

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

    r11779 r11790  
    353353    iface = ICertificateCourse
    354354
    355     location_fields = ['course', 'level', 'faculty_code', 'department_code',
    356                        'certificate_code',]
     355    location_fields = ['certificate_code', 'course', 'level', 'faculty_code',
     356                       'department_code',]
    357357    factory_name = 'waeup.CertificateCourse'
    358358
  • main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_batching.py

    r9754 r11790  
    8181    '\n')[0].split(',')
    8282
     83
     84CERTIFICATECOURSE_SAMPLE_DATA = open(
     85    os.path.join(os.path.dirname(__file__), 'sample_certificatecourse_data.csv'),
     86    'rb').read()
     87
     88CERTIFICATECOURSE_HEADER_FIELDS = CERTIFICATECOURSE_SAMPLE_DATA.split(
     89    '\n')[0].split(',')
     90
    8391class UniversityProcessorSetup(FunctionalTestCase):
    8492
     
    9098        self.workdir = tempfile.mkdtemp()
    9199        app = University()
     100        app['datacenter'].setStoragePath(self.dc_root)
    92101        self.getRootFolder()['app'] = app
    93102        self.app = self.getRootFolder()['app']
     
    312321        # Logging message from updateEntry
    313322        self.assertTrue(
    314             'INFO - system - Department Processor - sample_department_data '
    315             '- DEP2 - updated: local_roles=anne|waeup.local.DepartmentManager, '
    316             'code=DEP2\n'
     323            'INFO - system - Faculty Processor - sample_faculty_data_update - '
     324            'FAC1 - updated: code=FAC1'
     325            in logcontent)
     326        self.assertTrue(
     327            'INFO - system - Faculty Processor - sample_faculty_data_update - '
     328            'FAC2 - updated: local_roles=bob|waeup.local.DepartmentManager, '
     329            'code=FAC2'
     330            in logcontent)
     331        self.assertTrue(
     332            'INFO - system - Faculty Processor - sample_faculty_data_update - '
     333            'FAC3 - updated: code=FAC3'
     334            in logcontent)
     335        self.assertTrue(
     336            'INFO - system - Faculty Processor - sample_faculty_data_update - '
     337            'FAC4 - updated: code=FAC4'
    317338            in logcontent)
    318339        shutil.rmtree(os.path.dirname(fin_file))
     
    636657
    637658
    638 class CertCourseProcessorTests(FunctionalTestCase):
     659class CertCourseProcessorTests(UniversityProcessorSetup):
    639660
    640661    layer = FunctionalLayer
     
    643664        super(CertCourseProcessorTests, self).setUp()
    644665        self.proc = CertificateCourseProcessor()
    645         self.site0 = dict()
    646         self.site1 = dict(faculties=dict())
    647         self.site2 = dict(faculties=dict(FAC=dict()))
    648         self.department1 = Department(code='DPT')
    649         self.department2 = Department(code='DPT')
    650         self.certificate = Certificate(code='CRT')
    651         self.department2.certificates['CRT'] = self.certificate
    652         self.course = Course(code='CRS')
    653         self.department2.certificates['CRT'].addCertCourse(self.course)
    654         self.cert_course = self.certificate['CRS_100']
    655         self.department2.courses['CRS'] = self.course
    656         self.site3 = dict(faculties=dict(FAC=dict(DPT=self.department1)))
    657         self.site4 = dict(faculties=dict(FAC=dict(DPT=self.department2)))
    658         self.row = dict(
    659             department_code='DPT',
    660             faculty_code='FAC',
    661             certificate_code='CRT',
    662             course=self.course, level='100',
    663             code='CRS_100')
     666        self.certificate.addCertCourse(self.course)
     667        self.row1 = dict(
     668            department_code='DEP1',
     669            faculty_code='FAC1',
     670            certificate_code='CRT1',
     671            course=self.course, level='100')
     672        self.row2 = dict(
     673            department_code='DEP1',
     674            faculty_code='FAC1',
     675            certificate_code='CRT2',
     676            course=self.course, level='100')
     677        self.csv_file_certificatecourse = os.path.join(
     678            self.workdir, 'sample_certificatecourse_data.csv')
     679        open(self.csv_file_certificatecourse, 'wb').write(CERTIFICATECOURSE_SAMPLE_DATA)
    664680        return
    665681
     
    672688    def test_parents_exist(self):
    673689        # make sure we can find all certificate parents
    674         result0 = self.proc.parentsExist(self.row, self.site0)
    675         result1 = self.proc.parentsExist(self.row, self.site1)
    676         result2 = self.proc.parentsExist(self.row, self.site2)
    677         result3 = self.proc.parentsExist(self.row, self.site3)
    678         result4 = self.proc.parentsExist(self.row, self.site4)
    679         self.assertTrue(result0 is False)
    680         self.assertTrue(result1 is False)
    681         self.assertTrue(result2 is False)
    682         self.assertTrue(result3 is False)
    683         self.assertTrue(result4 is True)
     690        result1 = self.proc.parentsExist(self.row1, self.app)
     691        self.assertTrue(result1)
     692        result2 = self.proc.parentsExist(self.row2, self.app)
     693        self.assertFalse(result2)
    684694        return
    685695
    686696    def test_entry_exists(self):
    687697        # make sure we find an entry if it exists
    688         result0 = self.proc.entryExists(self.row, self.site0)
    689         result1 = self.proc.entryExists(self.row, self.site1)
    690         result2 = self.proc.entryExists(self.row, self.site2)
    691         result3 = self.proc.entryExists(self.row, self.site3)
    692         result4 = self.proc.entryExists(self.row, self.site4)
    693         self.assertTrue(result0 is False)
    694         self.assertTrue(result1 is False)
    695         self.assertTrue(result2 is False)
    696         self.assertTrue(result3 is False)
    697         self.assertTrue(result4 is True)
     698        result1 = self.proc.entryExists(self.row1, self.app)
     699        self.assertTrue(result1)
     700        result2 = self.proc.entryExists(self.row2, self.app)
     701        self.assertFalse(result2)
    698702        return
    699703
    700704    def test_get_entry(self):
    701705        # make sure we can get an entry if it exists
    702         result1 = self.proc.getEntry(self.row, self.site3)
    703         result2 = self.proc.getEntry(self.row, self.site4)
    704         self.assertTrue(result1 is None)
    705         self.assertTrue(result2 is self.cert_course)
     706        result1 = self.proc.getEntry(self.row1, self.app)
     707        self.assertTrue(result1 is self.certificate['CRS1_100'])
     708        result2 = self.proc.getEntry(self.row2, self.app)
     709        self.assertFalse(result2 is self.certificate['CRS1_100'])
    706710        return
    707711
    708712    def test_del_entry(self):
    709713        # make sure we can delete entries
    710         self.assertTrue('CRS_100' in self.certificate.keys())
    711         self.proc.delEntry(self.row, self.site4)
    712         self.assertTrue('CRS_100' not in self.certificate.keys())
    713         return
     714        self.assertTrue('CRS1_100' in self.certificate.keys())
     715        self.proc.delEntry(self.row1, self.app)
     716        self.assertTrue('CRS1_100' not in self.certificate.keys())
     717        return
     718
     719    def test_import(self):
     720        num, num_warns, fin_file, fail_file = self.proc.doImport(
     721            self.csv_file_certificatecourse, CERTIFICATECOURSE_HEADER_FIELDS)
     722        content = open(fail_file).read()
     723        self.assertEqual(num_warns,2)
     724        self.assertEqual(
     725            content,
     726            'faculty_code,course,level,department_code,certificate_code,'
     727            '--ERRORS--\r\nFAC1,CRS1,100,DEP1,CRT1,'
     728            'This object already exists. Skipping.\r\nFAC1,CRS1,100,DEP1,CRT2,'
     729            'Not all parents do exist yet. Skipping\r\n'
     730
     731            )
     732        logcontent = open(self.logfile).read()
     733        # Logging message from updateEntry
     734        self.assertTrue(
     735            'INFO - system - CertificateCourse Processor - '
     736            'sample_certificatecourse_data - CRT1 - updated: '
     737            'course=CRS1, level=200\n'
     738            in logcontent)
     739
     740        return
Note: See TracChangeset for help on using the changeset viewer.