Ignore:
Timestamp:
21 Sep 2012, 08:19:35 (12 years ago)
Author:
uli
Message:

Rollback r9209. Looks like multiple merges from trunk confuse svn when merging back into trunk.

Location:
main/waeup.kofa/branches/uli-zc-async
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/branches/uli-zc-async

  • main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/students/tests/test_batching.py

    r9209 r9211  
    2323import unittest
    2424import datetime
    25 import grok
    2625from time import time
    27 from zope.event import notify
    2826from zope.component import createObject
    2927from zope.component.hooks import setSite, clearSite
    3028from zope.interface.verify import verifyClass, verifyObject
    31 from hurry.workflow.interfaces import IWorkflowState
    3229
    3330from waeup.kofa.app import University
     
    129126    '\n')[0].split(',')
    130127
    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 
    138128class StudentImportExportSetup(FunctionalTestCase):
    139129
     
    181171    def setup_student(self, student):
    182172        # set predictable values for `student`
    183         student.matric_number = u'234'
     173        student.matric_number = u'M123456'
    184174        student.adm_code = u'my adm code'
    185175        student.clearance_locked = False
    186176        student.clr_code = u'my clr code'
    187177        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'
    189180        student.firstname = u'Anna'
    190181        student.lastname = u'Tester'
     
    220211        ticket.passmark = 100
    221212        ticket.semester = 2
    222         study_level[ticket.code] = ticket
     213        study_level.addCourseTicket(ticket)
    223214        self.add_payment(student)
    224215        return student
     
    241232
    242233
    243 class StudentProcessorTest(StudentImportExportSetup):
     234
     235class StudentProcessorTest(FunctionalTestCase):
    244236
    245237    layer = FunctionalLayer
     
    247239    def setUp(self):
    248240        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)
    249255
    250256        # Add student with subobjects
    251257        student = Student()
     258        student.firstname = u'Anna'
     259        student.lastname = u'Tester'
     260        student.reg_number = u'123'
     261        student.matric_number = u'234'
    252262        self.app['students'].addStudent(student)
    253         student = self.setup_student(student)
    254         notify(grok.ObjectModifiedEvent(student))
    255263        self.student = self.app['students'][student.student_id]
    256 
    257264        self.processor = StudentProcessor()
    258265        self.workdir = tempfile.mkdtemp()
     
    278285        open(self.csv_file_duplicates, 'wb').write(STUDENT_SAMPLE_DATA_DUPLICATES)
    279286
     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
    280294    def test_interface(self):
    281295        # Make sure we fulfill the interface contracts.
     
    329343        self.assertEqual(initial_stud_id, new_stud_id)
    330344        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 
    349345
    350346    def test_delEntry(self):
     
    490486        super(StudentStudyCourseProcessorTest, self).setUp()
    491487
    492         # Add student with subobjects
    493         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 
    499488        # Import students with subobjects
    500489        student_file = os.path.join(self.workdir, 'sample_student_data.csv')
     
    543532            dict(reg_number='1', current_level='100'))
    544533        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.')
    559534
    560535    def test_import(self):
     
    692667        self.assertEqual(num_warns,2)
    693668        shutil.rmtree(os.path.dirname(fin_file))
     669       
    694670
    695671class CourseTicketProcessorTest(StudentImportExportSetup):
     
    705681        shutil.rmtree(os.path.dirname(fin_file))
    706682
    707         # Add course and certificate course
     683        # Add course and course referrer
    708684        self.course = createObject('waeup.Course')
    709685        self.course.code = 'COURSE1'
     
    713689        self.app['faculties']['fac1']['dep1'].courses.addCourse(
    714690            self.course)
    715         self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
     691        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCourseRef(
    716692            self.course, level=100)
    717693
     
    779755        # Logging message from updateEntry,
    780756        self.assertTrue(
    781             'INFO - system - K1000000 - Course ticket in 100 updated: code=COURSE1, '
     757            'INFO - system - K1000000 - Course ticket updated: code=COURSE1, '
    782758            'mandatory=False, score=3'
    783759            in logcontent)
     
    793769        self.assertEqual(num_warns,2)
    794770        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 number
    799         # 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 True
    804         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 False
    809         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)
    814771
    815772class PaymentProcessorTest(StudentImportExportSetup):
     
    827784        self.student = self.app['students'][student.student_id]
    828785        payment = createObject(u'waeup.StudentOnlinePayment')
    829         payment.p_id = 'p120'
     786        payment.p_id = 'p123'
    830787        self.student['payments'][payment.p_id] = payment
    831788
     
    841798            self.workdir, 'sample_payment_data.csv')
    842799        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)
    846800
    847801    def test_interface(self):
     
    855809            dict(student_id='ID_NONE', p_id='nonsense'), self.app) is None
    856810        assert self.processor.getEntry(
    857             dict(student_id=self.student.student_id, p_id='p120'),
    858             self.app) is self.student['payments']['p120']
     811            dict(student_id=self.student.student_id, p_id='p123'),
     812            self.app) is self.student['payments']['p123']
    859813        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']
    875816
    876817    def test_addEntry(self):
     
    890831            self.app)
    891832        self.assertEqual(len(self.student['payments'].keys()),3)
    892         self.assertEqual(self.student['payments']['p560'].p_id, 'p560')
     833        self.assertEqual(self.student['payments']['p456'].p_id, 'p456')
    893834
    894835    def test_checkConversion(self):
    895836        errs, inv_errs, conv_dict = self.processor.checkConversion(
    896             dict(p_id='3816951266236341955'))
     837            dict(reg_number='1', p_id='3816951266236341955'))
    897838        self.assertEqual(len(errs),0)
    898839        errs, inv_errs, conv_dict = self.processor.checkConversion(
    899             dict(p_id='p1266236341955'))
     840            dict(reg_number='1', p_id='p1266236341955'))
    900841        self.assertEqual(len(errs),0)
    901842        errs, inv_errs, conv_dict = self.processor.checkConversion(
    902             dict(p_id='nonsense'))
     843            dict(reg_number='1', p_id='nonsense'))
    903844        self.assertEqual(len(errs),1)
    904         timestamp = ("%d" % int(time()*10000))[1:]
     845        timestamp = "%d" % int(time()*1000)
    905846        p_id = "p%s" % timestamp
    906847        errs, inv_errs, conv_dict = self.processor.checkConversion(
    907             dict(p_id=p_id))
     848            dict(reg_number='1', p_id=p_id))
    908849        self.assertEqual(len(errs),0)
    909850
     
    913854        self.assertEqual(num_warns,0)
    914855        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')
    918858        cdate = payment.creation_date.strftime("%Y-%m-%d %H:%M:%S")
    919859        self.assertEqual(cdate, "2010-11-26 18:59:33")
    920860        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
    932863        logcontent = open(self.logfile).read()
    933         # Logging message from updateEntry
     864        # Logging message from updateEntry,
    934865        self.assertTrue(
    935866            'INFO - system - K1000001 - Payment ticket updated: '
    936             'p_item=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'
    940871            in logcontent)
    941872
     
    950881        self.assertEqual(num_warns,0)
    951882        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 
    972883
    973884def test_suite():
Note: See TracChangeset for help on using the changeset viewer.