## $Id: test_browser.py 11069 2014-02-11 07:49:25Z henrik $
##
## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
import os
import shutil
import tempfile
from StringIO import StringIO
from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo
from zope.securitypolicy.interfaces import IPrincipalRoleManager
from zope.component.hooks import setSite, clearSite
from zope.component import getUtility, createObject
from zope.interface import verify
from zope.event import notify
from waeup.kofa.authentication import LocalRoleSetEvent
from waeup.kofa.app import University
from waeup.kofa.students.tests.test_browser import StudentsFullSetup
from waeup.kofa.students.accommodation import BedTicket
from waeup.kofa.testing import FunctionalTestCase
from waeup.kofa.interfaces import (
IExtFileStore, IFileStoreNameChooser)
from waeup.kofa.students.interfaces import IStudentsUtils
from waeup.uniben.testing import FunctionalLayer
class StudentUITests(StudentsFullSetup):
"""Tests for customized student class views and pages
"""
layer = FunctionalLayer
def setUp(self):
super(StudentUITests, self).setUp()
bedticket = BedTicket()
bedticket.booking_session = 2004
bedticket.bed_type = u'any bed type'
bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
bedticket.bed_coordinates = u'My bed coordinates'
self.student['accommodation'].addBedTicket(bedticket)
def test_next_session_allowed(self):
# Let's see if next_session_allowed works as expected
# A, ug_ft, 100
IWorkflowState(self.student).setState('returning')
self.assertTrue(self.student['studycourse'].next_session_allowed)
# Uniben special PG programmes have the same workflow
# as UG students
self.certificate.study_mode = 'special_pg_pt'
self.assertTrue(self.student['studycourse'].next_session_allowed)
IWorkflowState(self.student).setState('school fee paid')
self.assertFalse(self.student['studycourse'].next_session_allowed)
# Now we convert the certificate into a 'regular
# postgraduate certificate ...
self.certificate.study_mode = 'pg_ft'
# ... and voila next session registration is allowed
self.assertTrue(self.student['studycourse'].next_session_allowed)
def test_manage_access(self):
self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
# The student created in the base package is a ug student
self.browser.open(self.manage_clearance_path)
self.assertMatches('...First Sitting Record...',
self.browser.contents)
# There is no pg field in the clearance form
self.assertFalse('Second Higher Education Record'
in self.browser.contents)
# Now we change the study mode ...
self.certificate.study_mode = 'pg_ft'
self.browser.open(self.clearance_path)
# ... and additional pg clearance fields appears
self.assertMatches('...Second Higher Education Record...',
self.browser.contents)
# But also fields from the ug form are displayed
self.assertMatches('...First Sitting Record...',
self.browser.contents)
# The same holds for Uniben's special pg students
self.certificate.study_mode = 'special_pg_pt'
self.browser.open(self.clearance_path)
self.assertMatches('...Second Higher Education Record...',
self.browser.contents)
self.assertMatches('...First Sitting Record...',
self.browser.contents)
self.browser.open(self.student_path + '/clearance_slip.pdf')
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.assertEqual(self.browser.headers['Content-Type'],
'application/pdf')
def test_student_access(self):
# Students can edit clearance data
IWorkflowState(self.student).setState('clearance started')
self.student.clearance_locked = False
self.student.nationality = u'NG'
file_store = getUtility(IExtFileStore)
self.browser.open(self.login_path)
self.browser.getControl(name="form.login").value = self.student_id
self.browser.getControl(name="form.password").value = 'spwd'
self.browser.getControl("Login").click()
self.browser.open(self.edit_clearance_path)
# Clearance can only be requested if all required documents
# have been uploaded.
self.browser.getControl("Save and request clearance").click()
self.assertTrue('No birth certificate uploaded'
in self.browser.contents)
birth_certificate = 'My birth certificate'
file_id = IFileStoreNameChooser(self.student).chooseName(
attr="birth_certificate.jpg")
file_store.createFile(file_id, StringIO(birth_certificate))
self.browser.open(self.edit_clearance_path)
self.browser.getControl("Save and request clearance").click()
self.assertTrue('No guarantor/referee letter uploaded'
in self.browser.contents)
ref_let = 'My ref let'
file_id = IFileStoreNameChooser(self.student).chooseName(
attr="ref_let.jpg")
file_store.createFile(file_id, StringIO(ref_let))
self.browser.open(self.edit_clearance_path)
self.browser.getControl("Save and request clearance").click()
self.assertTrue('No acceptance letter uploaded'
in self.browser.contents)
acc_let = 'My acc let'
file_id = IFileStoreNameChooser(self.student).chooseName(
attr="acc_let.jpg")
file_store.createFile(file_id, StringIO(acc_let))
self.browser.open(self.edit_clearance_path)
self.browser.getControl("Save and request clearance").click()
self.assertTrue('No first sitting result uploaded'
in self.browser.contents)
fst_sit_scan = 'My first sitting result'
file_id = IFileStoreNameChooser(self.student).chooseName(
attr="fst_sit_scan.jpg")
file_store.createFile(file_id, StringIO(fst_sit_scan))
self.browser.open(self.edit_clearance_path)
self.browser.getControl("Save and request clearance").click()
#self.assertTrue('No second sitting result uploaded'
# in self.browser.contents)
#scd_sit_scan = 'My second sitting result'
#file_id = IFileStoreNameChooser(self.student).chooseName(
# attr="scd_sit_scan.jpg")
#file_store.createFile(file_id, StringIO(scd_sit_scan))
#self.browser.open(self.edit_clearance_path)
#self.browser.getControl("Save and request clearance").click()
self.assertTrue('No affidavit of non-membership of secret cults uploaded'
in self.browser.contents)
secr_cults = 'My non-membership scan'
file_id = IFileStoreNameChooser(self.student).chooseName(
attr="secr_cults.jpg")
file_store.createFile(file_id, StringIO(secr_cults))
self.browser.open(self.edit_clearance_path)
self.browser.getControl("Save and request clearance").click()
self.assertTrue('Clearance has been requested'
in self.browser.contents)
def test_manage_payments(self):
# Add missing configuration data
self.app['configuration']['2004'].gown_fee = 150.0
self.app['configuration']['2004'].transfer_fee = 90.0
#self.app['configuration']['2004'].clearance_fee = 120.0
self.app['configuration']['2004'].booking_fee = 150.0
self.app['configuration']['2004'].maint_fee = 180.0
# Managers can add online payment tickets
self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
self.browser.open(self.payments_path)
self.browser.getLink("Add current session payment ticket").click()
self.browser.getControl("Create ticket").click()
self.assertMatches('...Amount could not be determined...',
self.browser.contents)
IWorkflowState(self.student).setState('cleared')
self.student.nationality = u'NG'
self.browser.open(self.payments_path + '/addop')
self.browser.getControl(name="form.p_category").value = ['schoolfee']
self.browser.getControl("Create ticket").click()
self.assertMatches('...ticket created...',
self.browser.contents)
ctrl = self.browser.getControl(name='val_id')
value = ctrl.options[0]
self.browser.getLink(value).click()
self.assertMatches('...Amount Authorized...',
self.browser.contents)
# Managers can open payment slip
self.browser.getLink("Download payment slip").click()
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
# Set ticket paid
ticket = self.student['payments'].items()[0][1]
ticket.p_state = 'paid'
self.browser.open(self.payments_path + '/addop')
self.browser.getControl(name="form.p_category").value = ['schoolfee']
self.browser.getControl("Create ticket").click()
self.assertMatches('...This type of payment has already been made...',
self.browser.contents)
# Remove all payments so that we can add a school fee payment again
keys = [i for i in self.student['payments'].keys()]
for payment in keys:
del self.student['payments'][payment]
self.browser.open(self.payments_path + '/addop')
self.browser.getControl(name="form.p_category").value = ['schoolfee']
self.browser.getControl("Create ticket").click()
self.assertMatches('...ticket created...',
self.browser.contents)
schoolfee_ticket = self.student['payments'].values()[0]
self.browser.open(self.payments_path + '/addop')
self.browser.getControl(name="form.p_category").value = ['gown']
self.browser.getControl("Create ticket").click()
self.assertMatches('...ticket created...',
self.browser.contents)
self.browser.open(self.payments_path + '/addop')
self.browser.getControl(
name="form.p_category").value = ['tempmaint_1']
self.browser.getControl("Create ticket").click()
self.assertMatches('...ticket created...',
self.browser.contents)
self.browser.open(self.payments_path + '/addop')
self.browser.getControl(
name="form.p_category").value = ['tempmaint_2']
self.browser.getControl("Create ticket").click()
self.assertMatches('...ticket created...',
self.browser.contents)
self.browser.open(self.payments_path + '/addop')
self.browser.getControl(
name="form.p_category").value = ['tempmaint_3']
self.browser.getControl("Create ticket").click()
self.assertMatches('...ticket created...',
self.browser.contents)
self.browser.open(self.payments_path + '/addop')
# We can't test clearance payment ticket creation at the moment,
# since Uniben decided to deactivate clearance for ug students.
#self.browser.getControl(name="form.p_category").value = ['clearance']
#self.browser.getControl("Create ticket").click()
#self.assertMatches('...ticket created...',
# self.browser.contents)
self.browser.open(self.payments_path + '/addop')
self.browser.getControl(name="form.p_category").value = ['schoolfee']
self.browser.getControl("Create ticket").click()
self.assertMatches('...ticket created...',
self.browser.contents)
# In state returning we can add a new school fee ticket since
# p_session and p_level is different
IWorkflowState(self.student).setState('returning')
self.browser.open(self.payments_path + '/addop')
self.browser.getControl(name="form.p_category").value = ['schoolfee']
self.browser.getControl("Create ticket").click()
# Uups, we forgot to add a session configuration for next session
self.assertMatches('...Session configuration object is not...',
self.browser.contents)
configuration = createObject('waeup.SessionConfiguration')
configuration.academic_session = 2005
self.app['configuration'].addSessionConfiguration(configuration)
self.browser.open(self.payments_path + '/addop')
self.browser.getControl(name="form.p_category").value = ['schoolfee']
self.browser.getControl("Create ticket").click()
#self.assertMatches('...You have not yet paid your current/active session...',
# self.browser.contents)
## Ok, let's pay the first schoolfee ticket.
#schoolfee_ticket.approve()
#self.browser.open(self.payments_path + '/addop')
#self.browser.getControl(name="form.p_category").value = ['schoolfee']
#self.browser.getControl("Create ticket").click()
self.assertMatches('...ticket created...',
self.browser.contents)
# In state admitted school fee can't be determined
IWorkflowState(self.student).setState('admitted')
self.browser.open(self.payments_path + '/addop')
self.browser.getControl(name="form.p_category").value = ['schoolfee']
self.browser.getControl("Create ticket").click()
self.assertMatches('...Amount could not be determined...',
self.browser.contents)
# If the session configuration doesn't exist an error message will
# be shown. No other requirement is being checked.
del self.app['configuration']['2004']
self.browser.open(self.payments_path)
self.browser.getLink("Add current session payment ticket").click()
self.browser.getControl("Create ticket").click()
self.assertMatches('...Session configuration object is not...',
self.browser.contents)
def test_student_course_registration(self):
# Uniben students see grade instead of score on all level pages
# and on course ticket page.
IWorkflowState(self.student).setState('school fee paid')
self.browser.open(self.login_path)
self.browser.getControl(name="form.login").value = self.student_id
self.browser.getControl(name="form.password").value = 'spwd'
self.browser.getControl("Login").click()
# Now students can add the current study level
self.browser.getLink("Study Course").click()
self.browser.getLink("Add course list").click()
self.assertMatches('...Add current level 100 (Year 1)...',
self.browser.contents)
self.browser.getControl("Create course list now").click()
# A level with one course ticket was created
self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 1)
self.student['studycourse']['100']['COURSE1'].score = 55
self.browser.getLink("100").click()
# GPA has been properly calculated
self.assertEqual(self.student['studycourse']['100'].gpa_params[0], 3.0)
# Score is not shown but grade
self.assertTrue('
Grade | ' in self.browser.contents)
self.assertFalse('Score | ' in self.browser.contents)
self.browser.getLink("Edit course list").click()
self.assertTrue('Grade | ' in self.browser.contents)
self.assertFalse('Score | ' in self.browser.contents)
self.browser.getLink("COURSE1").click()
self.assertFalse('Score' in self.browser.contents)
# Students can open the customized pdf course registration slip
self.browser.open(self.student_path + '/studycourse/100')
self.browser.getLink("Download course registration slip").click()
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
# Students can open the special Uniben pdf course result slip
self.browser.open(self.student_path + '/studycourse/100')
self.browser.getLink("Download course result slip").click()
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
# Even if course is mandatory, students can remove the course
self.student['studycourse']['100']['COURSE1'].mandatory = True
self.browser.open(self.student_path + '/studycourse/100')
self.browser.getLink("Edit course list").click()
ctrl = self.browser.getControl(name='val_id')
ctrl.getControl(value='COURSE1').selected = True
self.browser.getControl("Remove selected", index=0).click()
self.assertTrue('Successfully removed' in self.browser.contents)
def test_get_returning_data(self):
# Student is in level 100, session 2004 with verdict A
utils = getUtility(IStudentsUtils)
self.assertEqual(utils.getReturningData(self.student),(2005, 200))
self.student['studycourse'].current_verdict = 'C'
self.assertEqual(utils.getReturningData(self.student),(2005, 110))
self.student['studycourse'].current_verdict = 'D'
self.assertEqual(utils.getReturningData(self.student),(2005, 100))
return
def test_set_returning_data(self):
# Student is in level 100, session 2004 with verdict A
utils = getUtility(IStudentsUtils)
utils.setReturningData(self.student)
self.assertEqual(self.student['studycourse'].current_session, 2005)
self.assertEqual(self.student['studycourse'].current_level, 200)
self.student['studycourse'].current_session = 2004
self.student['studycourse'].current_level = 100
self.student['studycourse'].current_verdict = 'C'
utils.setReturningData(self.student)
self.assertEqual(self.student['studycourse'].current_session, 2005)
self.assertEqual(self.student['studycourse'].current_level, 110)
self.student['studycourse'].current_session = 2004
self.student['studycourse'].current_level = 100
self.student['studycourse'].current_verdict = 'D'
utils.setReturningData(self.student)
self.assertEqual(self.student['studycourse'].current_session, 2005)
self.assertEqual(self.student['studycourse'].current_level, 100)
return
def test_set_payment_details(self):
self.app['configuration']['2004'].gown_fee = 150.0
self.app['configuration']['2004'].transfer_fee = 90.0
self.app['configuration']['2004'].booking_fee = 150.0
self.app['configuration']['2004'].maint_fee = 180.0
configuration = createObject('waeup.SessionConfiguration')
configuration.academic_session = 2000
self.app['configuration'].addSessionConfiguration(configuration)
configuration2 = createObject('waeup.SessionConfiguration')
configuration2.academic_session = 2002
self.app['configuration'].addSessionConfiguration(configuration2)
configuration3 = createObject('waeup.SessionConfiguration')
configuration3.academic_session = 2003
self.app['configuration'].addSessionConfiguration(configuration3)
configuration4 = createObject('waeup.SessionConfiguration')
configuration4.academic_session = 2005
self.app['configuration'].addSessionConfiguration(configuration4)
utils = getUtility(IStudentsUtils)
self.student['studycourse'].entry_session = 2002
self.student.nationality = u'NG'
error, payment = utils.setPaymentDetails('schoolfee',
self.student, None, None)
self.assertEqual(payment, None)
# Student is in state 'created' and can thus not pay.
self.assertTrue(u'Amount could not be determined.' in error)
# Previous session must be valid.
error, payment = utils.setPaymentDetails('schoolfee',
self.student, 2000, 300)
self.assertEqual(payment, None)
self.assertTrue(u'The previous session must not fall below' in error)
error, payment = utils.setPaymentDetails('schoolfee',
self.student, 2005, 300)
self.assertEqual(payment, None)
self.assertTrue(u'This is not a previous session' in error)
# Previous session schoolfee payment; fresh and returning
# are distinguished by their entry_level
error, payment = utils.setPaymentDetails('schoolfee',
self.student, 2002, 300)
self.assertEqual(payment.amount_auth, 40000.0)
self.assertEqual(payment.p_session, 2002)
self.assertEqual(payment.p_level, 300)
self.assertFalse(payment.p_current)
error, payment = utils.setPaymentDetails('schoolfee',
self.student, 2003, 300)
self.assertEqual(payment.amount_auth, 20000.0)
self.assertEqual(payment.p_session, 2003)
self.assertEqual(payment.p_level, 300)
self.assertFalse(payment.p_current)
# Current schoolfee payment; fresh and returning
# are distinguished by their state
IWorkflowState(self.student).setState('cleared')
error, payment = utils.setPaymentDetails('schoolfee',
self.student, None, None)
self.assertEqual(payment.p_level, 100)
self.assertEqual(payment.p_session, 2004)
self.assertEqual(payment.amount_auth, 40000.0)
self.assertEqual(payment.p_item, u'CERT1')
self.assertEqual(error, None)
self.assertTrue(payment.p_current)
# Add penalty fee ...
# ... for cleared
self.app['configuration']['2004'].penalty_ug = 99.0
# ... for returning
self.app['configuration']['2005'].penalty_ug = 88.0
error, payment = utils.setPaymentDetails('schoolfee',
self.student, None, None)
self.assertEqual(payment.amount_auth, 40099.0)
IWorkflowState(self.student).setState('returning')
#error, payment = utils.setPaymentDetails('schoolfee',
# self.student, None, None)
#self.assertTrue(
# u'You have not yet paid your current/active session.' in error)
## Ok, that means we have to add paid payment ticket first.
#payment = createObject('waeup.StudentOnlinePayment')
#payment.p_category = u'schoolfee'
#payment.p_session = self.student.current_session
#payment.p_item = u'My Certificate'
#payment.p_id = u'anyid'
#payment.p_state = u'paid'
#self.student['payments']['anykey'] = payment
error, payment = utils.setPaymentDetails('schoolfee',
self.student, None, None)
self.assertEqual(payment.p_level, 200)
self.assertEqual(payment.p_session, 2005)
self.assertEqual(payment.amount_auth, 20088.0)
self.assertEqual(payment.p_item, u'CERT1')
self.assertEqual(error, None)
# Staff members pay less.
self.student.is_staff = True
error, payment = utils.setPaymentDetails('schoolfee',
self.student, None, None)
self.assertEqual(payment.p_level, 200)
self.assertEqual(payment.p_session, 2005)
self.assertEqual(payment.amount_auth, 10088.0)
self.assertEqual(payment.p_item, u'CERT1')
self.assertEqual(error, None)
# Foreigners pay more.
IWorkflowState(self.student).setState('cleared')
self.student.is_staff = False
self.student.nationality = u'DE'
self.certificate.school_fee_3 = 60000.0
error, payment = utils.setPaymentDetails(
'schoolfee', self.student, None, None)
self.assertEqual(payment.p_level, 100)
self.assertEqual(payment.p_session, 2004)
self.assertEqual(payment.amount_auth, 60099.0)
self.assertEqual(payment.p_item, u'CERT1')
self.assertEqual(error, None)
IWorkflowState(self.student).setState('returning')
self.student.is_staff = False
self.certificate.school_fee_4 = 20000.0
error, payment = utils.setPaymentDetails(
'schoolfee', self.student, None, None)
self.assertEqual(payment.p_level, 200)
self.assertEqual(payment.p_session, 2005)
self.assertEqual(payment.amount_auth, 20088.0)
self.assertEqual(payment.p_item, u'CERT1')
self.assertEqual(error, None)
# In Uniben students can pay school fee in all states no matter
# if they are ug or pg students.
IWorkflowState(self.student).setState('school fee paid')
self.student.is_staff = False
self.student.nationality = u'NG'
self.certificate.school_fee_2 = 10000.0
error, payment = utils.setPaymentDetails(
'schoolfee', self.student, None, None)
self.assertEqual(payment.p_level, None)
self.assertEqual(payment.p_session, 2005)
self.assertEqual(payment.amount_auth, 10088.0)
self.assertEqual(payment.p_item, u'CERT1')
self.assertEqual(error, None)
IWorkflowState(self.student).setState('courses registered')
self.certificate.study_mode = 'special_pg_pt'
error, payment = utils.setPaymentDetails(
'schoolfee', self.student, None, None)
self.assertEqual(payment.p_level, None)
self.assertEqual(payment.p_session, 2005)
self.assertEqual(payment.amount_auth, 10000.0)
self.assertEqual(payment.p_item, u'CERT1')
self.assertEqual(error, None)
IWorkflowState(self.student).setState('courses validated')
error, payment = utils.setPaymentDetails(
'schoolfee', self.student, None, None)
self.assertEqual(payment.p_level, None)
self.assertEqual(payment.p_session, 2005)
self.assertEqual(payment.amount_auth, 10000.0)
self.assertEqual(payment.p_item, u'CERT1')
self.assertEqual(error, None)
error, payment = utils.setPaymentDetails('clearance',
self.student, None, None)
self.assertEqual(payment.p_level, 100)
self.assertEqual(payment.p_session, 2004)
self.assertEqual(payment.amount_auth, 45000.0)
self.assertEqual(payment.p_item, u'CERT1')
self.assertEqual(error, None)
error, payment = utils.setPaymentDetails('gown',
self.student, None, None)
self.assertEqual(payment.p_level, 100)
self.assertEqual(payment.p_session, 2004)
self.assertEqual(payment.amount_auth, 150.0)
self.assertEqual(payment.p_item, u'')
self.assertEqual(error, None)
error, payment = utils.setPaymentDetails('hostel_maintenance',
self.student, None, None)
self.assertEqual(payment.p_level, 100)
self.assertEqual(payment.p_session, 2004)
self.assertEqual(payment.amount_auth, 180.0)
self.assertEqual(payment.p_item, u'')
self.assertEqual(error, None)
error, payment = utils.setPaymentDetails('bed_allocation',
self.student, None, None)
self.assertEqual(payment.p_level, 100)
self.assertEqual(payment.p_session, 2004)
self.assertEqual(payment.amount_auth, 150.0)
self.assertEqual(payment.p_item, u'')
self.assertEqual(error, None)
error, payment = utils.setPaymentDetails('tempmaint_1',
self.student, None, None)
self.assertEqual(payment.p_level, 100)
self.assertEqual(payment.p_session, 2004)
self.assertEqual(payment.amount_auth, 8150.0)
self.assertEqual(payment.p_item, u'Hall 1-4 M/F Ekehuan')
self.assertEqual(error, None)
error, payment = utils.setPaymentDetails('tempmaint_2',
self.student, None, None)
self.assertEqual(payment.p_level, 100)
self.assertEqual(payment.p_session, 2004)
self.assertEqual(payment.amount_auth, 12650.0)
self.assertEqual(payment.p_item, u'Hall 5 M/F')
self.assertEqual(error, None)
error, payment = utils.setPaymentDetails('tempmaint_3',
self.student, None, None)
self.assertEqual(payment.p_level, 100)
self.assertEqual(payment.p_session, 2004)
self.assertEqual(payment.amount_auth, 9650.0)
self.assertEqual(payment.p_item, u'Clinical Hostel')
self.assertEqual(error, None)
error, payment = utils.setPaymentDetails('transfer',
self.student, None, None)
self.assertEqual(payment.p_level, 100)
self.assertEqual(payment.p_session, 2004)
self.assertEqual(payment.amount_auth, 90.0)
self.assertEqual(payment.p_item, u'')
self.assertEqual(error, None)
return
def test_edit_level_by_co(self):
# Create clearance officer
self.app['users'].addUser('mrclear', 'mrclearsecret')
self.app['users']['mrclear'].email = 'mrclear@foo.ng'
self.app['users']['mrclear'].title = 'Carlo Pitter'
# Assign local ClearanceOfficer role
department = self.app['faculties']['fac1']['dep1']
prmlocal = IPrincipalRoleManager(department)
prmlocal.assignRoleToPrincipal('waeup.local.ClearanceOfficer', 'mrclear')
notify(LocalRoleSetEvent(
department, 'waeup.local.ClearanceOfficer', 'mrclear', granted=True))
IWorkflowState(self.student).setState('clearance started')
# Login as clearance officer
self.browser.open(self.login_path)
self.browser.getControl(name="form.login").value = 'mrclear'
self.browser.getControl(name="form.password").value = 'mrclearsecret'
self.browser.getControl("Login").click()
self.assertMatches('...You logged in...', self.browser.contents)
# Only in state clearance requested the CO does see the
# 'Edit level' button ...
self.browser.open(self.studycourse_path)
self.assertFalse('Edit level' in self.browser.contents)
# ... and can open the edit_level view
self.browser.open(self.studycourse_path + '/edit_level')
self.assertMatches('...is locked...', self.browser.contents)
self.assertEqual(self.browser.url, self.studycourse_path)
IWorkflowInfo(self.student).fireTransition('request_clearance')
self.browser.open(self.studycourse_path)
self.assertTrue('Edit level' in self.browser.contents)
self.browser.getLink("Edit level").click()
self.browser.getControl(name="form.current_level").value = ['200']
self.browser.getControl("Save").click()
self.assertMatches('...has been saved...', self.browser.contents)
self.assertEqual(self.student.current_level, 200)
def test_postgraduate_student_access(self):
self.certificate.study_mode = 'special_pg_pt'
self.certificate.start_level = 700
self.certificate.end_level = 800
self.student['studycourse'].current_level = 700
IWorkflowState(self.student).setState('school fee paid')
self.browser.open(self.login_path)
self.browser.getControl(name="form.login").value = self.student_id
self.browser.getControl(name="form.password").value = 'spwd'
self.browser.getControl("Login").click()
self.assertTrue(
'You logged in.' in self.browser.contents)
# Now students can add the current study level
self.browser.getLink("Study Course").click()
self.browser.getLink("Add course list").click()
self.assertMatches('...Add current level 700...',
self.browser.contents)
self.browser.getControl("Create course list now").click()
# A level with no course ticket was created
self.assertEqual(self.student['studycourse']['700'].number_of_tickets, 0)
self.browser.getLink("700").click()
self.browser.getLink("Edit course list").click()
self.browser.getLink("here").click()
self.browser.getControl(name="form.course").value = ['COURSE1']
# Non-final year students can't add ticket with 51 credits
self.app['faculties']['fac1']['dep1'].courses['COURSE1'].credits = 51
self.browser.getControl("Add course ticket").click()
self.assertMatches('...Total credits exceed 50...',
self.browser.contents)
# Final year students can't add ticket with 52 credits ...
self.app['faculties']['fac1']['dep1'].courses['COURSE1'].credits = 52
self.student['studycourse'].certificate.end_level = 700
self.browser.getControl("Add course ticket").click()
self.assertMatches('...Total credits exceed 51...',
self.browser.contents)
# ... but with 51 credits
self.app['faculties']['fac1']['dep1'].courses['COURSE1'].credits = 51
self.browser.getControl("Add course ticket").click()
self.assertMatches('...Successfully added COURSE1...',
self.browser.contents)
# Non-final year special postgraduate students can't register
# course lists if their total credits are 51 and thus exceed 50 ...
self.student['studycourse'].certificate.end_level = 800
self.browser.getControl("Register course list").click()
self.assertMatches('...Maximum credits of 50 exceeded...',
self.browser.contents)
# ... but final year students can
self.student['studycourse'].certificate.end_level = 700
self.browser.getControl("Register course list").click()
self.assertMatches('...Course list has been registered...',
self.browser.contents)
self.assertEqual(self.student.state, 'courses registered')
return
def test_login(self):
# If suspended_comment is set this message will be flashed instead
self.student.suspended_comment = u'Aetsch baetsch!'
self.student.suspended = True
self.browser.open(self.login_path)
self.browser.getControl(name="form.login").value = self.student_id
self.browser.getControl(name="form.password").value = 'spwd'
self.browser.getControl("Login").click()
# Uniben does not display suspended_comment
self.assertMatches(
'...Your account has been deactivated.
...',
self.browser.contents)
self.student.suspended = False
def test_activate_deactivate_buttons(self):
self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
self.browser.open(self.student_path)
self.browser.getLink("Deactivate").click()
self.assertTrue(
'Student account has been deactivated.' in self.browser.contents)
self.assertTrue(
'Base Data (account deactivated)' in self.browser.contents)
self.assertTrue(self.student.suspended)
self.browser.getLink("Activate").click()
self.assertTrue(
'Student account has been activated.' in self.browser.contents)
self.assertFalse(
'Base Data (account deactivated)' in self.browser.contents)
self.assertFalse(self.student.suspended)
# History messages have been added ...
self.browser.getLink("History").click()
# User is undisclosed
self.assertTrue(
'Student account deactivated
' in self.browser.contents)
self.assertTrue(
'Student account activated
' in self.browser.contents)
# ... and actions have been logged.
logfile = os.path.join(
self.app['datacenter'].storage, 'logs', 'students.log')
logcontent = open(logfile).read()
self.assertTrue('zope.mgr - waeup.uniben.students.browser.CustomStudentDeactivatePage - '
'B1000000 - account deactivated' in logcontent)
self.assertTrue('zope.mgr - waeup.uniben.students.browser.CustomStudentActivatePage - '
'B1000000 - account activated' in logcontent)