Changeset 13872 for main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests
- Timestamp:
- 4 Jun 2016, 04:08:45 (9 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_batching.py
r13073 r13872 33 33 from waeup.kofa.app import University 34 34 from waeup.kofa.applicants.batching import ( 35 ApplicantsContainerProcessor, ApplicantProcessor) 35 ApplicantsContainerProcessor, ApplicantProcessor, 36 ApplicantOnlinePaymentProcessor) 36 37 from waeup.kofa.applicants.container import ApplicantsContainer 37 38 from waeup.kofa.applicants.applicant import Applicant … … 39 40 from waeup.kofa.university.department import Department 40 41 from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase 41 from waeup.kofa.interfaces import IBatchProcessor, IUserAccount 42 from waeup.kofa.interfaces import ( 43 IBatchProcessor, IUserAccount, DuplicationError) 42 44 from waeup.kofa.applicants.workflow import CREATED 43 45 … … 75 77 76 78 APPLICANT_HEADER_FIELDS_UPDATE2 = APPLICANT_SAMPLE_DATA_UPDATE2.split( 79 '\n')[0].split(',') 80 81 PAYMENT_SAMPLE_DATA = open( 82 os.path.join(os.path.dirname(__file__), 'sample_payment_data.csv'), 83 'rb').read() 84 85 PAYMENT_HEADER_FIELDS = PAYMENT_SAMPLE_DATA.split( 77 86 '\n')[0].split(',') 78 87 … … 225 234 self.application_number] 226 235 self.workdir = tempfile.mkdtemp() 236 237 self.logfile = os.path.join( 238 self.app['datacenter'].storage, 'logs', 'applicants.log') 227 239 return 228 240 … … 252 264 open(self.csv_file_update, 'wb').write(APPLICANT_SAMPLE_DATA_UPDATE) 253 265 open(self.csv_file_update2, 'wb').write(APPLICANT_SAMPLE_DATA_UPDATE2) 254 255 self.logfile = os.path.join(256 self.app['datacenter'].storage, 'logs', 'applicants.log')257 266 258 267 def test_interface(self): … … 415 424 logcontent) 416 425 shutil.rmtree(os.path.dirname(fin_file)) 426 427 class PaymentProcessorTest(ApplicantImportExportSetup): 428 429 def setUp(self): 430 super(PaymentProcessorTest, self).setUp() 431 432 applicant = Applicant() 433 applicant.firstname = u'Anna2' 434 applicant.lastname = u'Tester' 435 applicant.applicant_id = u'dp2011_1234' 436 self.app['applicants']['dp2011'].addApplicant(applicant) 437 payment = createObject(u'waeup.ApplicantOnlinePayment') 438 payment.p_id = 'p120' 439 payment.p_session = 2012 440 payment.p_category = 'application' 441 payment.p_state = 'paid' 442 applicant['p120'] = payment 443 self.applicant2 = applicant 444 self.processor = ApplicantOnlinePaymentProcessor() 445 self.csv_file = os.path.join( 446 self.workdir, 'sample_payment_data.csv') 447 open(self.csv_file, 'wb').write(PAYMENT_SAMPLE_DATA) 448 449 def test_interface(self): 450 # Make sure we fulfill the interface contracts. 451 assert verifyObject(IBatchProcessor, self.processor) is True 452 assert verifyClass( 453 IBatchProcessor, ApplicantOnlinePaymentProcessor) is True 454 455 def test_getEntry(self): 456 assert self.processor.getEntry( 457 dict(applicant_id='ID_NONE', p_id='nonsense'), self.app) is None 458 assert self.processor.getEntry( 459 dict(applicant_id=self.applicant2.applicant_id, p_id='p120'), 460 self.app) is self.applicant2['p120'] 461 assert self.processor.getEntry( 462 dict(applicant_id=self.applicant2.applicant_id, p_id='p120#'), 463 self.app) is self.applicant2['p120'] 464 465 def test_delEntry(self): 466 assert self.processor.getEntry( 467 dict(applicant_id=self.applicant2.applicant_id, p_id='p120'), 468 self.app) is self.applicant2['p120'] 469 self.assertEqual(len(self.applicant2.keys()),1) 470 self.processor.delEntry( 471 dict(applicant_id=self.applicant2.applicant_id, p_id='p120'), 472 self.app) 473 assert self.processor.getEntry( 474 dict(applicant_id=self.applicant2.applicant_id, p_id='p120'), 475 self.app) is None 476 self.assertEqual(len(self.applicant.keys()),0) 477 478 def test_addEntry(self): 479 self.assertEqual(len(self.applicant2.keys()),1) 480 self.processor.delEntry( 481 dict(applicant_id=self.applicant2.applicant_id, p_id='p120'), 482 self.app) 483 payment1 = createObject(u'waeup.ApplicantOnlinePayment') 484 payment1.p_category = 'application' 485 payment1.p_id = 'p234' 486 self.processor.addEntry( 487 payment1, dict(applicant_id=self.applicant2.applicant_id, p_id='p234'), 488 self.app) 489 self.assertEqual(len(self.applicant2.keys()),1) 490 self.assertEqual(self.applicant2['p234'].p_id, 'p234') 491 # Same payment must not exist. 492 payment1.p_state = 'paid' 493 payment2 = createObject(u'waeup.ApplicantOnlinePayment') 494 payment2.p_id = 'p456' 495 payment2.p_category = 'application' 496 self.assertRaises( 497 DuplicationError, self.processor.addEntry, payment2, 498 dict(applicant_id=self.applicant2.applicant_id, p_id='p456'), self.app) 499 500 def test_import(self): 501 num, num_warns, fin_file, fail_file = self.processor.doImport( 502 self.csv_file, PAYMENT_HEADER_FIELDS,'create') 503 self.assertEqual(num_warns,1) 504 fail_file = open(fail_file).read() 505 self.assertTrue('Payment has already been made' in fail_file) 506 self.processor.delEntry( 507 dict(applicant_id=self.applicant2.applicant_id, p_id='p120'), 508 self.app) 509 num, num_warns, fin_file, fail_file = self.processor.doImport( 510 self.csv_file, PAYMENT_HEADER_FIELDS,'create') 511 self.assertEqual(num_warns,0) 512 payment = self.processor.getEntry(dict(applicant_id='dp2011_1234', 513 p_id='p1266236341955'), self.app) 514 self.assertEqual(payment.p_id, 'p1266236341955') 515 cdate = payment.creation_date.strftime("%Y-%m-%d %H:%M:%S") 516 # Ooooh, still the old problem, see 517 # http://mail.dzug.org/mailman/archives/zope/2006-August/001153.html. 518 # WAT is interpreted as GMT-1 and not GMT+1 519 self.assertEqual(cdate, '2010-11-25 21:16:33') 520 self.assertEqual(str(payment.creation_date.tzinfo),'UTC') 521 shutil.rmtree(os.path.dirname(fin_file)) 522 logcontent = open(self.logfile).read() 523 # Logging message from updateEntry 524 self.assertTrue( 525 'INFO - system - ApplicantOnlinePayment Processor - dp2011_1234 - ' 526 'previous update cancelled' 527 in logcontent) 528 self.assertTrue( 529 'INFO - system - ApplicantOnlinePayment Processor - ' 530 'sample_payment_data - dp2011_1234 - updated: p_id=p1266236341955, ' 531 'creation_date=2010-11-25 21:16:33.757000+00:00, ' 532 'r_amount_approved=19500.1, p_category=application, ' 533 'amount_auth=19500.1, p_session=2015, p_state=paid' 534 in logcontent)
Note: See TracChangeset for help on using the changeset viewer.