Changeset 8341
- Timestamp:
- 4 May 2012, 11:52:16 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py
r8070 r8341 1 import datetime 2 import os 3 from zope.catalog.interfaces import ICatalog 4 from zope.component import queryUtility, getUtility 1 from zope.component import queryUtility 5 2 from zope.interface.verify import verifyObject, verifyClass 6 from zope.intid.interfaces import IIntIds7 3 from waeup.kofa.interfaces import ICSVExporter 8 4 from waeup.kofa.students.export import ( 9 StudentsExporter, StudentStudyCourseExporter, StudentStudyLevelExporter,) 10 from waeup.kofa.students.student import Student, StudentStudyCourse 11 from waeup.kofa.students.studylevel import StudentStudyLevel 5 StudentsExporter, StudentStudyCourseExporter, StudentStudyLevelExporter, 6 CourseTicketExporter) 7 from waeup.kofa.students.student import StudentStudyCourse 8 from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket 12 9 from waeup.kofa.students.tests.test_batching import StudentImportExportSetup 13 10 from waeup.kofa.testing import FunctionalLayer … … 19 16 def setUp(self): 20 17 super(StudentsExporterTest, self).setUp() 21 student = Student() 22 student.student_id = u'A111111' 23 self.app['students'][student.student_id] = self.student = student 24 self.outfile = os.path.join(self.workdir, 'myoutput.csv') 25 self.cat = getUtility(ICatalog, name='students_catalog') 26 self.intids = getUtility(IIntIds) 18 self.setup_for_export() 27 19 return 28 20 … … 39 31 self.assertTrue(result is not None) 40 32 return 41 42 def setup_student(self, student):43 # set predictable values for `student`44 student.matric_number = u'M123456'45 student.adm_code = u'my adm code'46 student.clearance_locked = False47 student.clr_code = u'my clr code'48 student.perm_address = u'Studentroad 21\nLagos 123456\n'49 student.reg_number = u'123456'50 student.student_id = u'A111111'51 student.firstname = u'Anna'52 student.lastname = u'Tester'53 student.middlename = u'M.'54 student.date_of_birth = datetime.date(1981, 2, 4)55 student.sex = 'f'56 student.email = 'anna@sample.com'57 student.phone = u'+234-123-12345'58 student.notice = u'Some notice\nin lines.'59 student.nationality = u'NG'60 return student61 33 62 34 def test_export(self): … … 104 76 def setUp(self): 105 77 super(StudentStudyCourseExporterTest, self).setUp() 106 student = Student() 107 student.student_id = u'A111111' 108 self.app['students'][student.student_id] = self.student = student 109 self.outfile = os.path.join(self.workdir, 'myoutput.csv') 110 self.cat = getUtility(ICatalog, name='students_catalog') 111 self.intids = getUtility(IIntIds) 112 #self.study_course = StudyCourse() 78 self.setup_for_export() 113 79 return 114 80 … … 125 91 self.assertTrue(result is not None) 126 92 return 127 128 def setup_student(self, student):129 # set predictable values for `student`130 student.matric_number = u'M123456'131 student.adm_code = u'my adm code'132 student.clearance_locked = False133 student.clr_code = u'my clr code'134 student.perm_address = u'Studentroad 21\nLagos 123456\n'135 student.reg_number = u'123456'136 student.student_id = u'A111111'137 student.firstname = u'Anna'138 student.lastname = u'Tester'139 student.middlename = u'M.'140 student.date_of_birth = datetime.date(1981, 2, 4)141 student.sex = 'f'142 student.email = 'anna@sample.com'143 student.phone = u'+234-123-12345'144 student.notice = u'Some notice\nin lines.'145 146 study_course = student.get('studycourse')147 student['studycourse'].certificate = self.certificate148 student['studycourse'].entry_mode = 'ug_ft'149 student['studycourse'].entry_session = 2010150 student['studycourse'].current_session = 2012151 student['studycourse'].current_level = int(self.certificate.start_level)152 return student153 93 154 94 def test_export_empty(self): … … 206 146 def setUp(self): 207 147 super(StudentStudyLevelExporterTest, self).setUp() 208 student = Student() 209 student.student_id = u'A111111' 210 self.app['students'][student.student_id] = self.student = student 211 self.outfile = os.path.join(self.workdir, 'myoutput.csv') 212 self.cat = getUtility(ICatalog, name='students_catalog') 213 self.intids = getUtility(IIntIds) 214 #self.study_level = StudyLevel() 148 self.setup_for_export() 215 149 return 216 150 … … 227 161 self.assertTrue(result is not None) 228 162 return 229 230 def setup_student(self, student):231 # set predictable values for `student`232 student.matric_number = u'M123456'233 student.adm_code = u'my adm code'234 student.clearance_locked = False235 student.clr_code = u'my clr code'236 student.perm_address = u'Studentroad 21\nLagos 123456\n'237 student.reg_number = u'123456'238 student.student_id = u'A111111'239 student.firstname = u'Anna'240 student.lastname = u'Tester'241 student.middlename = u'M.'242 student.date_of_birth = datetime.date(1981, 2, 4)243 student.sex = 'f'244 student.email = 'anna@sample.com'245 student.phone = u'+234-123-12345'246 student.notice = u'Some notice\nin lines.'247 248 study_course = student.get('studycourse')249 student['studycourse'].certificate = self.certificate250 student['studycourse'].entry_mode = 'ug_ft'251 student['studycourse'].entry_session = 2010252 student['studycourse'].current_session = 2012253 student['studycourse'].current_level = int(self.certificate.start_level)254 255 study_level = StudentStudyLevel()256 study_level.level_session = 2012257 study_level.level_verdict = "A"258 study_level.level = 100259 student['studycourse'].addStudentStudyLevel(260 self.certificate, study_level)261 return student262 163 263 164 def test_export_empty(self): … … 303 204 ) 304 205 return 206 207 class CourseTicketExporterTest(StudentImportExportSetup): 208 209 layer = FunctionalLayer 210 211 def setUp(self): 212 super(CourseTicketExporterTest, self).setUp() 213 self.setup_for_export() 214 return 215 216 def test_ifaces(self): 217 # make sure we fullfill interface contracts 218 obj = CourseTicketExporter() 219 verifyObject(ICSVExporter, obj) 220 verifyClass(ICSVExporter, CourseTicketExporter) 221 return 222 223 def test_get_as_utility(self): 224 # we can get an student exporter as utility 225 result = queryUtility(ICSVExporter, name="coursetickets") 226 self.assertTrue(result is not None) 227 return 228 229 def test_export_empty(self): 230 # we can export a nearly empty course ticket 231 ticket = CourseTicket() 232 exporter = CourseTicketExporter() 233 exporter.export([ticket], self.outfile) 234 result = open(self.outfile, 'rb').read() 235 self.assertEqual( 236 result, 237 'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,' 238 'matric_number,passmark,reg_number,score,semester,title\r\n' 239 '0,0,,,,,,0,,,,0,,\r\n' 240 ) 241 return 242 243 def test_export(self): 244 # we can really export course tickets. 245 # set values we can expect in export file 246 self.setup_student(self.student) 247 study_course = self.student.get('studycourse') 248 study_level = study_course[study_course.keys()[0]] 249 ticket = study_level['CRS1'] 250 exporter = CourseTicketExporter() 251 exporter.export([ticket], self.outfile) 252 result = open(self.outfile, 'rb').read() 253 self.assertEqual( 254 result, 255 'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,' 256 'matric_number,passmark,reg_number,score,semester,title\r\n' 257 '1,1,CRS1,100,DEP1,FAC1,100,0,M123456,100,123456,0,2,Course 1\r\n' 258 ) 259 return 260 261 def test_export_all(self): 262 # we can really export all course tickets 263 # set values we can expect in export file 264 self.setup_student(self.student) 265 exporter = CourseTicketExporter() 266 exporter.export_all(self.app, self.outfile) 267 result = open(self.outfile, 'rb').read() 268 self.assertEqual( 269 result, 270 'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,' 271 'matric_number,passmark,reg_number,score,semester,title\r\n' 272 '1,1,CRS1,100,DEP1,FAC1,100,0,M123456,100,123456,0,2,Course 1\r\n' 273 ) 274 return
Note: See TracChangeset for help on using the changeset viewer.