Changeset 7508 for main


Ignore:
Timestamp:
25 Jan 2012, 12:42:24 (13 years ago)
Author:
uli
Message:

Add test that shows when 01/02/2012 is interpreted erraneous as
January, 2nd.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_batching.py

    r7266 r7508  
    5050    os.path.join(os.path.dirname(__file__), 'sample_applicant_data.csv'),
    5151    'rb').read()
     52FAULTY_APPLICANT_SAMPLE_DATA = open(
     53    os.path.join(os.path.dirname(__file__),
     54                 'sample_faulty_applicant_data.csv'), 'rb').read()
     55
    5256
    5357APPLICANT_HEADER_FIELDS = APPLICANT_SAMPLE_DATA.split(
     
    5559
    5660APPLICANT_SAMPLE_DATA_UPDATE = open(
    57     os.path.join(os.path.dirname(__file__), 'sample_applicant_data_update.csv'),
    58     'rb').read()
     61    os.path.join(os.path.dirname(__file__),
     62                 'sample_applicant_data_update.csv'), 'rb').read()
    5963
    6064APPLICANT_HEADER_FIELDS_UPDATE = APPLICANT_SAMPLE_DATA_UPDATE.split(
     
    187191        self.workdir = tempfile.mkdtemp()
    188192        self.csv_file = os.path.join(self.workdir, 'sample_applicant_data.csv')
     193        self.csv_file_faulty = os.path.join(self.workdir,
     194                                            'faulty_applicant_data.csv')
    189195        self.csv_file_update = os.path.join(
    190196            self.workdir, 'sample_applicant_data_update.csv')
    191197        open(self.csv_file, 'wb').write(APPLICANT_SAMPLE_DATA)
     198        open(self.csv_file_faulty, 'wb').write(FAULTY_APPLICANT_SAMPLE_DATA)
    192199        open(self.csv_file_update, 'wb').write(APPLICANT_SAMPLE_DATA_UPDATE)
    193200
     
    238245        shutil.rmtree(os.path.dirname(fin_file))
    239246
     247    def test_import_faulty(self):
     248        # we cannot import data with faulty dates. A date is faulty
     249        # when in format xx/yy/zzzz as we cannot say whether it is
     250        # meant as dd/mm/yyyy or mm/dd/yyyy. We therefore require yyyy-mm-dd
     251        num, num_warns, fin_file, fail_file = self.importer.doImport(
     252            self.csv_file_faulty, APPLICANT_HEADER_FIELDS)
     253        if fail_file is not None:
     254            fail_contents = open(fail_file, 'rb').read()
     255            shutil.rmtree(os.path.dirname(fail_file))
     256        else:
     257            shutil.rmtree(os.path.dirname(fin_file))
     258        self.assertEqual(num_warns,1)
     259        self.assertTrue(
     260            'date_of_birth: Invalid datetime data' in fail_contents)
     261        self.assertEqual(len(self.app['applicants']['dp2011'].keys()), 1)
     262        return
     263
    240264    def test_import_update(self):
    241265        num, num_warns, fin_file, fail_file = self.importer.doImport(
Note: See TracChangeset for help on using the changeset viewer.