Ignore:
Timestamp:
2 Apr 2012, 09:58:35 (13 years ago)
Author:
uli
Message:

Exporters for study levels.

File:
1 edited

Legend:

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

    r7994 r8015  
    77from waeup.kofa.interfaces import ICSVExporter
    88from waeup.kofa.students.export import (
    9     StudentsExporter, StudentStudyCourseExporter)
     9    StudentsExporter, StudentStudyCourseExporter, StudentStudyLevelExporter,)
    1010from waeup.kofa.students.student import Student, StudentStudyCourse
     11from waeup.kofa.students.studylevel import StudentStudyLevel
    1112from waeup.kofa.students.tests.test_batching import StudentImportExportSetup
    1213from waeup.kofa.testing import FunctionalLayer
     
    197198            )
    198199        return
     200
     201class StudentStudyLevelExporterTest(StudentImportExportSetup):
     202
     203    layer = FunctionalLayer
     204
     205    def setUp(self):
     206        super(StudentStudyLevelExporterTest, self).setUp()
     207        student = Student()
     208        student.student_id = u'A111111'
     209        self.app['students'][student.student_id] = self.student = student
     210        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
     211        self.cat = getUtility(ICatalog, name='students_catalog')
     212        self.intids = getUtility(IIntIds)
     213        #self.study_level = StudyLevel()
     214        return
     215
     216    def test_ifaces(self):
     217        # make sure we fullfill interface contracts
     218        obj = StudentStudyLevelExporter()
     219        verifyObject(ICSVExporter, obj)
     220        verifyClass(ICSVExporter, StudentStudyLevelExporter)
     221        return
     222
     223    def test_get_as_utility(self):
     224        # we can get an student exporter as utility
     225        result = queryUtility(ICSVExporter, name="studentstudylevels")
     226        self.assertTrue(result is not None)
     227        return
     228
     229    def setup_student(self, student):
     230        # set predictable values for `student`
     231        student.matric_number = u'M123456'
     232        student.adm_code = u'my adm code'
     233        student.clearance_locked = False
     234        student.clr_code = u'my clr code'
     235        student.perm_address = u'Studentroad 21\nLagos 123456\n'
     236        student.reg_number = u'123456'
     237        student.student_id = u'A111111'
     238        student.firstname = u'Anna'
     239        student.lastname = u'Tester'
     240        student.middlename = u'M.'
     241        student.date_of_birth = datetime.date(1981, 2, 4)
     242        student.sex = 'f'
     243        student.email = 'anna@sample.com'
     244        student.phone = u'+234-123-12345'
     245        student.notice = u'Some notice\nin lines.'
     246
     247        study_course = student.get('studycourse')
     248        student['studycourse'].certificate = self.certificate
     249        student['studycourse'].entry_mode = 'ug_ft'
     250        student['studycourse'].entry_session = 2010
     251        student['studycourse'].current_session = 2012
     252        student['studycourse'].current_level = int(self.certificate.start_level)
     253
     254        study_level = StudentStudyLevel()
     255        study_level.level_session = 2012
     256        study_level.level_verdict = "A"
     257        study_level.level = 100
     258        student['studycourse'].addStudentStudyLevel(
     259            self.certificate, study_level)
     260        return student
     261
     262    def test_export_empty(self):
     263        # we can export a nearly empty study level
     264        study_level = StudentStudyLevel()
     265        exporter = StudentStudyLevelExporter()
     266        exporter.export([study_level], self.outfile)
     267        result = open(self.outfile, 'rb').read()
     268        self.assertEqual(
     269            result,
     270            'level,level_session,level_verdict,matric_number,reg_number\r\n'
     271            ',,0,,\r\n'
     272            )
     273        return
     274
     275    def test_export(self):
     276        # we can really export study levels.
     277        # set values we can expect in export file
     278        self.setup_student(self.student)
     279        study_course = self.student.get('studycourse')
     280        study_level = study_course[study_course.keys()[0]]
     281        exporter = StudentStudyLevelExporter()
     282        exporter.export([study_level], self.outfile)
     283        result = open(self.outfile, 'rb').read()
     284        self.assertEqual(
     285            result,
     286            'level,level_session,level_verdict,matric_number,reg_number\r\n'
     287            '100,2012,A,M123456,123456\r\n'
     288            )
     289        return
     290
     291    def test_export_all(self):
     292        # we can really export study levels
     293        # set values we can expect in export file
     294        self.setup_student(self.student)
     295        exporter = StudentStudyLevelExporter()
     296        exporter.export_all(self.app, self.outfile)
     297        result = open(self.outfile, 'rb').read()
     298        print [x for x in self.student['studycourse'].keys()]
     299        self.assertEqual(
     300            result,
     301            'level,level_session,level_verdict,matric_number,reg_number\r\n'
     302            '100,2012,A,M123456,123456\r\n'
     303            )
     304        return
Note: See TracChangeset for help on using the changeset viewer.