Changeset 17772
- Timestamp:
- 13 May 2024, 08:31:58 (8 months ago)
- Location:
- main/waeup.kofa/trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/CHANGES.txt
r17765 r17772 4 4 1.8.2.dev0 (unreleased) 5 5 ======================= 6 7 * Add `ApplicantRefereeReportProcessor`. 6 8 7 9 * Add `RefereeEntryConverter`. -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/batching.py
r17762 r17772 37 37 from waeup.kofa.applicants.interfaces import ( 38 38 IApplicantsContainer, IApplicant, IApplicantUpdateByRegNo, 39 IApplicantOnlinePayment )39 IApplicantOnlinePayment, IApplicantRefereeReport) 40 40 from waeup.kofa.applicants.workflow import IMPORTABLE_STATES, CREATED 41 41 … … 508 508 return errs, inv_errs, conv_dict 509 509 return errs, inv_errs, conv_dict 510 511 class ApplicantRefereeReportProcessor(BatchProcessor): 512 """The Applicant Referee Report Processor imports applicant referee reports. 513 The reports are located in the applicant container. 514 """ 515 grok.implements(IBatchProcessor) 516 grok.provides(IBatchProcessor) 517 grok.context(Interface) 518 util_name = 'applicantrefereereportprocessor' 519 grok.name(util_name) 520 521 name = _('ApplicantRefereeReport Processor') 522 iface = IApplicantRefereeReport 523 factory_name = 'waeup.ApplicantRefereeReport' 524 525 location_fields = ['applicant_id',] 526 527 def parentsExist(self, row, site): 528 return self.getParent(row, site) is not None 529 530 def getParent(self, row, site): 531 applicant_id = row['applicant_id'] 532 cat = queryUtility(ICatalog, name='applicants_catalog') 533 results = list( 534 cat.searchResults(applicant_id=(applicant_id, applicant_id))) 535 if results: 536 return results[0] 537 return None 538 539 def getEntry(self, row, site): 540 parent = self.getParent(row, site) 541 if parent is None: 542 return None 543 return parent.get(row['r_id']) 544 545 def entryExists(self, row, site): 546 return self.getEntry(row, site) is not None 547 548 def updateEntry(self, obj, row, site, filename): 549 """Update obj to the values given in row. 550 """ 551 items_changed = super(ApplicantRefereeReportProcessor, self).updateEntry( 552 obj, row, site, filename) 553 applicant = self.getParent(row, site) 554 applicant.__parent__.__parent__.logger.info( 555 '%s - %s - %s - updated: %s' 556 % (self.name, filename, applicant.applicant_id, items_changed)) 557 return 558 559 def addEntry(self, obj, row, site): 560 parent = self.getParent(row, site) 561 parent[row['r_id']] = obj 562 return 563 564 def delEntry(self, row, site): 565 report = self.getEntry(row, site) 566 parent = self.getParent(row, site) 567 if report is not None: 568 parent.__parent__.__parent__.logger.info( 569 '%s - Referee Report removed' % report.r_id) 570 del parent[report.r_id] 571 return -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_batching.py
r15553 r17772 35 35 from waeup.kofa.applicants.batching import ( 36 36 ApplicantsContainerProcessor, ApplicantProcessor, 37 ApplicantOnlinePaymentProcessor) 37 ApplicantOnlinePaymentProcessor, 38 ApplicantRefereeReportProcessor) 38 39 from waeup.kofa.applicants.container import ApplicantsContainer 39 40 from waeup.kofa.applicants.applicant import Applicant … … 85 86 86 87 PAYMENT_HEADER_FIELDS = PAYMENT_SAMPLE_DATA.split( 88 '\n')[0].split(',') 89 90 91 REPORT_SAMPLE_DATA = open( 92 os.path.join(os.path.dirname(__file__), 'sample_report_data.csv'), 93 'rb').read() 94 95 REPORT_HEADER_FIELDS = REPORT_SAMPLE_DATA.split( 87 96 '\n')[0].split(',') 88 97 … … 582 591 'amount_auth=10500.1, p_session=2016, p_state=failed' 583 592 % p_id_failed in logcontent) 593 594 class RefereeReportProcessorTest(ApplicantImportExportSetup): 595 596 def setUp(self): 597 super(RefereeReportProcessorTest, self).setUp() 598 599 applicant = Applicant() 600 applicant.firstname = u'Anna2' 601 applicant.lastname = u'Tester' 602 applicant.applicant_id = u'dp2011_1234' 603 self.app['applicants']['dp2011'].addApplicant(applicant) 604 report = createObject(u'waeup.ApplicantRefereeReport') 605 report.r_id = 'r120' 606 report.p_session = 2012 607 report.p_category = 'application' 608 report.p_state = 'paid' 609 applicant['r120'] = report 610 self.applicant2 = applicant 611 self.processor = ApplicantRefereeReportProcessor() 612 self.csv_file = os.path.join( 613 self.workdir, 'sample_report_data.csv') 614 open(self.csv_file, 'wb').write(REPORT_SAMPLE_DATA) 615 616 def test_interface(self): 617 # Make sure we fulfill the interface contracts. 618 assert verifyObject(IBatchProcessor, self.processor) is True 619 assert verifyClass( 620 IBatchProcessor, ApplicantRefereeReportProcessor) is True 621 622 def test_getEntry(self): 623 assert self.processor.getEntry( 624 dict(applicant_id='ID_NONE', r_id='nonsense'), self.app) is None 625 assert self.processor.getEntry( 626 dict(applicant_id=self.applicant2.applicant_id, r_id='r120'), 627 self.app) is self.applicant2['r120'] 628 629 def test_delEntry(self): 630 assert self.processor.getEntry( 631 dict(applicant_id=self.applicant2.applicant_id, r_id='r120'), 632 self.app) is self.applicant2['r120'] 633 self.assertEqual(len(self.applicant2.keys()),1) 634 self.processor.delEntry( 635 dict(applicant_id=self.applicant2.applicant_id, r_id='r120'), 636 self.app) 637 assert self.processor.getEntry( 638 dict(applicant_id=self.applicant2.applicant_id, r_id='r120'), 639 self.app) is None 640 self.assertEqual(len(self.applicant.keys()),0) 641 642 def test_addEntry(self): 643 self.assertEqual(len(self.applicant2.keys()),1) 644 self.processor.delEntry( 645 dict(applicant_id=self.applicant2.applicant_id, r_id='r120'), 646 self.app) 647 self.assertEqual(len(self.applicant2.keys()),0) 648 report1 = createObject(u'waeup.ApplicantRefereeReport') 649 report1.r_id = 'r234' 650 self.processor.addEntry( 651 report1, dict(applicant_id=self.applicant2.applicant_id, r_id='r234'), 652 self.app) 653 self.assertEqual(len(self.applicant2.keys()),1) 654 self.assertEqual(self.applicant2['r234'].r_id, 'r234') 655 656 def test_import(self): 657 num, num_warns, fin_file, fail_file = self.processor.doImport( 658 self.csv_file, REPORT_HEADER_FIELDS,'create') 659 #fail_contents = open(fail_file, 'rb').read() 660 self.assertEqual(num_warns,0) 661 report = self.processor.getEntry(dict(applicant_id='dp2011_1234', 662 r_id='r122'), self.app) 663 self.assertEqual(report.r_id, 'r122') 664 cdate = report.creation_date.strftime("%Y-%m-%d %H:%M:%S") 665 self.assertEqual(cdate, '2024-05-12 08:34:46') 666 self.assertEqual(str(report.creation_date.tzinfo),'UTC') 667 # ... the other one with generated p_id. 668 shutil.rmtree(os.path.dirname(fin_file)) 669 logcontent = open(self.logfile).read() 670 # Logging message from updateEntry 671 self.assertTrue( 672 'INFO - system - ApplicantRefereeReport Processor - ' 673 'sample_report_data - dp2011_1234 - updated: name=John Doe, ' 674 'email_pref=aa@aa.aa, creation_date=2024-05-12 08:34:46.515874+00:00, ' 675 'phone=--1234, r_id=r122, report=Very nice student., ' 676 'email=xx@xx.xx' in logcontent) -
main/waeup.kofa/trunk/src/waeup/kofa/doctests/batchprocessing_browser.txt
r17755 r17772 100 100 'ApplicantOnlinePayment Processor', 101 101 'Applicant Processor', 102 'ApplicantRefereeReport Processor', 102 103 'ApplicantsContainer Processor', 103 104 'Bed Processor (update only)',
Note: See TracChangeset for help on using the changeset viewer.