Changeset 12996 for main


Ignore:
Timestamp:
23 May 2015, 06:54:24 (9 years ago)
Author:
Henrik Bettermann
Message:

Be more careful when checking conversion. Take ignore marker into consideration.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/batching.py

    r12883 r12996  
    781781            return None
    782782        p_id = row.get('p_id', None)
    783         if p_id is None:
     783        if p_id in (None, IGNORE_MARKER):
    784784            return None
    785785        # We can use the hash symbol at the end of p_id in import files
     
    846846        # We have to check p_id.
    847847        p_id = row.get('p_id', None)
    848         if not p_id:
     848        if mode == 'create' and p_id in (None, IGNORE_MARKER):
    849849            timestamp = ("%d" % int(time()*10000))[1:]
    850850            p_id = "p%s" % timestamp
    851851            conv_dict['p_id'] = p_id
    852852            return errs, inv_errs, conv_dict
     853        elif p_id in (None, IGNORE_MARKER):
     854            errs.append(('p_id','missing'))
     855            return errs, inv_errs, conv_dict
    853856        else:
    854857            p_id = p_id.strip('#')
    855         if p_id.startswith('p'):
    856             if not len(p_id) == 14:
    857                 errs.append(('p_id','invalid length'))
    858                 return errs, inv_errs, conv_dict
    859         elif len(p_id.split('-')) == 3:
    860             # The SRP used either pins as keys ...
    861             if len(p_id.split('-')[2]) not in (9, 10):
    862                 errs.append(('p_id','invalid pin'))
    863                 return errs, inv_errs, conv_dict
    864         else:
    865             # ... or order_ids.
    866             if not len(p_id) == 19:
    867                 errs.append(('p_id','invalid format'))
    868                 return errs, inv_errs, conv_dict
     858            if p_id.startswith('p'):
     859                if not len(p_id) == 14:
     860                    errs.append(('p_id','invalid length'))
     861                    return errs, inv_errs, conv_dict
     862            elif len(p_id.split('-')) == 3:
     863                # The SRP used either pins as keys ...
     864                if len(p_id.split('-')[2]) not in (9, 10):
     865                    errs.append(('p_id','invalid pin'))
     866                    return errs, inv_errs, conv_dict
     867            else:
     868                # ... or order_ids.
     869                if not len(p_id) == 19:
     870                    errs.append(('p_id','invalid format'))
     871                    return errs, inv_errs, conv_dict
    869872        # Requirement added on 24/01/2015: p_id must be portal-wide unique.
    870873        if mode == 'create':
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/sample_payment_data.csv

    r12623 r12996  
    44,paid,schoolfee,p1266236341955,3,2009,19500,BTECHBDT,19500,0615,00,2010/02/15 13:19:01#,online,1
    55,paid,schoolfee,ABC-11-1234567890,3,2011,19500,BTECHBDT,19500.6,,SC,2010/02/15 13:19:01#,sc,1
     6,paid,schoolfee,<IGNORE>,3,2012,20500,BTECHBDT,20500,0615,00,2020/02/15 13:19:01#,online,1
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_batching.py

    r12981 r12996  
    10641064    def test_checkConversion(self):
    10651065        errs, inv_errs, conv_dict = self.processor.checkConversion(
     1066            dict(p_id='<IGNORE>'), mode='create')
     1067        self.assertEqual(len(errs),0)
     1068        errs, inv_errs, conv_dict = self.processor.checkConversion(
     1069            dict(p_id='<IGNORE>'), mode='update')
     1070        self.assertEqual(len(errs),1)
     1071        self.assertEqual(errs[0], ('p_id', u'missing'))
     1072        errs, inv_errs, conv_dict = self.processor.checkConversion(
    10661073            dict(p_id='3816951266236341955'))
    10671074        self.assertEqual(len(errs),0)
     
    10751082            dict(p_id='nonsense'))
    10761083        self.assertEqual(len(errs),1)
     1084        self.assertEqual(errs[0], ('p_id', u'invalid format'))
    10771085        timestamp = ("%d" % int(time()*10000))[1:]
    10781086        p_id = "p%s" % timestamp
     
    11421150        # We perform the same import twice,
    11431151        # the second time in update mode. The number
    1144         # of warnings must be the same.
     1152        # of warnings increases becaus one p_id is missing.
    11451153        num, num_warns, fin_file, fail_file = self.processor.doImport(
    11461154            self.csv_file, PAYMENT_HEADER_FIELDS,'create')
     
    11481156        num, num_warns, fin_file, fail_file = self.processor.doImport(
    11491157            self.csv_file, PAYMENT_HEADER_FIELDS,'update')
    1150         self.assertEqual(num_warns,0)
    1151         shutil.rmtree(os.path.dirname(fin_file))
     1158        self.assertEqual(num_warns,1)
     1159        content = open(fail_file).read()
     1160        shutil.rmtree(os.path.dirname(fin_file))
     1161        self.assertTrue('p_id: missing' in content)
    11521162
    11531163    def test_import_remove(self):
    11541164        # We perform the same import twice,
    11551165        # the second time in remove mode. The number
    1156         # of warnings must be the same.
     1166        # of warnings increases becaus one p_id is missing.
    11571167        num, num_warns, fin_file, fail_file = self.processor.doImport(
    11581168            self.csv_file, PAYMENT_HEADER_FIELDS,'create')
     
    11601170        num, num_warns, fin_file, fail_file = self.processor.doImport(
    11611171            self.csv_file, PAYMENT_HEADER_FIELDS,'remove')
    1162         self.assertEqual(num_warns,0)
     1172        self.assertEqual(num_warns,1)
     1173        content = open(fail_file).read()
     1174        self.assertTrue('p_id: missing' in content)
    11631175        shutil.rmtree(os.path.dirname(fin_file))
    11641176        logcontent = open(self.logfile).read()
     
    11671179            in logcontent)
    11681180
    1169     def test_import_wo_pid(self):
     1181    def test_import_same_payment_exists(self):
    11701182        num, num_warns, fin_file, fail_file = self.processor.doImport(
    11711183            self.csv_file2, PAYMENT_CREATE_HEADER_FIELDS,'create')
Note: See TracChangeset for help on using the changeset viewer.