Changeset 6848 for main/waeup.sirp


Ignore:
Timestamp:
3 Oct 2011, 08:05:53 (13 years ago)
Author:
Henrik Bettermann
Message:

Include student update and removal tests.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/students/tests
Files:
1 added
1 edited

Legend:

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

    r6846 r6848  
    4747    '\n')[0].split(',')
    4848
     49STUDENT_SAMPLE_DATA_UPDATE = open(
     50    os.path.join(os.path.dirname(__file__), 'sample_student_data_update.csv'),
     51    'rb').read()
     52
     53STUDENT_HEADER_FIELDS_UPDATE = STUDENT_SAMPLE_DATA_UPDATE.split(
     54    '\n')[0].split(',')
     55
     56STUDENT_SAMPLE_DATA = open(
     57    os.path.join(os.path.dirname(__file__), 'sample_student_data.csv'),
     58    'rb').read()
     59
     60STUDENT_HEADER_FIELDS = STUDENT_SAMPLE_DATA.split(
     61    '\n')[0].split(',')
     62
    4963STUDYCOURSE_SAMPLE_DATA = open(
    5064    os.path.join(os.path.dirname(__file__), 'sample_studycourse_data.csv'),
     
    8599        self.workdir = tempfile.mkdtemp()
    86100        self.csv_file = os.path.join(self.workdir, 'sample_student_data.csv')
     101        self.csv_file_update = os.path.join(self.workdir, 'sample_student_data_update.csv')
    87102        open(self.csv_file, 'wb').write(STUDENT_SAMPLE_DATA)
     103        open(self.csv_file_update, 'wb').write(STUDENT_SAMPLE_DATA_UPDATE)
    88104
    89105    def tearDown(self):
     
    106122    def test_entryExists(self):
    107123        assert self.importer.entryExists(
    108             dict(student_id='ID_NONE'), self.app) is False
    109         student = dict(student_id=self.student.student_id), self.app)
     124            dict(student_id='ID_NONE'), self.app) is None
     125        student = self.importer.getEntry(
     126            dict(student_id=self.student.student_id), self.app)
    110127        self.assertEqual(student.reg_number, u'123')
    111128
     
    130147        assert self.student.student_id not in self.app['students'].keys()
    131148
     149    def test_delEntry(self):
     150        assert self.student.student_id in self.app['students'].keys()
     151        self.importer.delEntry(dict(reg_number=self.student.reg_number), self.app)
     152        assert self.student.student_id not in self.app['students'].keys()
     153
    132154    def test_import(self):
    133155        num, num_warns, fin_file, fail_file = self.importer.doImport(
     
    135157        self.assertEqual(num_warns,0)
    136158        assert len(self.app['students'].keys()) == 4
     159        shutil.rmtree(os.path.dirname(fin_file))
     160
     161    def test_import_update(self):
     162        num, num_warns, fin_file, fail_file = self.importer.doImport(
     163            self.csv_file, STUDENT_HEADER_FIELDS)
     164        shutil.rmtree(os.path.dirname(fin_file))
     165        num, num_warns, fin_file, fail_file = self.importer.doImport(
     166            self.csv_file_update, STUDENT_HEADER_FIELDS_UPDATE, 'update')
     167        self.assertEqual(num_warns,0)
     168        shutil.rmtree(os.path.dirname(fin_file))
     169
     170    def test_import_remove(self):
     171        num, num_warns, fin_file, fail_file = self.importer.doImport(
     172            self.csv_file, STUDENT_HEADER_FIELDS)
     173        shutil.rmtree(os.path.dirname(fin_file))
     174        num, num_warns, fin_file, fail_file = self.importer.doImport(
     175            self.csv_file_update, STUDENT_HEADER_FIELDS_UPDATE, 'remove')
     176        self.assertEqual(num_warns,0)
    137177        shutil.rmtree(os.path.dirname(fin_file))
    138178
     
    190230    def test_entryExists(self):
    191231        assert self.importer.entryExists(
    192             dict(reg_number='REG_NONE'), self.app) is False
     232            dict(reg_number='REG_NONE'), self.app) is None
    193233        student = self.importer.entryExists(dict(reg_number='1'), self.app)
    194234        self.assertEqual(student.reg_number, u'1')
Note: See TracChangeset for help on using the changeset viewer.