Changeset 9211 for main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/students/tests/test_batching.py
- Timestamp:
- 21 Sep 2012, 08:19:35 (12 years ago)
- Location:
- main/waeup.kofa/branches/uli-zc-async
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/branches/uli-zc-async
- Property svn:mergeinfo changed
/main/waeup.kofa/branches/uli-async-update removed /main/waeup.kofa/branches/uli-autoinclude-less removed /main/waeup.kofa/trunk removed
- Property svn:mergeinfo changed
-
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/students/tests/test_batching.py
r9209 r9211 23 23 import unittest 24 24 import datetime 25 import grok26 25 from time import time 27 from zope.event import notify28 26 from zope.component import createObject 29 27 from zope.component.hooks import setSite, clearSite 30 28 from zope.interface.verify import verifyClass, verifyObject 31 from hurry.workflow.interfaces import IWorkflowState32 29 33 30 from waeup.kofa.app import University … … 129 126 '\n')[0].split(',') 130 127 131 PAYMENT_CREATE_SAMPLE_DATA = open(132 os.path.join(os.path.dirname(__file__), 'sample_create_payment_data.csv'),133 'rb').read()134 135 PAYMENT_CREATE_HEADER_FIELDS = PAYMENT_CREATE_SAMPLE_DATA.split(136 '\n')[0].split(',')137 138 128 class StudentImportExportSetup(FunctionalTestCase): 139 129 … … 181 171 def setup_student(self, student): 182 172 # set predictable values for `student` 183 student.matric_number = u' 234'173 student.matric_number = u'M123456' 184 174 student.adm_code = u'my adm code' 185 175 student.clearance_locked = False 186 176 student.clr_code = u'my clr code' 187 177 student.perm_address = u'Studentroad 21\nLagos 123456\n' 188 student.reg_number = u'123' 178 student.reg_number = u'123456' 179 student.student_id = u'A111111' 189 180 student.firstname = u'Anna' 190 181 student.lastname = u'Tester' … … 220 211 ticket.passmark = 100 221 212 ticket.semester = 2 222 study_level [ticket.code] = ticket213 study_level.addCourseTicket(ticket) 223 214 self.add_payment(student) 224 215 return student … … 241 232 242 233 243 class StudentProcessorTest(StudentImportExportSetup): 234 235 class StudentProcessorTest(FunctionalTestCase): 244 236 245 237 layer = FunctionalLayer … … 247 239 def setUp(self): 248 240 super(StudentProcessorTest, self).setUp() 241 # Setup a sample site for each test 242 app = University() 243 self.dc_root = tempfile.mkdtemp() 244 app['datacenter'].setStoragePath(self.dc_root) 245 246 # Prepopulate the ZODB... 247 self.getRootFolder()['app'] = app 248 # we add the site immediately after creation to the 249 # ZODB. Catalogs and other local utilities are not setup 250 # before that step. 251 self.app = self.getRootFolder()['app'] 252 # Set site here. Some of the following setup code might need 253 # to access grok.getSite() and should get our new app then 254 setSite(app) 249 255 250 256 # Add student with subobjects 251 257 student = Student() 258 student.firstname = u'Anna' 259 student.lastname = u'Tester' 260 student.reg_number = u'123' 261 student.matric_number = u'234' 252 262 self.app['students'].addStudent(student) 253 student = self.setup_student(student)254 notify(grok.ObjectModifiedEvent(student))255 263 self.student = self.app['students'][student.student_id] 256 257 264 self.processor = StudentProcessor() 258 265 self.workdir = tempfile.mkdtemp() … … 278 285 open(self.csv_file_duplicates, 'wb').write(STUDENT_SAMPLE_DATA_DUPLICATES) 279 286 287 def tearDown(self): 288 super(StudentProcessorTest, self).tearDown() 289 shutil.rmtree(self.workdir) 290 shutil.rmtree(self.dc_root) 291 clearSite() 292 return 293 280 294 def test_interface(self): 281 295 # Make sure we fulfill the interface contracts. … … 329 343 self.assertEqual(initial_stud_id, new_stud_id) 330 344 return 331 332 def test_checkUpdateRequirements(self):333 # Make sure that pg students can't be updated with wrong transition.334 err = self.processor.checkUpdateRequirements(self.student,335 dict(reg_number='1', state='returning'), self.app)336 self.assertTrue(err is None)337 self.certificate.study_mode = 'pg_ft'338 err = self.processor.checkUpdateRequirements(self.student,339 dict(reg_number='1', state='returning'), self.app)340 self.assertEqual(err, 'State not allowed (pg student).')341 IWorkflowState(self.student).setState('school fee paid')342 err = self.processor.checkUpdateRequirements(self.student,343 dict(reg_number='1', transition='reset6'), self.app)344 self.assertEqual(err, 'Transition not allowed (pg student).')345 err = self.processor.checkUpdateRequirements(self.student,346 dict(reg_number='1', transition='register_courses'), self.app)347 self.assertEqual(err, 'Transition not allowed (pg student).')348 349 345 350 346 def test_delEntry(self): … … 490 486 super(StudentStudyCourseProcessorTest, self).setUp() 491 487 492 # Add student with subobjects493 student = Student()494 self.app['students'].addStudent(student)495 student = self.setup_student(student)496 notify(grok.ObjectModifiedEvent(student))497 self.student = self.app['students'][student.student_id]498 499 488 # Import students with subobjects 500 489 student_file = os.path.join(self.workdir, 'sample_student_data.csv') … … 543 532 dict(reg_number='1', current_level='100')) 544 533 self.assertEqual(len(errs),0) 545 546 def test_checkUpdateRequirements(self):547 # Make sure that pg students can't be updated with wrong transition.548 err = self.processor.checkUpdateRequirements(self.student['studycourse'],549 dict(reg_number='1', current_level='100'), self.app)550 self.assertTrue(err is None)551 # Since row has passed the converter, current_level is an integer.552 err = self.processor.checkUpdateRequirements(self.student['studycourse'],553 dict(reg_number='1', current_level=999), self.app)554 self.assertTrue(err is None)555 IWorkflowState(self.student).setState('returning')556 err = self.processor.checkUpdateRequirements(self.student['studycourse'],557 dict(reg_number='1', current_level=999), self.app)558 self.assertEqual(err, 'Not a pg student.')559 534 560 535 def test_import(self): … … 692 667 self.assertEqual(num_warns,2) 693 668 shutil.rmtree(os.path.dirname(fin_file)) 669 694 670 695 671 class CourseTicketProcessorTest(StudentImportExportSetup): … … 705 681 shutil.rmtree(os.path.dirname(fin_file)) 706 682 707 # Add course and c ertificate course683 # Add course and course referrer 708 684 self.course = createObject('waeup.Course') 709 685 self.course.code = 'COURSE1' … … 713 689 self.app['faculties']['fac1']['dep1'].courses.addCourse( 714 690 self.course) 715 self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addC ertCourse(691 self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCourseRef( 716 692 self.course, level=100) 717 693 … … 779 755 # Logging message from updateEntry, 780 756 self.assertTrue( 781 'INFO - system - K1000000 - Course ticket in 100updated: code=COURSE1, '757 'INFO - system - K1000000 - Course ticket updated: code=COURSE1, ' 782 758 'mandatory=False, score=3' 783 759 in logcontent) … … 793 769 self.assertEqual(num_warns,2) 794 770 shutil.rmtree(os.path.dirname(fin_file)) 795 796 def test_import_remove(self):797 # We perform the same import twice,798 # the second time in remove mode. The number799 # of warnings must be the same.800 num, num_warns, fin_file, fail_file = self.processor.doImport(801 self.csv_file, COURSETICKET_HEADER_FIELDS,'create')802 assert self.processor.entryExists(803 dict(reg_number='1', level='100', code='COURSE1'), self.app) is True804 num, num_warns, fin_file, fail_file = self.processor.doImport(805 self.csv_file, COURSETICKET_HEADER_FIELDS,'remove')806 self.assertEqual(num_warns,2)807 assert self.processor.entryExists(808 dict(reg_number='1', level='100', code='COURSE1'), self.app) is False809 shutil.rmtree(os.path.dirname(fin_file))810 logcontent = open(self.logfile).read()811 self.assertTrue(812 'INFO - system - K1000000 - Course ticket in 100 removed: COURSE1'813 in logcontent)814 771 815 772 class PaymentProcessorTest(StudentImportExportSetup): … … 827 784 self.student = self.app['students'][student.student_id] 828 785 payment = createObject(u'waeup.StudentOnlinePayment') 829 payment.p_id = 'p12 0'786 payment.p_id = 'p123' 830 787 self.student['payments'][payment.p_id] = payment 831 788 … … 841 798 self.workdir, 'sample_payment_data.csv') 842 799 open(self.csv_file, 'wb').write(PAYMENT_SAMPLE_DATA) 843 self.csv_file2 = os.path.join(844 self.workdir, 'sample_create_payment_data.csv')845 open(self.csv_file2, 'wb').write(PAYMENT_CREATE_SAMPLE_DATA)846 800 847 801 def test_interface(self): … … 855 809 dict(student_id='ID_NONE', p_id='nonsense'), self.app) is None 856 810 assert self.processor.getEntry( 857 dict(student_id=self.student.student_id, p_id='p12 0'),858 self.app) is self.student['payments']['p12 0']811 dict(student_id=self.student.student_id, p_id='p123'), 812 self.app) is self.student['payments']['p123'] 859 813 assert self.processor.getEntry( 860 dict(student_id=self.student.student_id, p_id='XXXXXX112'), 861 self.app) is self.student['payments']['p120'] 862 863 def test_delEntry(self): 864 assert self.processor.getEntry( 865 dict(student_id=self.student.student_id, p_id='p120'), 866 self.app) is self.student['payments']['p120'] 867 self.assertEqual(len(self.student['payments'].keys()),1) 868 self.processor.delEntry( 869 dict(student_id=self.student.student_id, p_id='p120'), 870 self.app) 871 assert self.processor.getEntry( 872 dict(student_id=self.student.student_id, p_id='p120'), 873 self.app) is None 874 self.assertEqual(len(self.student['payments'].keys()),0) 814 dict(student_id=self.student.student_id, p_id='XXXXXX123'), 815 self.app) is self.student['payments']['p123'] 875 816 876 817 def test_addEntry(self): … … 890 831 self.app) 891 832 self.assertEqual(len(self.student['payments'].keys()),3) 892 self.assertEqual(self.student['payments']['p 560'].p_id, 'p560')833 self.assertEqual(self.student['payments']['p456'].p_id, 'p456') 893 834 894 835 def test_checkConversion(self): 895 836 errs, inv_errs, conv_dict = self.processor.checkConversion( 896 dict( p_id='3816951266236341955'))837 dict(reg_number='1', p_id='3816951266236341955')) 897 838 self.assertEqual(len(errs),0) 898 839 errs, inv_errs, conv_dict = self.processor.checkConversion( 899 dict( p_id='p1266236341955'))840 dict(reg_number='1', p_id='p1266236341955')) 900 841 self.assertEqual(len(errs),0) 901 842 errs, inv_errs, conv_dict = self.processor.checkConversion( 902 dict( p_id='nonsense'))843 dict(reg_number='1', p_id='nonsense')) 903 844 self.assertEqual(len(errs),1) 904 timestamp = ("%d" % int(time()*10000))[1:]845 timestamp = "%d" % int(time()*1000) 905 846 p_id = "p%s" % timestamp 906 847 errs, inv_errs, conv_dict = self.processor.checkConversion( 907 dict( p_id=p_id))848 dict(reg_number='1', p_id=p_id)) 908 849 self.assertEqual(len(errs),0) 909 850 … … 913 854 self.assertEqual(num_warns,0) 914 855 payment = self.processor.getEntry(dict(reg_number='1', 915 p_id='p2907979737440'), self.app) 916 self.assertEqual(payment.p_id, 'p2907979737440') 917 self.assertTrue(payment.p_current) 856 p_id='p1290797973744'), self.app) 857 self.assertEqual(payment.p_id, 'p1290797973744') 918 858 cdate = payment.creation_date.strftime("%Y-%m-%d %H:%M:%S") 919 859 self.assertEqual(cdate, "2010-11-26 18:59:33") 920 860 self.assertEqual(str(payment.creation_date.tzinfo),'UTC') 921 payment = self.processor.getEntry(dict(matric_number='100001', 922 p_id='p2907125937570'), self.app) 923 self.assertEqual(payment.p_id, 'p2907125937570') 924 self.assertFalse(payment.p_current) 925 cdate = payment.creation_date.strftime("%Y-%m-%d %H:%M:%S") 926 # Ooooh, still the old problem, see 927 # http://mail.dzug.org/mailman/archives/zope/2006-August/001153.html. 928 # WAT is interpreted as GMT-1 and not GMT+1 929 self.assertEqual(cdate, "2010-11-25 21:16:33") 930 self.assertEqual(str(payment.creation_date.tzinfo),'UTC') 931 shutil.rmtree(os.path.dirname(fin_file)) 861 shutil.rmtree(os.path.dirname(fin_file)) 862 932 863 logcontent = open(self.logfile).read() 933 # Logging message from updateEntry 864 # Logging message from updateEntry, 934 865 self.assertTrue( 935 866 'INFO - system - K1000001 - Payment ticket updated: ' 936 'p_i tem=BTECHBDT, creation_date=2010-02-15 13:19:01+00:00, '937 ' p_category=schoolfee, amount_auth=19500.0, p_current=True, '938 ' p_id=p1266236341955, r_code=00, r_amount_approved=19500.0, '939 ' p_state=paid'867 'p_id=p1266236341955, p_item=BTECHBDT, ' 868 'creation_date=2010-02-15 13:19:01+00:00, r_code=00, ' 869 'r_amount_approved=19500.0, p_category=schoolfee, ' 870 'amount_auth=19500.0, p_state=paid' 940 871 in logcontent) 941 872 … … 950 881 self.assertEqual(num_warns,0) 951 882 shutil.rmtree(os.path.dirname(fin_file)) 952 953 def test_import_remove(self):954 num, num_warns, fin_file, fail_file = self.processor.doImport(955 self.csv_file, PAYMENT_HEADER_FIELDS,'create')956 num, num_warns, fin_file, fail_file = self.processor.doImport(957 self.csv_file, PAYMENT_HEADER_FIELDS,'remove')958 self.assertEqual(num_warns,0)959 shutil.rmtree(os.path.dirname(fin_file))960 logcontent = open(self.logfile).read()961 self.assertTrue(962 'INFO - system - K1000001 - Payment ticket removed: p1266236341955'963 in logcontent)964 965 def test_import_wo_pid(self):966 num, num_warns, fin_file, fail_file = self.processor.doImport(967 self.csv_file2, PAYMENT_CREATE_HEADER_FIELDS,'create')968 self.assertEqual(num_warns,0)969 shutil.rmtree(os.path.dirname(fin_file))970 self.assertEqual(len(self.app['students']['X666666']['payments']), 50)971 972 883 973 884 def test_suite():
Note: See TracChangeset for help on using the changeset viewer.