Ignore:
Timestamp:
13 May 2024, 08:31:58 (6 months ago)
Author:
Henrik Bettermann
Message:

Add ApplicantRefereeReportProcessor.

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

    r15553 r17772  
    3535from waeup.kofa.applicants.batching import (
    3636    ApplicantsContainerProcessor, ApplicantProcessor,
    37     ApplicantOnlinePaymentProcessor)
     37    ApplicantOnlinePaymentProcessor,
     38    ApplicantRefereeReportProcessor)
    3839from waeup.kofa.applicants.container import ApplicantsContainer
    3940from waeup.kofa.applicants.applicant import Applicant
     
    8586
    8687PAYMENT_HEADER_FIELDS = PAYMENT_SAMPLE_DATA.split(
     88    '\n')[0].split(',')
     89
     90
     91REPORT_SAMPLE_DATA = open(
     92    os.path.join(os.path.dirname(__file__), 'sample_report_data.csv'),
     93    'rb').read()
     94
     95REPORT_HEADER_FIELDS = REPORT_SAMPLE_DATA.split(
    8796    '\n')[0].split(',')
    8897
     
    582591            'amount_auth=10500.1, p_session=2016, p_state=failed'
    583592            % p_id_failed in logcontent)
     593
     594class 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)
Note: See TracChangeset for help on using the changeset viewer.