Changeset 7933 for main/waeup.kofa/trunk/src/waeup/kofa/students/tests
- Timestamp:
- 21 Mar 2012, 13:42:00 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students/tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_batching.py
r7811 r7933 16 16 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 17 ## 18 """Unit tests for students-related data importers.18 """Unit tests for students-related data processors. 19 19 """ 20 20 import os … … 95 95 '\n')[0].split(',') 96 96 97 class Student ImporterTest(FunctionalTestCase):97 class StudentProcessorTest(FunctionalTestCase): 98 98 99 99 layer = FunctionalLayer 100 100 101 101 def setUp(self): 102 super(Student ImporterTest, self).setUp()102 super(StudentProcessorTest, self).setUp() 103 103 # Setup a sample site for each test 104 104 app = University() … … 124 124 self.app['students'].addStudent(student) 125 125 self.student = self.app['students'][student.student_id] 126 self. importer = StudentProcessor()126 self.processor = StudentProcessor() 127 127 self.workdir = tempfile.mkdtemp() 128 128 self.csv_file = os.path.join(self.workdir, 'sample_student_data.csv') … … 139 139 140 140 def tearDown(self): 141 super(Student ImporterTest, self).tearDown()141 super(StudentProcessorTest, self).tearDown() 142 142 shutil.rmtree(self.workdir) 143 143 shutil.rmtree(self.dc_root) … … 147 147 def test_interface(self): 148 148 # Make sure we fulfill the interface contracts. 149 assert verifyObject(IBatchProcessor, self. importer) is True149 assert verifyObject(IBatchProcessor, self.processor) is True 150 150 assert verifyClass( 151 151 IBatchProcessor, StudentProcessor) is True 152 152 153 153 def test_parentsExist(self): 154 self.assertFalse(self. importer.parentsExist(None, dict()))155 self.assertTrue(self. importer.parentsExist(None, self.app))154 self.assertFalse(self.processor.parentsExist(None, dict())) 155 self.assertTrue(self.processor.parentsExist(None, self.app)) 156 156 157 157 def test_entryExists(self): 158 assert self. importer.entryExists(158 assert self.processor.entryExists( 159 159 dict(student_id='ID_NONE'), self.app) is False 160 assert self. importer.entryExists(160 assert self.processor.entryExists( 161 161 dict(reg_number='123'), self.app) is True 162 162 163 163 def test_getParent(self): 164 parent = self. importer.getParent(None, self.app)164 parent = self.processor.getParent(None, self.app) 165 165 assert parent is self.app['students'] 166 166 167 167 def test_getEntry(self): 168 assert self. importer.getEntry(168 assert self.processor.getEntry( 169 169 dict(student_id='ID_NONE'), self.app) is None 170 assert self. importer.getEntry(170 assert self.processor.getEntry( 171 171 dict(student_id=self.student.student_id), self.app) is self.student 172 172 173 173 def test_addEntry(self): 174 174 new_student = Student() 175 self. importer.addEntry(175 self.processor.addEntry( 176 176 new_student, dict(), self.app) 177 177 assert len(self.app['students'].keys()) == 2 178 178 179 179 def test_checkConversion(self): 180 errs, inv_errs, conv_dict = self. importer.checkConversion(180 errs, inv_errs, conv_dict = self.processor.checkConversion( 181 181 dict(reg_number='1', reg_state='admitted')) 182 182 self.assertEqual(len(errs),0) 183 errs, inv_errs, conv_dict = self. importer.checkConversion(183 errs, inv_errs, conv_dict = self.processor.checkConversion( 184 184 dict(reg_number='1', reg_state='')) 185 185 self.assertEqual(len(errs),1) 186 186 self.assertTrue(('reg_state', 'no value provided') in errs) 187 errs, inv_errs, conv_dict = self. importer.checkConversion(187 errs, inv_errs, conv_dict = self.processor.checkConversion( 188 188 dict(reg_number='1', reg_state='nonsense')) 189 189 self.assertEqual(len(errs),1) … … 192 192 def test_delEntry(self): 193 193 assert self.student.student_id in self.app['students'].keys() 194 self. importer.delEntry(194 self.processor.delEntry( 195 195 dict(reg_number=self.student.reg_number), self.app) 196 196 assert self.student.student_id not in self.app['students'].keys() 197 197 198 198 def test_import(self): 199 num, num_warns, fin_file, fail_file = self. importer.doImport(199 num, num_warns, fin_file, fail_file = self.processor.doImport( 200 200 self.csv_file, STUDENT_HEADER_FIELDS) 201 201 self.assertEqual(num_warns,0) … … 205 205 206 206 def test_import_update(self): 207 num, num_warns, fin_file, fail_file = self. importer.doImport(207 num, num_warns, fin_file, fail_file = self.processor.doImport( 208 208 self.csv_file, STUDENT_HEADER_FIELDS) 209 209 shutil.rmtree(os.path.dirname(fin_file)) 210 num, num_warns, fin_file, fail_file = self. importer.doImport(210 num, num_warns, fin_file, fail_file = self.processor.doImport( 211 211 self.csv_file_update, STUDENT_HEADER_FIELDS_UPDATE, 'update') 212 212 self.assertEqual(num_warns,0) … … 214 214 215 215 def test_import_update2(self): 216 num, num_warns, fin_file, fail_file = self. importer.doImport(216 num, num_warns, fin_file, fail_file = self.processor.doImport( 217 217 self.csv_file, STUDENT_HEADER_FIELDS) 218 218 shutil.rmtree(os.path.dirname(fin_file)) 219 num, num_warns, fin_file, fail_file = self. importer.doImport(219 num, num_warns, fin_file, fail_file = self.processor.doImport( 220 220 self.csv_file_update2, STUDENT_HEADER_FIELDS_UPDATE2, 'update') 221 221 self.assertEqual(num_warns,0) … … 223 223 224 224 def test_import_remove(self): 225 num, num_warns, fin_file, fail_file = self. importer.doImport(225 num, num_warns, fin_file, fail_file = self.processor.doImport( 226 226 self.csv_file, STUDENT_HEADER_FIELDS) 227 227 shutil.rmtree(os.path.dirname(fin_file)) 228 num, num_warns, fin_file, fail_file = self. importer.doImport(228 num, num_warns, fin_file, fail_file = self.processor.doImport( 229 229 self.csv_file_update, STUDENT_HEADER_FIELDS_UPDATE, 'remove') 230 230 self.assertEqual(num_warns,0) … … 232 232 233 233 def test_import_migration_data(self): 234 num, num_warns, fin_file, fail_file = self. importer.doImport(234 num, num_warns, fin_file, fail_file = self.processor.doImport( 235 235 self.csv_file_migration, STUDENT_HEADER_FIELDS_MIGRATION) 236 236 self.assertEqual(num_warns,2) … … 251 251 252 252 253 class StudentStudyCourse ImporterTest(FunctionalTestCase):253 class StudentStudyCourseProcessorTest(FunctionalTestCase): 254 254 255 255 layer = FunctionalLayer 256 256 257 257 def setUp(self): 258 super(StudentStudyCourse ImporterTest, self).setUp()258 super(StudentStudyCourseProcessorTest, self).setUp() 259 259 self.dc_root = tempfile.mkdtemp() 260 260 self.workdir = tempfile.mkdtemp() … … 283 283 self.certificate) 284 284 285 self. importer = StudentStudyCourseProcessor()285 self.processor = StudentStudyCourseProcessor() 286 286 self.csv_file = os.path.join( 287 287 self.workdir, 'sample_studycourse_data.csv') … … 290 290 291 291 def tearDown(self): 292 super(StudentStudyCourse ImporterTest, self).tearDown()292 super(StudentStudyCourseProcessorTest, self).tearDown() 293 293 shutil.rmtree(self.workdir) 294 294 shutil.rmtree(self.dc_root) … … 298 298 def test_interface(self): 299 299 # Make sure we fulfill the interface contracts. 300 assert verifyObject(IBatchProcessor, self. importer) is True300 assert verifyObject(IBatchProcessor, self.processor) is True 301 301 assert verifyClass( 302 302 IBatchProcessor, StudentStudyCourseProcessor) is True 303 303 304 304 def test_entryExists(self): 305 assert self. importer.entryExists(305 assert self.processor.entryExists( 306 306 dict(reg_number='REG_NONE'), self.app) is False 307 assert self. importer.entryExists(307 assert self.processor.entryExists( 308 308 dict(reg_number='1'), self.app) is True 309 309 310 310 def test_getEntry(self): 311 student = self. importer.getEntry(311 student = self.processor.getEntry( 312 312 dict(reg_number='1'), self.app).__parent__ 313 313 self.assertEqual(student.reg_number,'1') 314 314 315 315 def test_checkConversion(self): 316 errs, inv_errs, conv_dict = self. importer.checkConversion(316 errs, inv_errs, conv_dict = self.processor.checkConversion( 317 317 dict(reg_number='1', certificate='CERT1', current_level='200')) 318 318 self.assertEqual(len(errs),0) 319 errs, inv_errs, conv_dict = self. importer.checkConversion(319 errs, inv_errs, conv_dict = self.processor.checkConversion( 320 320 dict(reg_number='1', certificate='CERT999')) 321 321 self.assertEqual(len(errs),1) 322 322 self.assertTrue(('certificate', u'Invalid value') in errs) 323 errs, inv_errs, conv_dict = self. importer.checkConversion(323 errs, inv_errs, conv_dict = self.processor.checkConversion( 324 324 dict(reg_number='1', certificate='CERT1', current_level='100')) 325 325 self.assertEqual(len(errs),1) 326 326 self.assertTrue(('current_level','not in range') in errs) 327 327 # If we import only current_level, no conversion checking is done. 328 errs, inv_errs, conv_dict = self. importer.checkConversion(328 errs, inv_errs, conv_dict = self.processor.checkConversion( 329 329 dict(reg_number='1', current_level='100')) 330 330 self.assertEqual(len(errs),0) 331 331 332 332 def test_import(self): 333 num, num_warns, fin_file, fail_file = self. importer.doImport(333 num, num_warns, fin_file, fail_file = self.processor.doImport( 334 334 self.csv_file, STUDYCOURSE_HEADER_FIELDS,'update') 335 335 self.assertEqual(num_warns,1) 336 studycourse = self. importer.getEntry(dict(reg_number='1'), self.app)336 studycourse = self.processor.getEntry(dict(reg_number='1'), self.app) 337 337 self.assertEqual(studycourse.certificate.code, u'CERT1') 338 338 shutil.rmtree(os.path.dirname(fin_file)) 339 339 340 class StudentStudyLevel ImporterTest(FunctionalTestCase):340 class StudentStudyLevelProcessorTest(FunctionalTestCase): 341 341 342 342 layer = FunctionalLayer 343 343 344 344 def setUp(self): 345 super(StudentStudyLevel ImporterTest, self).setUp()345 super(StudentStudyLevelProcessorTest, self).setUp() 346 346 self.dc_root = tempfile.mkdtemp() 347 347 self.workdir = tempfile.mkdtemp() … … 374 374 self.workdir, 'sample_studycourse_data.csv') 375 375 open(studycourse_file, 'wb').write(STUDYCOURSE_SAMPLE_DATA) 376 importer = StudentStudyCourseProcessor()377 num, num_warns, fin_file, fail_file = importer.doImport(376 processor = StudentStudyCourseProcessor() 377 num, num_warns, fin_file, fail_file = processor.doImport( 378 378 studycourse_file, STUDYCOURSE_HEADER_FIELDS,'update') 379 379 shutil.rmtree(os.path.dirname(fin_file)) 380 380 381 self. importer = StudentStudyLevelProcessor()381 self.processor = StudentStudyLevelProcessor() 382 382 self.csv_file = os.path.join( 383 383 self.workdir, 'sample_studylevel_data.csv') … … 385 385 386 386 def tearDown(self): 387 super(StudentStudyLevel ImporterTest, self).tearDown()387 super(StudentStudyLevelProcessorTest, self).tearDown() 388 388 shutil.rmtree(self.workdir) 389 389 shutil.rmtree(self.dc_root) … … 393 393 def test_interface(self): 394 394 # Make sure we fulfill the interface contracts. 395 assert verifyObject(IBatchProcessor, self. importer) is True395 assert verifyObject(IBatchProcessor, self.processor) is True 396 396 assert verifyClass( 397 397 IBatchProcessor, StudentStudyLevelProcessor) is True 398 398 399 399 def test_checkConversion(self): 400 errs, inv_errs, conv_dict = self. importer.checkConversion(400 errs, inv_errs, conv_dict = self.processor.checkConversion( 401 401 dict(reg_number='1', level='220')) 402 402 self.assertEqual(len(errs),0) 403 errs, inv_errs, conv_dict = self. importer.checkConversion(403 errs, inv_errs, conv_dict = self.processor.checkConversion( 404 404 dict(reg_number='1', level='900')) 405 405 self.assertEqual(len(errs),1) 406 406 self.assertTrue(('level','no valid integer') in errs) 407 errs, inv_errs, conv_dict = self. importer.checkConversion(407 errs, inv_errs, conv_dict = self.processor.checkConversion( 408 408 dict(reg_number='1', level='xyz')) 409 409 self.assertEqual(len(errs),1) … … 411 411 412 412 def test_import(self): 413 num, num_warns, fin_file, fail_file = self. importer.doImport(413 num, num_warns, fin_file, fail_file = self.processor.doImport( 414 414 self.csv_file, STUDYLEVEL_HEADER_FIELDS,'create') 415 415 self.assertEqual(num_warns,2) 416 assert self. importer.entryExists(416 assert self.processor.entryExists( 417 417 dict(reg_number='1', level='100'), self.app) is True 418 studylevel = self. importer.getEntry(418 studylevel = self.processor.getEntry( 419 419 dict(reg_number='1', level='100'), self.app) 420 420 self.assertEqual(studylevel.__parent__.certificate.code, u'CERT1') … … 425 425 426 426 427 class CourseTicket ImporterTest(FunctionalTestCase):427 class CourseTicketProcessorTest(FunctionalTestCase): 428 428 429 429 layer = FunctionalLayer 430 430 431 431 def setUp(self): 432 super(CourseTicket ImporterTest, self).setUp()432 super(CourseTicketProcessorTest, self).setUp() 433 433 self.dc_root = tempfile.mkdtemp() 434 434 self.workdir = tempfile.mkdtemp() … … 470 470 self.workdir, 'sample_studycourse_data.csv') 471 471 open(studycourse_file, 'wb').write(STUDYCOURSE_SAMPLE_DATA) 472 importer = StudentStudyCourseProcessor()473 num, num_warns, fin_file, fail_file = importer.doImport(472 processor = StudentStudyCourseProcessor() 473 num, num_warns, fin_file, fail_file = processor.doImport( 474 474 studycourse_file, STUDYCOURSE_HEADER_FIELDS,'update') 475 475 shutil.rmtree(os.path.dirname(fin_file)) 476 476 477 477 # Import study levels 478 importer = StudentStudyLevelProcessor()478 processor = StudentStudyLevelProcessor() 479 479 studylevel_file = os.path.join( 480 480 self.workdir, 'sample_studylevel_data.csv') 481 481 open(studylevel_file, 'wb').write(STUDYLEVEL_SAMPLE_DATA) 482 num, num_warns, fin_file, fail_file = importer.doImport(482 num, num_warns, fin_file, fail_file = processor.doImport( 483 483 studylevel_file, STUDYLEVEL_HEADER_FIELDS,'create') 484 484 shutil.rmtree(os.path.dirname(fin_file)) 485 485 486 self. importer = CourseTicketProcessor()486 self.processor = CourseTicketProcessor() 487 487 self.csv_file = os.path.join( 488 488 self.workdir, 'sample_courseticket_data.csv') … … 490 490 491 491 def tearDown(self): 492 super(CourseTicket ImporterTest, self).tearDown()492 super(CourseTicketProcessorTest, self).tearDown() 493 493 shutil.rmtree(self.workdir) 494 494 shutil.rmtree(self.dc_root) … … 498 498 def test_interface(self): 499 499 # Make sure we fulfill the interface contracts. 500 assert verifyObject(IBatchProcessor, self. importer) is True500 assert verifyObject(IBatchProcessor, self.processor) is True 501 501 assert verifyClass( 502 502 IBatchProcessor, CourseTicketProcessor) is True 503 503 504 504 def test_checkConversion(self): 505 errs, inv_errs, conv_dict = self. importer.checkConversion(505 errs, inv_errs, conv_dict = self.processor.checkConversion( 506 506 dict(reg_number='1', code='COURSE1', level='220')) 507 507 self.assertEqual(len(errs),0) 508 errs, inv_errs, conv_dict = self. importer.checkConversion(508 errs, inv_errs, conv_dict = self.processor.checkConversion( 509 509 dict(reg_number='1', code='COURSE2', level='220')) 510 510 self.assertEqual(len(errs),1) … … 513 513 def test_import(self): 514 514 515 num, num_warns, fin_file, fail_file = self. importer.doImport(515 num, num_warns, fin_file, fail_file = self.processor.doImport( 516 516 self.csv_file, COURSETICKET_HEADER_FIELDS,'create') 517 517 518 518 self.assertEqual(num_warns,2) 519 assert self. importer.entryExists(519 assert self.processor.entryExists( 520 520 dict(reg_number='1', level='100', code='COURSE1'), self.app) is True 521 courseticket = self. importer.getEntry(521 courseticket = self.processor.getEntry( 522 522 dict(reg_number='1', level='100', code='COURSE1'), self.app) 523 523 self.assertEqual(courseticket.__parent__.__parent__.certificate.code, u'CERT1') … … 533 533 shutil.rmtree(os.path.dirname(fin_file)) 534 534 535 class Payment ImporterTest(FunctionalTestCase):535 class PaymentProcessorTest(FunctionalTestCase): 536 536 537 537 layer = FunctionalLayer 538 538 539 539 def setUp(self): 540 super(Payment ImporterTest, self).setUp()540 super(PaymentProcessorTest, self).setUp() 541 541 self.dc_root = tempfile.mkdtemp() 542 542 self.workdir = tempfile.mkdtemp() … … 566 566 shutil.rmtree(os.path.dirname(fin_file)) 567 567 568 self. importer = StudentOnlinePaymentProcessor()568 self.processor = StudentOnlinePaymentProcessor() 569 569 self.csv_file = os.path.join( 570 570 self.workdir, 'sample_payment_data.csv') … … 572 572 573 573 def tearDown(self): 574 super(Payment ImporterTest, self).tearDown()574 super(PaymentProcessorTest, self).tearDown() 575 575 shutil.rmtree(self.workdir) 576 576 shutil.rmtree(self.dc_root) … … 580 580 def test_interface(self): 581 581 # Make sure we fulfill the interface contracts. 582 assert verifyObject(IBatchProcessor, self. importer) is True582 assert verifyObject(IBatchProcessor, self.processor) is True 583 583 assert verifyClass( 584 584 IBatchProcessor, StudentOnlinePaymentProcessor) is True 585 585 586 586 def test_getEntry(self): 587 assert self. importer.getEntry(587 assert self.processor.getEntry( 588 588 dict(student_id='ID_NONE', p_id='nonsense'), self.app) is None 589 assert self. importer.getEntry(589 assert self.processor.getEntry( 590 590 dict(student_id=self.student.student_id, p_id='p123'), 591 591 self.app) is self.student['payments']['p123'] 592 assert self. importer.getEntry(592 assert self.processor.getEntry( 593 593 dict(student_id=self.student.student_id, p_id='XXXXXX123'), 594 594 self.app) is self.student['payments']['p123'] … … 598 598 payment1 = createObject(u'waeup.StudentOnlinePayment') 599 599 payment1.p_id = 'p234' 600 self. importer.addEntry(600 self.processor.addEntry( 601 601 payment1, dict(student_id=self.student.student_id, p_id='p234'), 602 602 self.app) … … 606 606 payment1.p_id = 'nonsense' 607 607 # payment1.p_id will be replaced if p_id doesn't start with 'p' 608 self. importer.addEntry(608 self.processor.addEntry( 609 609 payment2, dict(student_id=self.student.student_id, p_id='XXXXXX456'), 610 610 self.app) … … 613 613 614 614 def test_checkConversion(self): 615 errs, inv_errs, conv_dict = self. importer.checkConversion(615 errs, inv_errs, conv_dict = self.processor.checkConversion( 616 616 dict(reg_number='1', p_id='3816951266236341955')) 617 617 self.assertEqual(len(errs),0) 618 errs, inv_errs, conv_dict = self. importer.checkConversion(618 errs, inv_errs, conv_dict = self.processor.checkConversion( 619 619 dict(reg_number='1', p_id='p1266236341955')) 620 620 self.assertEqual(len(errs),0) 621 errs, inv_errs, conv_dict = self. importer.checkConversion(621 errs, inv_errs, conv_dict = self.processor.checkConversion( 622 622 dict(reg_number='1', p_id='nonsense')) 623 623 self.assertEqual(len(errs),1) 624 624 timestamp = "%d" % int(time()*1000) 625 625 p_id = "p%s" % timestamp 626 errs, inv_errs, conv_dict = self. importer.checkConversion(626 errs, inv_errs, conv_dict = self.processor.checkConversion( 627 627 dict(reg_number='1', p_id=p_id)) 628 628 self.assertEqual(len(errs),0) 629 629 630 630 def test_import(self): 631 num, num_warns, fin_file, fail_file = self. importer.doImport(631 num, num_warns, fin_file, fail_file = self.processor.doImport( 632 632 self.csv_file, PAYMENT_HEADER_FIELDS,'create') 633 633 self.assertEqual(num_warns,0) 634 payment = self. importer.getEntry(dict(reg_number='1',634 payment = self.processor.getEntry(dict(reg_number='1', 635 635 p_id='p1290797973744'), self.app) 636 636 self.assertEqual(payment.p_id, 'p1290797973744') … … 642 642 suite = unittest.TestSuite() 643 643 for testcase in [ 644 Student ImporterTest,StudentStudyCourseImporterTest,645 StudentStudyLevel ImporterTest,CourseTicketImporterTest,646 Payment ImporterTest,]:644 StudentProcessorTest,StudentStudyCourseProcessorTest, 645 StudentStudyLevelProcessorTest,CourseTicketProcessorTest, 646 PaymentProcessorTest,]: 647 647 suite.addTest(unittest.TestLoader().loadTestsFromTestCase( 648 648 testcase -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
r7887 r7933 743 743 importerselect = self.browser.getControl(name='importer') 744 744 modeselect = self.browser.getControl(name='mode') 745 importerselect.getControl('Student Importer').selected = True745 importerselect.getControl('Student Processor').selected = True 746 746 modeselect.getControl(value='create').selected = True 747 747 self.browser.getControl('Proceed to step 3').click() … … 770 770 modeselect = self.browser.getControl(name='mode') 771 771 importerselect.getControl( 772 'StudentStudyCourse Importer (update only)').selected = True772 'StudentStudyCourse Processor (update only)').selected = True 773 773 modeselect.getControl(value='create').selected = True 774 774 self.browser.getControl('Proceed to step 3').click()
Note: See TracChangeset for help on using the changeset viewer.