Ignore:
Timestamp:
2 Oct 2012, 06:43:52 (12 years ago)
Author:
Henrik Bettermann
Message:

Repair and optimize AccessCodeProcessor?. AC states and transitions can now be imported in create and update mode.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests/sample_ac_data.csv

    r9265 r9266  
    1 batch_num,batch_prefix,batch_serial,cost,history,owner,random_num,representation,state
    2 1,CLR,33,100.0,2012-07-11 14:51:56 UTC - initialized by Manager||2012-07-11 14:55:42 UTC - invalidated by Manager,K1000009,1625368961#,CLR-1-1625368961,used
    3 1,CLR,2,100.0,2012-05-12 16:32:29 UTC - initialized by Manager,,5468453598#,CLR-1-5468453598,initialized
    4 1,HOS,731,0.0,2012-09-19 08:59:28 UTC - initialized by Manager,,0007044547#,HOS-1-0007044547,initialized
     1batch_num,batch_prefix,batch_serial,cost,history,owner,random_num,representation,state,transition
     21,CLR,33,100.0,anything,K1000009,1625368961#,CLR-1-1625368961,used,
     31,CLR,2,100.0,anything,,5468453598#,CLR-1-5468453598,initialized,
     41,HOS,456,0.0,anything,,98769876#,HOS-1-98769876,,use
     51,HOS,456,0.0,anything,,76254765#,HOS-1-76254765,,
     61,HOS,23,0.0,anything,,0007044547#,HOS-1-0007044547,nonsense,
     71,HOS,731,0.0,anything,,555#,HOS-1-555,used,disable_unused
     81,HOS,456,0.0,anything,,666#,HOS-1-666,,nonsense
     9
  • main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests/test_batching.py

    r9265 r9266  
    5454    '\n')[0].split(',')
    5555
     56AC_SAMPLE_DATA_UPDATE = open(
     57    os.path.join(os.path.dirname(__file__), 'sample_ac_data_update.csv'),
     58    'rb').read()
     59
     60AC_HEADER_FIELDS_UPDATE = AC_SAMPLE_DATA_UPDATE.split(
     61    '\n')[0].split(',')
     62
    5663class ACFullSetup(FunctionalTestCase):
    5764
     
    104111        self.assertTrue(
    105112            'system - AccessCodeBatch Processor - CLR-1 - '
    106             'Batch updated: num=1, creator=system, entry_num=3, '
    107             'creation_date=2012-04-28 07:28:48.719026+00:00, '
     113            'Batch updated: num=1, creator=system, used_num=1, '
     114            'entry_num=3, creation_date=2012-04-28 07:28:48.719026+00:00, '
    108115            'prefix=CLR, cost=0.0, disabled_num=0'
    109116            in logcontent)
     
    115122    layer = FunctionalLayer
    116123
    117     def test_import(self):
     124    def test_import_create(self):
    118125        self.processor = AccessCodeBatchProcessor()
    119126        self.csv_file = os.path.join(self.workdir, 'sample_batch_data.csv')
     
    126133        num, num_warns, fin_file, fail_file =  self.processor.doImport(
    127134            self.csv_file, AC_HEADER_FIELDS)
    128         self.assertEqual(num_warns,0)
     135        self.assertEqual(num_warns,3)
     136        fail_file = open(fail_file).read()
     137        self.assertTrue(
     138            'HOS-1-0007044547,HOS,anything,state: not allowed' in fail_file)
     139        self.assertTrue(
     140            'HOS-1-555,HOS,anything,workflow: not allowed' in fail_file)
     141        self.assertTrue(
     142            'HOS-1-666,HOS,anything,transition: not allowed' in fail_file)
     143        self.assertEqual(
     144            self.app['accesscodes']['HOS-1']['HOS-1-98769876'].state, 'used')
     145        self.assertEqual(
     146            self.app['accesscodes']['HOS-1']['HOS-1-76254765'].state, 'initialized')
    129147        self.assertEqual(
    130148            self.app['accesscodes']['CLR-1']['CLR-1-1625368961'].batch_serial, 33)
     
    133151        self.assertEqual(
    134152            self.app['accesscodes']['CLR-1']['CLR-1-1625368961'].state, 'used')
     153        self.assertMatches(
     154            self.app['accesscodes']['CLR-1']['CLR-1-1625368961'].history,
     155            "<YYYY-MM-DD hh:mm:ss> UTC - initialized by system|"
     156            "|<YYYY-MM-DD hh:mm:ss> UTC - state 'used' set by system")
     157        self.assertMatches(
     158            self.app['accesscodes']['HOS-1']['HOS-1-98769876'].history,
     159            "<YYYY-MM-DD hh:mm:ss> UTC - initialized by system|"
     160            "|<YYYY-MM-DD hh:mm:ss> UTC - used by system")
    135161        logcontent = open(self.logfile).read()
    136162        self.assertTrue(
    137163            'INFO - system - AccessCode Processor - CLR-1-1625368961 - '
    138             'AC updated: state=used, history=2012-07-11 14:51:56 UTC - '
    139             'initialized by Manager||2012-07-11 14:55:42 UTC - '
    140             'invalidated by Manager, batch_serial=33, '
    141             'random_num=1625368961, cost=100.0, owner=K1000009'
     164            'AC updated: state=used, batch_serial=33, random_num=1625368961, '
     165            'cost=100.0, owner=K1000009'
    142166            in logcontent)
    143167        shutil.rmtree(os.path.dirname(fin_file))
    144168        return
     169
     170    def test_import_update(self):
     171        self.processor = AccessCodeBatchProcessor()
     172        self.csv_file = os.path.join(self.workdir, 'sample_batch_data.csv')
     173        open(self.csv_file, 'wb').write(BATCH_SAMPLE_DATA)
     174        self.processor.doImport(self.csv_file, BATCH_HEADER_FIELDS)
     175
     176        self.processor = AccessCodeProcessor()
     177        self.csv_file = os.path.join(self.workdir, 'sample_ac_data.csv')
     178        open(self.csv_file, 'wb').write(AC_SAMPLE_DATA)
     179        num, num_warns, fin_file, fail_file =  self.processor.doImport(
     180            self.csv_file, AC_HEADER_FIELDS)
     181
     182        self.csv_file = os.path.join(self.workdir, 'sample_ac_data_update.csv')
     183        open(self.csv_file, 'wb').write(AC_SAMPLE_DATA_UPDATE)
     184        num, num_warns, fin_file, fail_file =  self.processor.doImport(
     185            self.csv_file, AC_HEADER_FIELDS_UPDATE, 'update')
     186        fin_file = open(fin_file).read()
     187        self.assertEqual(num_warns,0)
     188        self.assertEqual(
     189            self.app['accesscodes']['HOS-1']['HOS-1-98769876'].state, 'disabled')
     190        self.assertEqual(
     191            self.app['accesscodes']['CLR-1']['CLR-1-1625368961'].state, 'disabled')
     192        self.assertMatches(
     193            self.app['accesscodes']['CLR-1']['CLR-1-1625368961'].history,
     194            "<YYYY-MM-DD hh:mm:ss> UTC - initialized by system|"
     195            "|<YYYY-MM-DD hh:mm:ss> UTC - state 'used' set by system|"
     196            "|<YYYY-MM-DD hh:mm:ss> UTC - state 'disabled' set by system")
     197        self.assertMatches(
     198            self.app['accesscodes']['HOS-1']['HOS-1-98769876'].history,
     199            "<YYYY-MM-DD hh:mm:ss> UTC - initialized by system|"
     200            "|<YYYY-MM-DD hh:mm:ss> UTC - used by system|"
     201            "|<YYYY-MM-DD hh:mm:ss> UTC - disabled by system")
     202        return
Note: See TracChangeset for help on using the changeset viewer.