Changeset 7536 for main/waeup.sirp/trunk/src/waeup/sirp/students/tests
- Timestamp:
- 30 Jan 2012, 07:41:17 (13 years ago)
- 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
r7534 r7536 31 31 from waeup.sirp.university.department import Department 32 32 from waeup.sirp.students.batching import ( 33 StudentProcessor, StudentStudyCourseProcessor) 33 StudentProcessor, StudentStudyCourseProcessor, 34 StudentStudyLevelProcessor) 34 35 from waeup.sirp.students.student import Student 35 36 from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase … … 69 70 70 71 STUDENT_HEADER_FIELDS_MIGRATION = STUDENT_SAMPLE_DATA_MIGRATION.split( 72 '\n')[0].split(',') 73 74 STUDYLEVEL_SAMPLE_DATA = open( 75 os.path.join(os.path.dirname(__file__), 'sample_studylevel_data.csv'), 76 'rb').read() 77 78 STUDYLEVEL_HEADER_FIELDS = STUDYLEVEL_SAMPLE_DATA.split( 71 79 '\n')[0].split(',') 72 80 … … 212 220 shutil.rmtree(os.path.dirname(fin_file)) 213 221 222 214 223 class StudentStudyCourseImporterTest(FunctionalTestCase): 215 224 … … 218 227 def setUp(self): 219 228 super(StudentStudyCourseImporterTest, self).setUp() 229 self.dc_root = tempfile.mkdtemp() 230 self.workdir = tempfile.mkdtemp() 220 231 app = University() 221 self.dc_root = tempfile.mkdtemp()222 232 app['datacenter'].setStoragePath(self.dc_root) 223 224 233 self.getRootFolder()['app'] = app 225 234 self.app = self.getRootFolder()['app'] 226 235 setSite(app) 227 228 self.workdir = tempfile.mkdtemp()229 self.importer = StudentStudyCourseProcessor()230 self.csv_file = os.path.join(231 self.workdir, 'sample_studycourse_data.csv')232 open(self.csv_file, 'wb').write(STUDYCOURSE_SAMPLE_DATA)233 236 234 237 # Import students with subobjects … … 249 252 self.app['faculties']['fac1']['dep1'].certificates.addCertificate( 250 253 self.certificate) 254 255 self.importer = StudentStudyCourseProcessor() 256 self.csv_file = os.path.join( 257 self.workdir, 'sample_studycourse_data.csv') 258 open(self.csv_file, 'wb').write(STUDYCOURSE_SAMPLE_DATA) 251 259 return 252 260 … … 283 291 shutil.rmtree(os.path.dirname(fin_file)) 284 292 293 class StudentStudyLevelImporterTest(FunctionalTestCase): 294 295 layer = FunctionalLayer 296 297 def setUp(self): 298 super(StudentStudyLevelImporterTest, self).setUp() 299 self.dc_root = tempfile.mkdtemp() 300 self.workdir = tempfile.mkdtemp() 301 app = University() 302 app['datacenter'].setStoragePath(self.dc_root) 303 self.getRootFolder()['app'] = app 304 self.app = self.getRootFolder()['app'] 305 setSite(app) 306 307 # Import students with subobjects 308 student_file = os.path.join(self.workdir, 'sample_student_data.csv') 309 open(student_file, 'wb').write(STUDENT_SAMPLE_DATA) 310 num, num_warns, fin_file, fail_file = StudentProcessor().doImport( 311 student_file, STUDENT_HEADER_FIELDS) 312 shutil.rmtree(os.path.dirname(fin_file)) 313 314 # Populate university 315 self.certificate = createObject('waeup.Certificate') 316 self.certificate.code = 'CERT1' 317 self.certificate.application_category = 'basic' 318 self.certificate.start_level = 200 319 self.certificate.end_level = 500 320 self.app['faculties']['fac1'] = Faculty() 321 self.app['faculties']['fac1']['dep1'] = Department() 322 self.app['faculties']['fac1']['dep1'].certificates.addCertificate( 323 self.certificate) 324 325 # Update study courses 326 studycourse_file = os.path.join( 327 self.workdir, 'sample_studycourse_data.csv') 328 open(studycourse_file, 'wb').write(STUDYCOURSE_SAMPLE_DATA) 329 importer = StudentStudyCourseProcessor() 330 num, num_warns, fin_file, fail_file = importer.doImport( 331 studycourse_file, STUDYCOURSE_HEADER_FIELDS,'update') 332 shutil.rmtree(os.path.dirname(fin_file)) 333 334 self.importer = StudentStudyLevelProcessor() 335 self.csv_file = os.path.join( 336 self.workdir, 'sample_studylevel_data.csv') 337 open(self.csv_file, 'wb').write(STUDYLEVEL_SAMPLE_DATA) 338 339 def tearDown(self): 340 super(StudentStudyLevelImporterTest, self).tearDown() 341 shutil.rmtree(self.workdir) 342 shutil.rmtree(self.dc_root) 343 clearSite() 344 return 345 346 def test_interface(self): 347 # Make sure we fulfill the interface contracts. 348 assert verifyObject(IBatchProcessor, self.importer) is True 349 assert verifyClass( 350 IBatchProcessor, StudentStudyLevelProcessor) is True 351 352 def test_import(self): 353 num, num_warns, fin_file, fail_file = self.importer.doImport( 354 self.csv_file, STUDYLEVEL_HEADER_FIELDS,'create') 355 self.assertEqual(num_warns,2) 356 assert self.importer.entryExists( 357 dict(reg_number='1', level='100'), self.app) is True 358 studylevel = self.importer.getEntry( 359 dict(reg_number='1', level='100'), self.app) 360 self.assertEqual(studylevel.__parent__.certificate.code, u'CERT1') 361 self.assertEqual(studylevel.level_session, 2008) 362 self.assertEqual(studylevel.level_verdict, 'A') 363 self.assertEqual(studylevel.level, 100) 364 shutil.rmtree(os.path.dirname(fin_file)) 365 366 285 367 def test_suite(): 286 368 suite = unittest.TestSuite() 287 369 for testcase in [ 288 370 StudentImporterTest,StudentStudyCourseImporterTest, 289 ]:371 StudentStudyLevelImporterTest,]: 290 372 suite.addTest(unittest.TestLoader().loadTestsFromTestCase( 291 373 testcase … … 293 375 ) 294 376 return suite 377 378
Note: See TracChangeset for help on using the changeset viewer.