Index: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py	(revision 8340)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py	(revision 8341)
@@ -1,13 +1,10 @@
-import datetime
-import os
-from zope.catalog.interfaces import ICatalog
-from zope.component import queryUtility, getUtility
+from zope.component import queryUtility
 from zope.interface.verify import verifyObject, verifyClass
-from zope.intid.interfaces import IIntIds
 from waeup.kofa.interfaces import ICSVExporter
 from waeup.kofa.students.export import (
-    StudentsExporter, StudentStudyCourseExporter, StudentStudyLevelExporter,)
-from waeup.kofa.students.student import Student, StudentStudyCourse
-from waeup.kofa.students.studylevel import StudentStudyLevel
+    StudentsExporter, StudentStudyCourseExporter, StudentStudyLevelExporter,
+    CourseTicketExporter)
+from waeup.kofa.students.student import StudentStudyCourse
+from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket
 from waeup.kofa.students.tests.test_batching import StudentImportExportSetup
 from waeup.kofa.testing import FunctionalLayer
@@ -19,10 +16,5 @@
     def setUp(self):
         super(StudentsExporterTest, self).setUp()
-        student = Student()
-        student.student_id = u'A111111'
-        self.app['students'][student.student_id] = self.student = student
-        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
-        self.cat = getUtility(ICatalog, name='students_catalog')
-        self.intids = getUtility(IIntIds)
+        self.setup_for_export()
         return
 
@@ -39,24 +31,4 @@
         self.assertTrue(result is not None)
         return
-
-    def setup_student(self, student):
-        # set predictable values for `student`
-        student.matric_number = u'M123456'
-        student.adm_code = u'my adm code'
-        student.clearance_locked = False
-        student.clr_code = u'my clr code'
-        student.perm_address = u'Studentroad 21\nLagos 123456\n'
-        student.reg_number = u'123456'
-        student.student_id = u'A111111'
-        student.firstname = u'Anna'
-        student.lastname = u'Tester'
-        student.middlename = u'M.'
-        student.date_of_birth = datetime.date(1981, 2, 4)
-        student.sex = 'f'
-        student.email = 'anna@sample.com'
-        student.phone = u'+234-123-12345'
-        student.notice = u'Some notice\nin lines.'
-        student.nationality = u'NG'
-        return student
 
     def test_export(self):
@@ -104,11 +76,5 @@
     def setUp(self):
         super(StudentStudyCourseExporterTest, self).setUp()
-        student = Student()
-        student.student_id = u'A111111'
-        self.app['students'][student.student_id] = self.student = student
-        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
-        self.cat = getUtility(ICatalog, name='students_catalog')
-        self.intids = getUtility(IIntIds)
-        #self.study_course = StudyCourse()
+        self.setup_for_export()
         return
 
@@ -125,30 +91,4 @@
         self.assertTrue(result is not None)
         return
-
-    def setup_student(self, student):
-        # set predictable values for `student`
-        student.matric_number = u'M123456'
-        student.adm_code = u'my adm code'
-        student.clearance_locked = False
-        student.clr_code = u'my clr code'
-        student.perm_address = u'Studentroad 21\nLagos 123456\n'
-        student.reg_number = u'123456'
-        student.student_id = u'A111111'
-        student.firstname = u'Anna'
-        student.lastname = u'Tester'
-        student.middlename = u'M.'
-        student.date_of_birth = datetime.date(1981, 2, 4)
-        student.sex = 'f'
-        student.email = 'anna@sample.com'
-        student.phone = u'+234-123-12345'
-        student.notice = u'Some notice\nin lines.'
-
-        study_course = student.get('studycourse')
-        student['studycourse'].certificate = self.certificate
-        student['studycourse'].entry_mode = 'ug_ft'
-        student['studycourse'].entry_session = 2010
-        student['studycourse'].current_session = 2012
-        student['studycourse'].current_level = int(self.certificate.start_level)
-        return student
 
     def test_export_empty(self):
@@ -206,11 +146,5 @@
     def setUp(self):
         super(StudentStudyLevelExporterTest, self).setUp()
-        student = Student()
-        student.student_id = u'A111111'
-        self.app['students'][student.student_id] = self.student = student
-        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
-        self.cat = getUtility(ICatalog, name='students_catalog')
-        self.intids = getUtility(IIntIds)
-        #self.study_level = StudyLevel()
+        self.setup_for_export()
         return
 
@@ -227,37 +161,4 @@
         self.assertTrue(result is not None)
         return
-
-    def setup_student(self, student):
-        # set predictable values for `student`
-        student.matric_number = u'M123456'
-        student.adm_code = u'my adm code'
-        student.clearance_locked = False
-        student.clr_code = u'my clr code'
-        student.perm_address = u'Studentroad 21\nLagos 123456\n'
-        student.reg_number = u'123456'
-        student.student_id = u'A111111'
-        student.firstname = u'Anna'
-        student.lastname = u'Tester'
-        student.middlename = u'M.'
-        student.date_of_birth = datetime.date(1981, 2, 4)
-        student.sex = 'f'
-        student.email = 'anna@sample.com'
-        student.phone = u'+234-123-12345'
-        student.notice = u'Some notice\nin lines.'
-
-        study_course = student.get('studycourse')
-        student['studycourse'].certificate = self.certificate
-        student['studycourse'].entry_mode = 'ug_ft'
-        student['studycourse'].entry_session = 2010
-        student['studycourse'].current_session = 2012
-        student['studycourse'].current_level = int(self.certificate.start_level)
-
-        study_level = StudentStudyLevel()
-        study_level.level_session = 2012
-        study_level.level_verdict = "A"
-        study_level.level = 100
-        student['studycourse'].addStudentStudyLevel(
-            self.certificate, study_level)
-        return student
 
     def test_export_empty(self):
@@ -303,2 +204,71 @@
             )
         return
+
+class CourseTicketExporterTest(StudentImportExportSetup):
+
+    layer = FunctionalLayer
+
+    def setUp(self):
+        super(CourseTicketExporterTest, self).setUp()
+        self.setup_for_export()
+        return
+
+    def test_ifaces(self):
+        # make sure we fullfill interface contracts
+        obj = CourseTicketExporter()
+        verifyObject(ICSVExporter, obj)
+        verifyClass(ICSVExporter, CourseTicketExporter)
+        return
+
+    def test_get_as_utility(self):
+        # we can get an student exporter as utility
+        result = queryUtility(ICSVExporter, name="coursetickets")
+        self.assertTrue(result is not None)
+        return
+
+    def test_export_empty(self):
+        # we can export a nearly empty course ticket
+        ticket = CourseTicket()
+        exporter = CourseTicketExporter()
+        exporter.export([ticket], self.outfile)
+        result = open(self.outfile, 'rb').read()
+        self.assertEqual(
+            result,
+            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
+            'matric_number,passmark,reg_number,score,semester,title\r\n'
+            '0,0,,,,,,0,,,,0,,\r\n'
+            )
+        return
+
+    def test_export(self):
+        # we can really export course tickets.
+        # set values we can expect in export file
+        self.setup_student(self.student)
+        study_course = self.student.get('studycourse')
+        study_level = study_course[study_course.keys()[0]]
+        ticket = study_level['CRS1']
+        exporter = CourseTicketExporter()
+        exporter.export([ticket], self.outfile)
+        result = open(self.outfile, 'rb').read()
+        self.assertEqual(
+            result,
+            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
+            'matric_number,passmark,reg_number,score,semester,title\r\n'
+            '1,1,CRS1,100,DEP1,FAC1,100,0,M123456,100,123456,0,2,Course 1\r\n'
+            )
+        return
+
+    def test_export_all(self):
+        # we can really export all course tickets
+        # set values we can expect in export file
+        self.setup_student(self.student)
+        exporter = CourseTicketExporter()
+        exporter.export_all(self.app, self.outfile)
+        result = open(self.outfile, 'rb').read()
+        self.assertEqual(
+            result,
+            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
+            'matric_number,passmark,reg_number,score,semester,title\r\n'
+            '1,1,CRS1,100,DEP1,FAC1,100,0,M123456,100,123456,0,2,Course 1\r\n'
+            )
+        return
