- Timestamp:
- 28 Mar 2012, 06:12:21 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py
r7993 r7994 6 6 from zope.intid.interfaces import IIntIds 7 7 from waeup.kofa.interfaces import ICSVExporter 8 from waeup.kofa.students.export import StudentsExporter 9 from waeup.kofa.students.student import Student 8 from waeup.kofa.students.export import ( 9 StudentsExporter, StudentStudyCourseExporter) 10 from waeup.kofa.students.student import Student, StudentStudyCourse 10 11 from waeup.kofa.students.tests.test_batching import StudentImportExportSetup 11 12 from waeup.kofa.testing import FunctionalLayer … … 95 96 return 96 97 98 class StudentStudyCourseExporterTest(StudentImportExportSetup): 99 100 layer = FunctionalLayer 101 102 def setUp(self): 103 super(StudentStudyCourseExporterTest, self).setUp() 104 student = Student() 105 student.student_id = u'A111111' 106 self.app['students'][student.student_id] = self.student = student 107 self.outfile = os.path.join(self.workdir, 'myoutput.csv') 108 self.cat = getUtility(ICatalog, name='students_catalog') 109 self.intids = getUtility(IIntIds) 110 #self.study_course = StudyCourse() 111 return 112 113 def test_ifaces(self): 114 # make sure we fullfill interface contracts 115 obj = StudentStudyCourseExporter() 116 verifyObject(ICSVExporter, obj) 117 verifyClass(ICSVExporter, StudentStudyCourseExporter) 118 return 119 120 def test_get_as_utility(self): 121 # we can get an student exporter as utility 122 result = queryUtility(ICSVExporter, name="studentstudycourses") 123 self.assertTrue(result is not None) 124 return 125 126 def setup_student(self, student): 127 # set predictable values for `student` 128 student.matric_number = u'M123456' 129 student.adm_code = u'my adm code' 130 student.clearance_locked = False 131 student.clr_code = u'my clr code' 132 student.perm_address = u'Studentroad 21\nLagos 123456\n' 133 student.reg_number = u'123456' 134 student.student_id = u'A111111' 135 student.firstname = u'Anna' 136 student.lastname = u'Tester' 137 student.middlename = u'M.' 138 student.date_of_birth = datetime.date(1981, 2, 4) 139 student.sex = 'f' 140 student.email = 'anna@sample.com' 141 student.phone = u'+234-123-12345' 142 student.notice = u'Some notice\nin lines.' 143 144 study_course = student.get('studycourse') 145 student['studycourse'].certificate = self.certificate 146 student['studycourse'].entry_mode = 'ug_ft' 147 student['studycourse'].entry_session = 2010 148 student['studycourse'].current_session = 2012 149 student['studycourse'].current_level = int(self.certificate.start_level) 150 return student 151 152 def test_export_empty(self): 153 # we can export a nearly empty study course 154 study_course = StudentStudyCourse() 155 exporter = StudentStudyCourseExporter() 156 exporter.export([study_course], self.outfile) 157 result = open(self.outfile, 'rb').read() 158 self.assertEqual( 159 result, 160 'certificate,current_level,current_session,current_verdict,' 161 'entry_mode,entry_session,previous_verdict\r\n' 162 163 ',,,0,,,0\r\n' 164 ) 165 return 166 167 def test_export(self): 168 # we can really export study courses. 169 # set values we can expect in export file 170 self.setup_student(self.student) 171 study_course = self.student.get('studycourse') 172 exporter = StudentStudyCourseExporter() 173 exporter.export([study_course], self.outfile) 174 result = open(self.outfile, 'rb').read() 175 self.assertEqual( 176 result, 177 'certificate,current_level,current_session,current_verdict,' 178 'entry_mode,entry_session,previous_verdict\r\n' 179 180 'CERT1,200,2012,0,ug_ft,2010,0\r\n' 181 ) 182 return 183 184 def test_export_all(self): 185 # we can really export students 186 # set values we can expect in export file 187 self.setup_student(self.student) 188 exporter = StudentStudyCourseExporter() 189 exporter.export_all(self.app, self.outfile) 190 result = open(self.outfile, 'rb').read() 191 self.assertEqual( 192 result, 193 'certificate,current_level,current_session,current_verdict,' 194 'entry_mode,entry_session,previous_verdict\r\n' 195 196 'CERT1,200,2012,0,ug_ft,2010,0\r\n' 197 ) 198 return
Note: See TracChangeset for help on using the changeset viewer.