Changeset 7604
- Timestamp:
- 8 Feb 2012, 10:37:42 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.custom/trunk/src/waeup/custom/students/tests.py
r7419 r7604 16 16 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 17 ## 18 import os 19 import shutil 20 import tempfile 21 from zope.component.hooks import setSite, clearSite 22 from waeup.sirp.app import University 23 from waeup.sirp.students.tests.test_browser import StudentsFullSetup 24 from waeup.sirp.testing import FunctionalTestCase 25 from waeup.sirp.students.batching import StudentProcessor as StudentProcessorBase 26 from waeup.custom.students.batching import StudentProcessor 18 27 from waeup.custom.testing import FunctionalLayer 19 from waeup.sirp.students.tests.test_browser import StudentsFullSetup20 28 from waeup.custom.configuration import SessionConfiguration 21 29 30 STUDENT_SAMPLE_DATA = open( 31 os.path.join(os.path.dirname(__file__), 'sample_student_data.csv'), 32 'rb').read() 33 34 STUDENT_HEADER_FIELDS = STUDENT_SAMPLE_DATA.split( 35 '\n')[0].split(',') 36 37 class StudentImporterTest(FunctionalTestCase): 38 """Perform some batching tests. 39 """ 40 41 layer = FunctionalLayer 42 43 def setUp(self): 44 super(StudentImporterTest, self).setUp() 45 # Setup a sample site for each test 46 app = University() 47 self.dc_root = tempfile.mkdtemp() 48 app['datacenter'].setStoragePath(self.dc_root) 49 50 # Prepopulate the ZODB... 51 self.getRootFolder()['app'] = app 52 # we add the site immediately after creation to the 53 # ZODB. Catalogs and other local utilities are not setup 54 # before that step. 55 self.app = self.getRootFolder()['app'] 56 # Set site here. Some of the following setup code might need 57 # to access grok.getSite() and should get our new app then 58 setSite(app) 59 60 self.importer_base = StudentProcessorBase() 61 self.importer = StudentProcessor() 62 self.workdir = tempfile.mkdtemp() 63 self.csv_file = os.path.join(self.workdir, 'sample_student_data.csv') 64 open(self.csv_file, 'wb').write(STUDENT_SAMPLE_DATA) 65 66 def tearDown(self): 67 super(StudentImporterTest, self).tearDown() 68 shutil.rmtree(self.workdir) 69 shutil.rmtree(self.dc_root) 70 clearSite() 71 return 72 73 def test_import(self): 74 # We added empty columns 'nationality' and 'lga' to the import file. 75 # The original importer will fail because these fields are required 76 # in the base package. 77 num, num_warns, fin_file, fail_file = self.importer_base.doImport( 78 self.csv_file, STUDENT_HEADER_FIELDS) 79 self.assertEqual(num_warns,3) 80 assert len(self.app['students'].keys()) == 0 81 # The customized importer does not complain since both fields are 82 # not required in the custom package. 83 num, num_warns, fin_file, fail_file = self.importer.doImport( 84 self.csv_file, STUDENT_HEADER_FIELDS) 85 self.assertEqual(num_warns,0) 86 assert len(self.app['students'].keys()) == 3 87 shutil.rmtree(os.path.dirname(fin_file)) 88 89 22 90 class StudentUITests(StudentsFullSetup): 23 # Tests for customized student class views and pages 91 """Tests for customized student class views and pages 92 """ 24 93 25 94 layer = FunctionalLayer
Note: See TracChangeset for help on using the changeset viewer.