Changeset 9336


Ignore:
Timestamp:
15 Oct 2012, 07:49:01 (12 years ago)
Author:
Henrik Bettermann
Message:

Resort tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r9334 r9336  
    400400        return
    401401
    402 class StudentUITests(StudentsFullSetup):
     402class OfficerUITests(StudentsFullSetup):
    403403    # Tests for Student class views and pages
    404 
    405     layer = FunctionalLayer
    406404
    407405    def test_student_properties(self):
     
    743741        self.assertTrue(
    744742            self.student['studycourse']['200']['COURSE1'].carry_over)
     743        return
     744
     745    def test_manage_payments(self):
     746        # Managers can add online school fee payment tickets
     747        # if certain requirements are met
     748        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     749        self.browser.open(self.payments_path)
     750        IWorkflowState(self.student).setState('cleared')
     751        self.browser.getControl("Add online payment ticket").click()
     752        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     753        self.browser.getControl("Create ticket").click()
     754        self.assertMatches('...ticket created...',
     755                           self.browser.contents)
     756        ctrl = self.browser.getControl(name='val_id')
     757        value = ctrl.options[0]
     758        self.browser.getLink(value).click()
     759        self.assertMatches('...Amount Authorized...',
     760                           self.browser.contents)
     761        self.assertEqual(self.student['payments'][value].amount_auth, 40000.0)
     762        payment_url = self.browser.url
     763
     764        # The pdf payment slip can't yet be opened
     765        #self.browser.open(payment_url + '/payment_slip.pdf')
     766        #self.assertMatches('...Ticket not yet paid...',
     767        #                   self.browser.contents)
     768
     769        # The same payment (with same p_item, p_session and p_category)
     770        # can be initialized a second time if the former ticket is not yet paid.
     771        self.browser.open(self.payments_path)
     772        self.browser.getControl("Add online payment ticket").click()
     773        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     774        self.browser.getControl("Create ticket").click()
     775        self.assertMatches('...Payment ticket created...',
     776                           self.browser.contents)
     777
     778        # Managers can approve the payment
     779        self.assertEqual(len(self.app['accesscodes']['SFE-0']),0)
     780        self.browser.open(payment_url)
     781        self.browser.getLink("Approve payment").click()
     782        self.assertMatches('...Payment approved...',
     783                          self.browser.contents)
     784
     785        # The authorized amount has been stored in the access code
     786        self.assertEqual(
     787            self.app['accesscodes']['SFE-0'].values()[0].cost,40000.0)
     788
     789        # Payments can't be approved twice
     790        self.browser.open(payment_url + '/approve')
     791        self.assertMatches('...This ticket has already been paid...',
     792                          self.browser.contents)
     793
     794        # Now the first ticket is paid and no more ticket of same type
     795        # (with same p_item, p_session and p_category) can be added
     796        self.browser.open(self.payments_path)
     797        self.browser.getControl("Add online payment ticket").click()
     798        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     799        self.browser.getControl("Create ticket").click()
     800        self.assertMatches(
     801            '...This type of payment has already been made...',
     802            self.browser.contents)
     803
     804        # Managers can open the pdf payment slip
     805        self.browser.open(payment_url)
     806        self.browser.getLink("Download payment slip").click()
     807        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     808        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
     809
     810        # Managers can remove online school fee payment tickets
     811        self.browser.open(self.payments_path)
     812        self.browser.getControl("Remove selected").click()
     813        self.assertMatches('...No payment selected...', self.browser.contents)
     814        ctrl = self.browser.getControl(name='val_id')
     815        value = ctrl.options[0]
     816        ctrl.getControl(value=value).selected = True
     817        self.browser.getControl("Remove selected", index=0).click()
     818        self.assertTrue('Successfully removed' in self.browser.contents)
     819
     820        # Managers can add online clearance payment tickets
     821        self.browser.open(self.payments_path + '/addop')
     822        self.browser.getControl(name="form.p_category").value = ['clearance']
     823        self.browser.getControl("Create ticket").click()
     824        self.assertMatches('...ticket created...',
     825                           self.browser.contents)
     826
     827        # Managers can approve the payment
     828        self.assertEqual(len(self.app['accesscodes']['CLR-0']),0)
     829        ctrl = self.browser.getControl(name='val_id')
     830        value = ctrl.options[1] # The clearance payment is the second in the table
     831        self.browser.getLink(value).click()
     832        self.browser.open(self.browser.url + '/approve')
     833        self.assertMatches('...Payment approved...',
     834                          self.browser.contents)
     835        expected = '''...
     836        <td>
     837          <span>Paid</span>
     838        </td>...'''
     839        self.assertMatches(expected,self.browser.contents)
     840        # The new CLR-0 pin has been created
     841        self.assertEqual(len(self.app['accesscodes']['CLR-0']),1)
     842        pin = self.app['accesscodes']['CLR-0'].keys()[0]
     843        ac = self.app['accesscodes']['CLR-0'][pin]
     844        self.assertEqual(ac.owner, self.student_id)
     845        self.assertEqual(ac.cost, 3456.0)
     846        return
     847
     848    def test_manage_accommodation(self):
     849        # Managers can add online booking fee payment tickets and open the
     850        # callback view (see test_manage_payments)
     851        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     852        self.browser.open(self.payments_path)
     853        self.browser.getControl("Add online payment ticket").click()
     854        self.browser.getControl(name="form.p_category").value = ['bed_allocation']
     855        # If student is not in accommodation session, payment cannot be processed
     856        self.app['hostels'].accommodation_session = 2011
     857        self.browser.getControl("Create ticket").click()
     858        self.assertMatches('...Your current session does not match...',
     859                           self.browser.contents)
     860        self.app['hostels'].accommodation_session = 2004
     861        self.browser.getControl("Add online payment ticket").click()
     862        self.browser.getControl(name="form.p_category").value = ['bed_allocation']
     863        self.browser.getControl("Create ticket").click()
     864        ctrl = self.browser.getControl(name='val_id')
     865        value = ctrl.options[0]
     866        self.browser.getLink(value).click()
     867        self.browser.open(self.browser.url + '/approve')
     868        # The new HOS-0 pin has been created
     869        self.assertEqual(len(self.app['accesscodes']['HOS-0']),1)
     870        pin = self.app['accesscodes']['HOS-0'].keys()[0]
     871        ac = self.app['accesscodes']['HOS-0'][pin]
     872        self.assertEqual(ac.owner, self.student_id)
     873        parts = pin.split('-')[1:]
     874        sfeseries, sfenumber = parts
     875        # Managers can use HOS code and book a bed space with it
     876        self.browser.open(self.acco_path)
     877        self.browser.getLink("Book accommodation").click()
     878        self.assertMatches('...You are in the wrong...',
     879                           self.browser.contents)
     880        IWorkflowInfo(self.student).fireTransition('admit')
     881        # An existing HOS code can only be used if students
     882        # are in accommodation session
     883        self.student['studycourse'].current_session = 2003
     884        self.browser.getLink("Book accommodation").click()
     885        self.assertMatches('...Your current session does not match...',
     886                           self.browser.contents)
     887        self.student['studycourse'].current_session = 2004
     888        # All requirements are met and ticket can be created
     889        self.browser.getLink("Book accommodation").click()
     890        self.assertMatches('...Activation Code:...',
     891                           self.browser.contents)
     892        self.browser.getControl(name="ac_series").value = sfeseries
     893        self.browser.getControl(name="ac_number").value = sfenumber
     894        self.browser.getControl("Create bed ticket").click()
     895        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
     896                           self.browser.contents)
     897        # Bed has been allocated
     898        bed1 = self.app['hostels']['hall-1']['hall-1_A_101_A']
     899        self.assertTrue(bed1.owner == self.student_id)
     900        # BedTicketAddPage is now blocked
     901        self.browser.getLink("Book accommodation").click()
     902        self.assertMatches('...You already booked a bed space...',
     903            self.browser.contents)
     904        # The bed ticket displays the data correctly
     905        self.browser.open(self.acco_path + '/2004')
     906        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
     907                           self.browser.contents)
     908        self.assertMatches('...2004/2005...', self.browser.contents)
     909        self.assertMatches('...regular_male_fr...', self.browser.contents)
     910        self.assertMatches('...%s...' % pin, self.browser.contents)
     911        # Managers can relocate students if the student's bed_type has changed
     912        self.browser.getLink("Relocate student").click()
     913        self.assertMatches(
     914            "...Student can't be relocated...", self.browser.contents)
     915        self.student.sex = u'f'
     916        self.browser.getLink("Relocate student").click()
     917        self.assertMatches(
     918            "...Hall 1, Block A, Room 101, Bed B...", self.browser.contents)
     919        self.assertTrue(bed1.owner == NOT_OCCUPIED)
     920        bed2 = self.app['hostels']['hall-1']['hall-1_A_101_B']
     921        self.assertTrue(bed2.owner == self.student_id)
     922        self.assertTrue(self.student['accommodation'][
     923            '2004'].bed_type == u'regular_female_fr')
     924        # The payment object still shows the original payment item
     925        payment_id = self.student['payments'].keys()[0]
     926        payment = self.student['payments'][payment_id]
     927        self.assertTrue(payment.p_item == u'regular_male_fr')
     928        # Managers can relocate students if the bed's bed_type has changed
     929        bed1.bed_type = u'regular_female_fr'
     930        bed2.bed_type = u'regular_male_fr'
     931        notify(grok.ObjectModifiedEvent(bed1))
     932        notify(grok.ObjectModifiedEvent(bed2))
     933        self.browser.getLink("Relocate student").click()
     934        self.assertMatches(
     935            "...Student relocated...", self.browser.contents)
     936        self.assertMatches(
     937            "... Hall 1, Block A, Room 101, Bed A...", self.browser.contents)
     938        self.assertMatches(bed1.owner, self.student_id)
     939        self.assertMatches(bed2.owner, NOT_OCCUPIED)
     940        # Managers can't relocate students if bed is reserved
     941        self.student.sex = u'm'
     942        bed1.bed_type = u'regular_female_reserved'
     943        notify(grok.ObjectModifiedEvent(bed1))
     944        self.browser.getLink("Relocate student").click()
     945        self.assertMatches(
     946            "...Students in reserved beds can't be relocated...",
     947            self.browser.contents)
     948        # Managers can relocate students if booking has been cancelled but
     949        # other bed space has been manually allocated after cancellation
     950        old_owner = bed1.releaseBed()
     951        self.assertMatches(old_owner, self.student_id)
     952        bed2.owner = self.student_id
     953        self.browser.open(self.acco_path + '/2004')
     954        self.assertMatches(
     955            "...booking cancelled...", self.browser.contents)
     956        self.browser.getLink("Relocate student").click()
     957        # We didn't informed the catalog therefore the new owner is not found
     958        self.assertMatches(
     959            "...There is no free bed in your category regular_male_fr...",
     960            self.browser.contents)
     961        # Now we fire the event properly
     962        notify(grok.ObjectModifiedEvent(bed2))
     963        self.browser.getLink("Relocate student").click()
     964        self.assertMatches(
     965            "...Student relocated...", self.browser.contents)
     966        self.assertMatches(
     967            "... Hall 1, Block A, Room 101, Bed B...", self.browser.contents)
     968          # Managers can delete bed tickets
     969        self.browser.open(self.acco_path)
     970        ctrl = self.browser.getControl(name='val_id')
     971        value = ctrl.options[0]
     972        ctrl.getControl(value=value).selected = True
     973        self.browser.getControl("Remove selected", index=0).click()
     974        self.assertMatches('...Successfully removed...', self.browser.contents)
     975        # The bed has been properly released by the event handler
     976        self.assertMatches(bed1.owner, NOT_OCCUPIED)
     977        self.assertMatches(bed2.owner, NOT_OCCUPIED)
    745978        return
    746979
     
    10921325        self.assertTrue(self.student_id in self.browser.contents)
    10931326
     1327    def test_change_current_mode(self):
     1328        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     1329        self.browser.open(self.clearance_path)
     1330        self.assertFalse('Employer' in self.browser.contents)
     1331        self.browser.open(self.manage_clearance_path)
     1332        self.assertFalse('Employer' in self.browser.contents)
     1333        self.student.clearance_locked = False
     1334        self.browser.open(self.edit_clearance_path)
     1335        self.assertFalse('Employer' in self.browser.contents)
     1336        # Now we change the study mode of the certificate and a different
     1337        # interface is used by clearance views.
     1338        self.certificate.study_mode = 'pg_ft'
     1339        # Invariants are not being checked here?!
     1340        self.certificate.end_level = 100
     1341        self.browser.open(self.clearance_path)
     1342        self.assertTrue('Employer' in self.browser.contents)
     1343        self.browser.open(self.manage_clearance_path)
     1344        self.assertTrue('Employer' in self.browser.contents)
     1345        self.browser.open(self.edit_clearance_path)
     1346        self.assertTrue('Employer' in self.browser.contents)
     1347
     1348    def test_activate_deactivate_buttons(self):
     1349        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     1350        self.browser.open(self.student_path)
     1351        self.browser.getLink("Deactivate").click()
     1352        self.assertTrue(
     1353            'Student account has been deactivated.' in self.browser.contents)
     1354        self.assertTrue(
     1355            'Base Data (account deactivated)' in self.browser.contents)
     1356        self.assertTrue(self.student.suspended)
     1357        self.browser.getLink("Activate").click()
     1358        self.assertTrue(
     1359            'Student account has been activated.' in self.browser.contents)
     1360        self.assertFalse(
     1361            'Base Data (account deactivated)' in self.browser.contents)
     1362        self.assertFalse(self.student.suspended)
     1363        # History messages have been added ...
     1364        self.browser.getLink("History").click()
     1365        self.assertTrue(
     1366            'Student account deactivated by Manager<br />' in self.browser.contents)
     1367        self.assertTrue(
     1368            'Student account activated by Manager<br />' in self.browser.contents)
     1369        # ... and actions have been logged.
     1370        logfile = os.path.join(
     1371            self.app['datacenter'].storage, 'logs', 'students.log')
     1372        logcontent = open(logfile).read()
     1373        self.assertTrue('zope.mgr - students.browser.StudentDeactivatePage - '
     1374                        'K1000000 - account deactivated' in logcontent)
     1375        self.assertTrue('zope.mgr - students.browser.StudentActivatePage - '
     1376                        'K1000000 - account activated' in logcontent)
     1377
     1378    def test_manage_student_transfer(self):
     1379        # Add second certificate
     1380        self.certificate2 = createObject('waeup.Certificate')
     1381        self.certificate2.code = u'CERT2'
     1382        self.certificate2.study_mode = 'ug_ft'
     1383        self.certificate2.start_level = 999
     1384        self.certificate2.end_level = 999
     1385        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
     1386            self.certificate2)
     1387
     1388        # Add study level to old study course
     1389        studylevel = createObject(u'waeup.StudentStudyLevel')
     1390        studylevel.level = 200
     1391        self.student['studycourse'].addStudentStudyLevel(
     1392            self.certificate, studylevel)
     1393        studylevel = createObject(u'waeup.StudentStudyLevel')
     1394        studylevel.level = 999
     1395        self.student['studycourse'].addStudentStudyLevel(
     1396            self.certificate, studylevel)
     1397
     1398        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     1399        self.browser.open(self.student_path)
     1400        self.browser.getLink("Transfer").click()
     1401        self.browser.getControl(name="form.certificate").value = ['CERT2']
     1402        self.browser.getControl(name="form.current_session").value = ['2011']
     1403        self.browser.getControl(name="form.current_level").value = ['200']
     1404        self.browser.getControl("Transfer").click()
     1405        self.assertTrue(
     1406            'Current level does not match certificate levels'
     1407            in self.browser.contents)
     1408        self.browser.getControl(name="form.current_level").value = ['999']
     1409        self.browser.getControl("Transfer").click()
     1410        self.assertTrue('Successfully transferred' in self.browser.contents)
     1411        # The catalog has been updated
     1412        cat = queryUtility(ICatalog, name='students_catalog')
     1413        results = list(
     1414            cat.searchResults(
     1415            certcode=('CERT2', 'CERT2')))
     1416        self.assertTrue(results[0] is self.student)
     1417        results = list(
     1418            cat.searchResults(
     1419            current_session=(2011, 2011)))
     1420        self.assertTrue(results[0] is self.student)
     1421        # Add study level to new study course
     1422        studylevel = createObject(u'waeup.StudentStudyLevel')
     1423        studylevel.level = 999
     1424        self.student['studycourse'].addStudentStudyLevel(
     1425            self.certificate, studylevel)
     1426
     1427        # Edit and add pages are locked for old study courses
     1428        self.browser.open(self.student_path + '/studycourse/manage')
     1429        self.assertFalse('The requested form is locked' in self.browser.contents)
     1430        self.browser.open(self.student_path + '/studycourse_1/manage')
     1431        self.assertTrue('The requested form is locked' in self.browser.contents)
     1432
     1433        self.browser.open(self.student_path + '/studycourse/start_session')
     1434        self.assertFalse('The requested form is locked' in self.browser.contents)
     1435        self.browser.open(self.student_path + '/studycourse_1/start_session')
     1436        self.assertTrue('The requested form is locked' in self.browser.contents)
     1437
     1438        IWorkflowState(self.student).setState('school fee paid')
     1439        self.browser.open(self.student_path + '/studycourse/add')
     1440        self.assertFalse('The requested form is locked' in self.browser.contents)
     1441        self.browser.open(self.student_path + '/studycourse_1/add')
     1442        self.assertTrue('The requested form is locked' in self.browser.contents)
     1443
     1444        self.browser.open(self.student_path + '/studycourse/999/manage')
     1445        self.assertFalse('The requested form is locked' in self.browser.contents)
     1446        self.browser.open(self.student_path + '/studycourse_1/999/manage')
     1447        self.assertTrue('The requested form is locked' in self.browser.contents)
     1448
     1449        self.browser.open(self.student_path + '/studycourse/999/validate_courses')
     1450        self.assertFalse('The requested form is locked' in self.browser.contents)
     1451        self.browser.open(self.student_path + '/studycourse_1/999/validate_courses')
     1452        self.assertTrue('The requested form is locked' in self.browser.contents)
     1453
     1454        self.browser.open(self.student_path + '/studycourse/999/reject_courses')
     1455        self.assertFalse('The requested form is locked' in self.browser.contents)
     1456        self.browser.open(self.student_path + '/studycourse_1/999/reject_courses')
     1457        self.assertTrue('The requested form is locked' in self.browser.contents)
     1458
     1459        self.browser.open(self.student_path + '/studycourse/999/add')
     1460        self.assertFalse('The requested form is locked' in self.browser.contents)
     1461        self.browser.open(self.student_path + '/studycourse_1/999/add')
     1462        self.assertTrue('The requested form is locked' in self.browser.contents)
     1463
     1464        self.browser.open(self.student_path + '/studycourse/999/edit')
     1465        self.assertFalse('The requested form is locked' in self.browser.contents)
     1466        self.browser.open(self.student_path + '/studycourse_1/999/edit')
     1467        self.assertTrue('The requested form is locked' in self.browser.contents)
     1468
     1469class StudentUITests(StudentsFullSetup):
     1470    # Tests for Student class views and pages
     1471
    10941472    def test_student_change_password(self):
    10951473        # Students can change the password
     
    14511829        self.assertMatches('...Clearance has been requested...',
    14521830                           self.browser.contents)
    1453 
    1454     def test_manage_payments(self):
    1455         # Managers can add online school fee payment tickets
    1456         # if certain requirements are met
    1457         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    1458         self.browser.open(self.payments_path)
    1459         IWorkflowState(self.student).setState('cleared')
    1460         self.browser.getControl("Add online payment ticket").click()
    1461         self.browser.getControl(name="form.p_category").value = ['schoolfee']
    1462         self.browser.getControl("Create ticket").click()
    1463         self.assertMatches('...ticket created...',
    1464                            self.browser.contents)
    1465         ctrl = self.browser.getControl(name='val_id')
    1466         value = ctrl.options[0]
    1467         self.browser.getLink(value).click()
    1468         self.assertMatches('...Amount Authorized...',
    1469                            self.browser.contents)
    1470         self.assertEqual(self.student['payments'][value].amount_auth, 40000.0)
    1471         payment_url = self.browser.url
    1472 
    1473         # The pdf payment slip can't yet be opened
    1474         #self.browser.open(payment_url + '/payment_slip.pdf')
    1475         #self.assertMatches('...Ticket not yet paid...',
    1476         #                   self.browser.contents)
    1477 
    1478         # The same payment (with same p_item, p_session and p_category)
    1479         # can be initialized a second time if the former ticket is not yet paid.
    1480         self.browser.open(self.payments_path)
    1481         self.browser.getControl("Add online payment ticket").click()
    1482         self.browser.getControl(name="form.p_category").value = ['schoolfee']
    1483         self.browser.getControl("Create ticket").click()
    1484         self.assertMatches('...Payment ticket created...',
    1485                            self.browser.contents)
    1486 
    1487         # Managers can approve the payment
    1488         self.assertEqual(len(self.app['accesscodes']['SFE-0']),0)
    1489         self.browser.open(payment_url)
    1490         self.browser.getLink("Approve payment").click()
    1491         self.assertMatches('...Payment approved...',
    1492                           self.browser.contents)
    1493 
    1494         # The authorized amount has been stored in the access code
    1495         self.assertEqual(
    1496             self.app['accesscodes']['SFE-0'].values()[0].cost,40000.0)
    1497 
    1498         # Payments can't be approved twice
    1499         self.browser.open(payment_url + '/approve')
    1500         self.assertMatches('...This ticket has already been paid...',
    1501                           self.browser.contents)
    1502 
    1503         # Now the first ticket is paid and no more ticket of same type
    1504         # (with same p_item, p_session and p_category) can be added
    1505         self.browser.open(self.payments_path)
    1506         self.browser.getControl("Add online payment ticket").click()
    1507         self.browser.getControl(name="form.p_category").value = ['schoolfee']
    1508         self.browser.getControl("Create ticket").click()
    1509         self.assertMatches(
    1510             '...This type of payment has already been made...',
    1511             self.browser.contents)
    1512 
    1513         # Managers can open the pdf payment slip
    1514         self.browser.open(payment_url)
    1515         self.browser.getLink("Download payment slip").click()
    1516         self.assertEqual(self.browser.headers['Status'], '200 Ok')
    1517         self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
    1518 
    1519         # Managers can remove online school fee payment tickets
    1520         self.browser.open(self.payments_path)
    1521         self.browser.getControl("Remove selected").click()
    1522         self.assertMatches('...No payment selected...', self.browser.contents)
    1523         ctrl = self.browser.getControl(name='val_id')
    1524         value = ctrl.options[0]
    1525         ctrl.getControl(value=value).selected = True
    1526         self.browser.getControl("Remove selected", index=0).click()
    1527         self.assertTrue('Successfully removed' in self.browser.contents)
    1528 
    1529         # Managers can add online clearance payment tickets
    1530         self.browser.open(self.payments_path + '/addop')
    1531         self.browser.getControl(name="form.p_category").value = ['clearance']
    1532         self.browser.getControl("Create ticket").click()
    1533         self.assertMatches('...ticket created...',
    1534                            self.browser.contents)
    1535 
    1536         # Managers can approve the payment
    1537         self.assertEqual(len(self.app['accesscodes']['CLR-0']),0)
    1538         ctrl = self.browser.getControl(name='val_id')
    1539         value = ctrl.options[1] # The clearance payment is the second in the table
    1540         self.browser.getLink(value).click()
    1541         self.browser.open(self.browser.url + '/approve')
    1542         self.assertMatches('...Payment approved...',
    1543                           self.browser.contents)
    1544         expected = '''...
    1545         <td>
    1546           <span>Paid</span>
    1547         </td>...'''
    1548         self.assertMatches(expected,self.browser.contents)
    1549         # The new CLR-0 pin has been created
    1550         self.assertEqual(len(self.app['accesscodes']['CLR-0']),1)
    1551         pin = self.app['accesscodes']['CLR-0'].keys()[0]
    1552         ac = self.app['accesscodes']['CLR-0'][pin]
    1553         self.assertEqual(ac.owner, self.student_id)
    1554         self.assertEqual(ac.cost, 3456.0)
    1555         return
    15561831
    15571832    def test_student_payments(self):
     
    18592134        return
    18602135
    1861     def test_manage_accommodation(self):
    1862         # Managers can add online booking fee payment tickets and open the
    1863         # callback view (see test_manage_payments)
    1864         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    1865         self.browser.open(self.payments_path)
    1866         self.browser.getControl("Add online payment ticket").click()
    1867         self.browser.getControl(name="form.p_category").value = ['bed_allocation']
    1868         # If student is not in accommodation session, payment cannot be processed
    1869         self.app['hostels'].accommodation_session = 2011
    1870         self.browser.getControl("Create ticket").click()
    1871         self.assertMatches('...Your current session does not match...',
    1872                            self.browser.contents)
    1873         self.app['hostels'].accommodation_session = 2004
    1874         self.browser.getControl("Add online payment ticket").click()
    1875         self.browser.getControl(name="form.p_category").value = ['bed_allocation']
    1876         self.browser.getControl("Create ticket").click()
    1877         ctrl = self.browser.getControl(name='val_id')
    1878         value = ctrl.options[0]
    1879         self.browser.getLink(value).click()
    1880         self.browser.open(self.browser.url + '/approve')
    1881         # The new HOS-0 pin has been created
    1882         self.assertEqual(len(self.app['accesscodes']['HOS-0']),1)
    1883         pin = self.app['accesscodes']['HOS-0'].keys()[0]
    1884         ac = self.app['accesscodes']['HOS-0'][pin]
    1885         self.assertEqual(ac.owner, self.student_id)
    1886         parts = pin.split('-')[1:]
    1887         sfeseries, sfenumber = parts
    1888         # Managers can use HOS code and book a bed space with it
    1889         self.browser.open(self.acco_path)
    1890         self.browser.getLink("Book accommodation").click()
    1891         self.assertMatches('...You are in the wrong...',
    1892                            self.browser.contents)
    1893         IWorkflowInfo(self.student).fireTransition('admit')
    1894         # An existing HOS code can only be used if students
    1895         # are in accommodation session
    1896         self.student['studycourse'].current_session = 2003
    1897         self.browser.getLink("Book accommodation").click()
    1898         self.assertMatches('...Your current session does not match...',
    1899                            self.browser.contents)
    1900         self.student['studycourse'].current_session = 2004
    1901         # All requirements are met and ticket can be created
    1902         self.browser.getLink("Book accommodation").click()
    1903         self.assertMatches('...Activation Code:...',
    1904                            self.browser.contents)
    1905         self.browser.getControl(name="ac_series").value = sfeseries
    1906         self.browser.getControl(name="ac_number").value = sfenumber
    1907         self.browser.getControl("Create bed ticket").click()
    1908         self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
    1909                            self.browser.contents)
    1910         # Bed has been allocated
    1911         bed1 = self.app['hostels']['hall-1']['hall-1_A_101_A']
    1912         self.assertTrue(bed1.owner == self.student_id)
    1913         # BedTicketAddPage is now blocked
    1914         self.browser.getLink("Book accommodation").click()
    1915         self.assertMatches('...You already booked a bed space...',
    1916             self.browser.contents)
    1917         # The bed ticket displays the data correctly
    1918         self.browser.open(self.acco_path + '/2004')
    1919         self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
    1920                            self.browser.contents)
    1921         self.assertMatches('...2004/2005...', self.browser.contents)
    1922         self.assertMatches('...regular_male_fr...', self.browser.contents)
    1923         self.assertMatches('...%s...' % pin, self.browser.contents)
    1924         # Managers can relocate students if the student's bed_type has changed
    1925         self.browser.getLink("Relocate student").click()
    1926         self.assertMatches(
    1927             "...Student can't be relocated...", self.browser.contents)
    1928         self.student.sex = u'f'
    1929         self.browser.getLink("Relocate student").click()
    1930         self.assertMatches(
    1931             "...Hall 1, Block A, Room 101, Bed B...", self.browser.contents)
    1932         self.assertTrue(bed1.owner == NOT_OCCUPIED)
    1933         bed2 = self.app['hostels']['hall-1']['hall-1_A_101_B']
    1934         self.assertTrue(bed2.owner == self.student_id)
    1935         self.assertTrue(self.student['accommodation'][
    1936             '2004'].bed_type == u'regular_female_fr')
    1937         # The payment object still shows the original payment item
    1938         payment_id = self.student['payments'].keys()[0]
    1939         payment = self.student['payments'][payment_id]
    1940         self.assertTrue(payment.p_item == u'regular_male_fr')
    1941         # Managers can relocate students if the bed's bed_type has changed
    1942         bed1.bed_type = u'regular_female_fr'
    1943         bed2.bed_type = u'regular_male_fr'
    1944         notify(grok.ObjectModifiedEvent(bed1))
    1945         notify(grok.ObjectModifiedEvent(bed2))
    1946         self.browser.getLink("Relocate student").click()
    1947         self.assertMatches(
    1948             "...Student relocated...", self.browser.contents)
    1949         self.assertMatches(
    1950             "... Hall 1, Block A, Room 101, Bed A...", self.browser.contents)
    1951         self.assertMatches(bed1.owner, self.student_id)
    1952         self.assertMatches(bed2.owner, NOT_OCCUPIED)
    1953         # Managers can't relocate students if bed is reserved
    1954         self.student.sex = u'm'
    1955         bed1.bed_type = u'regular_female_reserved'
    1956         notify(grok.ObjectModifiedEvent(bed1))
    1957         self.browser.getLink("Relocate student").click()
    1958         self.assertMatches(
    1959             "...Students in reserved beds can't be relocated...",
    1960             self.browser.contents)
    1961         # Managers can relocate students if booking has been cancelled but
    1962         # other bed space has been manually allocated after cancellation
    1963         old_owner = bed1.releaseBed()
    1964         self.assertMatches(old_owner, self.student_id)
    1965         bed2.owner = self.student_id
    1966         self.browser.open(self.acco_path + '/2004')
    1967         self.assertMatches(
    1968             "...booking cancelled...", self.browser.contents)
    1969         self.browser.getLink("Relocate student").click()
    1970         # We didn't informed the catalog therefore the new owner is not found
    1971         self.assertMatches(
    1972             "...There is no free bed in your category regular_male_fr...",
    1973             self.browser.contents)
    1974         # Now we fire the event properly
    1975         notify(grok.ObjectModifiedEvent(bed2))
    1976         self.browser.getLink("Relocate student").click()
    1977         self.assertMatches(
    1978             "...Student relocated...", self.browser.contents)
    1979         self.assertMatches(
    1980             "... Hall 1, Block A, Room 101, Bed B...", self.browser.contents)
    1981           # Managers can delete bed tickets
    1982         self.browser.open(self.acco_path)
    1983         ctrl = self.browser.getControl(name='val_id')
    1984         value = ctrl.options[0]
    1985         ctrl.getControl(value=value).selected = True
    1986         self.browser.getControl("Remove selected", index=0).click()
    1987         self.assertMatches('...Successfully removed...', self.browser.contents)
    1988         # The bed has been properly released by the event handler
    1989         self.assertMatches(bed1.owner, NOT_OCCUPIED)
    1990         self.assertMatches(bed2.owner, NOT_OCCUPIED)
    1991         return
    1992 
    19932136    def test_student_accommodation(self):
    19942137        # Login
     
    20912234        self.browser.getControl("Send login credentials").click()
    20922235        self.assertTrue('An email with' in self.browser.contents)
    2093 
    2094     def test_change_current_mode(self):
    2095         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    2096         self.browser.open(self.clearance_path)
    2097         self.assertFalse('Employer' in self.browser.contents)
    2098         self.browser.open(self.manage_clearance_path)
    2099         self.assertFalse('Employer' in self.browser.contents)
    2100         self.student.clearance_locked = False
    2101         self.browser.open(self.edit_clearance_path)
    2102         self.assertFalse('Employer' in self.browser.contents)
    2103         # Now we change the study mode of the certificate and a different
    2104         # interface is used by clearance views.
    2105         self.certificate.study_mode = 'pg_ft'
    2106         # Invariants are not being checked here?!
    2107         self.certificate.end_level = 100
    2108         self.browser.open(self.clearance_path)
    2109         self.assertTrue('Employer' in self.browser.contents)
    2110         self.browser.open(self.manage_clearance_path)
    2111         self.assertTrue('Employer' in self.browser.contents)
    2112         self.browser.open(self.edit_clearance_path)
    2113         self.assertTrue('Employer' in self.browser.contents)
    2114 
    2115     def test_activate_deactivate_buttons(self):
    2116         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    2117         self.browser.open(self.student_path)
    2118         self.browser.getLink("Deactivate").click()
    2119         self.assertTrue(
    2120             'Student account has been deactivated.' in self.browser.contents)
    2121         self.assertTrue(
    2122             'Base Data (account deactivated)' in self.browser.contents)
    2123         self.assertTrue(self.student.suspended)
    2124         self.browser.getLink("Activate").click()
    2125         self.assertTrue(
    2126             'Student account has been activated.' in self.browser.contents)
    2127         self.assertFalse(
    2128             'Base Data (account deactivated)' in self.browser.contents)
    2129         self.assertFalse(self.student.suspended)
    2130         # History messages have been added ...
    2131         self.browser.getLink("History").click()
    2132         self.assertTrue(
    2133             'Student account deactivated by Manager<br />' in self.browser.contents)
    2134         self.assertTrue(
    2135             'Student account activated by Manager<br />' in self.browser.contents)
    2136         # ... and actions have been logged.
    2137         logfile = os.path.join(
    2138             self.app['datacenter'].storage, 'logs', 'students.log')
    2139         logcontent = open(logfile).read()
    2140         self.assertTrue('zope.mgr - students.browser.StudentDeactivatePage - '
    2141                         'K1000000 - account deactivated' in logcontent)
    2142         self.assertTrue('zope.mgr - students.browser.StudentActivatePage - '
    2143                         'K1000000 - account activated' in logcontent)
    2144 
    2145     def test_student_locked_level_forms(self):
    2146 
    2147         # Add two study levels, one current and one previous
    2148         studylevel = createObject(u'waeup.StudentStudyLevel')
    2149         studylevel.level = 100
    2150         self.student['studycourse'].addStudentStudyLevel(
    2151             self.certificate, studylevel)
    2152         studylevel = createObject(u'waeup.StudentStudyLevel')
    2153         studylevel.level = 200
    2154         self.student['studycourse'].addStudentStudyLevel(
    2155             self.certificate, studylevel)
    2156         IWorkflowState(self.student).setState('school fee paid')
    2157         self.student['studycourse'].current_level = 200
    2158 
    2159         self.browser.open(self.login_path)
    2160         self.browser.getControl(name="form.login").value = self.student_id
    2161         self.browser.getControl(name="form.password").value = 'spwd'
    2162         self.browser.getControl("Login").click()
    2163 
    2164         self.browser.open(self.student_path + '/studycourse/200/edit')
    2165         self.assertFalse('The requested form is locked' in self.browser.contents)
    2166         self.browser.open(self.student_path + '/studycourse/100/edit')
    2167         self.assertTrue('The requested form is locked' in self.browser.contents)
    2168 
    2169         self.browser.open(self.student_path + '/studycourse/200/ctadd')
    2170         self.assertFalse('The requested form is locked' in self.browser.contents)
    2171         self.browser.open(self.student_path + '/studycourse/100/ctadd')
    2172         self.assertTrue('The requested form is locked' in self.browser.contents)
    2173 
    2174         IWorkflowState(self.student).setState('courses registered')
    2175         self.browser.open(self.student_path + '/studycourse/200/edit')
    2176         self.assertTrue('The requested form is locked' in self.browser.contents)
    2177         self.browser.open(self.student_path + '/studycourse/200/ctadd')
    2178         self.assertTrue('The requested form is locked' in self.browser.contents)
    2179 
    2180 
    2181     def test_manage_student_transfer(self):
    2182         # Add second certificate
    2183         self.certificate2 = createObject('waeup.Certificate')
    2184         self.certificate2.code = u'CERT2'
    2185         self.certificate2.study_mode = 'ug_ft'
    2186         self.certificate2.start_level = 999
    2187         self.certificate2.end_level = 999
    2188         self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
    2189             self.certificate2)
    2190 
    2191         # Add study level to old study course
    2192         studylevel = createObject(u'waeup.StudentStudyLevel')
    2193         studylevel.level = 200
    2194         self.student['studycourse'].addStudentStudyLevel(
    2195             self.certificate, studylevel)
    2196         studylevel = createObject(u'waeup.StudentStudyLevel')
    2197         studylevel.level = 999
    2198         self.student['studycourse'].addStudentStudyLevel(
    2199             self.certificate, studylevel)
    2200 
    2201         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    2202         self.browser.open(self.student_path)
    2203         self.browser.getLink("Transfer").click()
    2204         self.browser.getControl(name="form.certificate").value = ['CERT2']
    2205         self.browser.getControl(name="form.current_session").value = ['2011']
    2206         self.browser.getControl(name="form.current_level").value = ['200']
    2207         self.browser.getControl("Transfer").click()
    2208         self.assertTrue(
    2209             'Current level does not match certificate levels'
    2210             in self.browser.contents)
    2211         self.browser.getControl(name="form.current_level").value = ['999']
    2212         self.browser.getControl("Transfer").click()
    2213         self.assertTrue('Successfully transferred' in self.browser.contents)
    2214         # The catalog has been updated
    2215         cat = queryUtility(ICatalog, name='students_catalog')
    2216         results = list(
    2217             cat.searchResults(
    2218             certcode=('CERT2', 'CERT2')))
    2219         self.assertTrue(results[0] is self.student)
    2220         results = list(
    2221             cat.searchResults(
    2222             current_session=(2011, 2011)))
    2223         self.assertTrue(results[0] is self.student)
    2224         # Add study level to new study course
    2225         studylevel = createObject(u'waeup.StudentStudyLevel')
    2226         studylevel.level = 999
    2227         self.student['studycourse'].addStudentStudyLevel(
    2228             self.certificate, studylevel)
    2229 
    2230         # Edit and add pages are locked for old study courses
    2231         self.browser.open(self.student_path + '/studycourse/manage')
    2232         self.assertFalse('The requested form is locked' in self.browser.contents)
    2233         self.browser.open(self.student_path + '/studycourse_1/manage')
    2234         self.assertTrue('The requested form is locked' in self.browser.contents)
    2235 
    2236         self.browser.open(self.student_path + '/studycourse/start_session')
    2237         self.assertFalse('The requested form is locked' in self.browser.contents)
    2238         self.browser.open(self.student_path + '/studycourse_1/start_session')
    2239         self.assertTrue('The requested form is locked' in self.browser.contents)
    2240 
    2241         IWorkflowState(self.student).setState('school fee paid')
    2242         self.browser.open(self.student_path + '/studycourse/add')
    2243         self.assertFalse('The requested form is locked' in self.browser.contents)
    2244         self.browser.open(self.student_path + '/studycourse_1/add')
    2245         self.assertTrue('The requested form is locked' in self.browser.contents)
    2246 
    2247         self.browser.open(self.student_path + '/studycourse/999/manage')
    2248         self.assertFalse('The requested form is locked' in self.browser.contents)
    2249         self.browser.open(self.student_path + '/studycourse_1/999/manage')
    2250         self.assertTrue('The requested form is locked' in self.browser.contents)
    2251 
    2252         self.browser.open(self.student_path + '/studycourse/999/validate_courses')
    2253         self.assertFalse('The requested form is locked' in self.browser.contents)
    2254         self.browser.open(self.student_path + '/studycourse_1/999/validate_courses')
    2255         self.assertTrue('The requested form is locked' in self.browser.contents)
    2256 
    2257         self.browser.open(self.student_path + '/studycourse/999/reject_courses')
    2258         self.assertFalse('The requested form is locked' in self.browser.contents)
    2259         self.browser.open(self.student_path + '/studycourse_1/999/reject_courses')
    2260         self.assertTrue('The requested form is locked' in self.browser.contents)
    2261 
    2262         self.browser.open(self.student_path + '/studycourse/999/add')
    2263         self.assertFalse('The requested form is locked' in self.browser.contents)
    2264         self.browser.open(self.student_path + '/studycourse_1/999/add')
    2265         self.assertTrue('The requested form is locked' in self.browser.contents)
    2266 
    2267         self.browser.open(self.student_path + '/studycourse/999/edit')
    2268         self.assertFalse('The requested form is locked' in self.browser.contents)
    2269         self.browser.open(self.student_path + '/studycourse_1/999/edit')
    2270         self.assertTrue('The requested form is locked' in self.browser.contents)
    22712236
    22722237class StudentRequestPWTests(StudentsFullSetup):
     
    23302295                        '234 (K1000000) - new@yy.zz' in logcontent)
    23312296        return
     2297
     2298    def test_student_locked_level_forms(self):
     2299
     2300        # Add two study levels, one current and one previous
     2301        studylevel = createObject(u'waeup.StudentStudyLevel')
     2302        studylevel.level = 100
     2303        self.student['studycourse'].addStudentStudyLevel(
     2304            self.certificate, studylevel)
     2305        studylevel = createObject(u'waeup.StudentStudyLevel')
     2306        studylevel.level = 200
     2307        self.student['studycourse'].addStudentStudyLevel(
     2308            self.certificate, studylevel)
     2309        IWorkflowState(self.student).setState('school fee paid')
     2310        self.student['studycourse'].current_level = 200
     2311
     2312        self.browser.open(self.login_path)
     2313        self.browser.getControl(name="form.login").value = self.student_id
     2314        self.browser.getControl(name="form.password").value = 'spwd'
     2315        self.browser.getControl("Login").click()
     2316
     2317        self.browser.open(self.student_path + '/studycourse/200/edit')
     2318        self.assertFalse('The requested form is locked' in self.browser.contents)
     2319        self.browser.open(self.student_path + '/studycourse/100/edit')
     2320        self.assertTrue('The requested form is locked' in self.browser.contents)
     2321
     2322        self.browser.open(self.student_path + '/studycourse/200/ctadd')
     2323        self.assertFalse('The requested form is locked' in self.browser.contents)
     2324        self.browser.open(self.student_path + '/studycourse/100/ctadd')
     2325        self.assertTrue('The requested form is locked' in self.browser.contents)
     2326
     2327        IWorkflowState(self.student).setState('courses registered')
     2328        self.browser.open(self.student_path + '/studycourse/200/edit')
     2329        self.assertTrue('The requested form is locked' in self.browser.contents)
     2330        self.browser.open(self.student_path + '/studycourse/200/ctadd')
     2331        self.assertTrue('The requested form is locked' in self.browser.contents)
Note: See TracChangeset for help on using the changeset viewer.