# -*- coding: utf-8 -*-
## $Id: test_browser.py 17659 2023-12-22 16:47:45Z henrik $
##
## Copyright (C) 2013 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
##
"""
Test the applicant-related UI components.
"""
import os
import datetime
import pytz
from StringIO import StringIO
from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
from zope.securitypolicy.interfaces import IPrincipalRoleManager
from zope.component import createObject, getUtility
from waeup.kofa.interfaces import IUserAccount
from waeup.kofa.browser.tests.test_pdf import samples_dir
from waeup.kofa.applicants.container import ApplicantsContainer
from waeup.uniben.testing import FunctionalLayer
from waeup.uniben.configuration import CustomSessionConfiguration
from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup, PH_LEN
session_1 = datetime.datetime.now().year - 2
SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg')
class CustomApplicantUITests(ApplicantsFullSetup):
# Tests for uploading/browsing the passport image of appplicants
layer = FunctionalLayer
#def setUp(self):
# super(CustomApplicantUITests, self).setUp()
# return
def test_applicant_access(self):
# Anonymous users can't see the application fee.
self.browser.open(self.container_path)
self.assertFalse('Application Fee' in self.browser.contents)
# Applicants can edit their record
self.browser.open(self.login_path)
self.login()
self.assertTrue(
'You logged in as an applicant.' in self.browser.contents)
self.browser.open(self.edit_path)
self.assertTrue(self.browser.url != self.login_path)
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.fill_correct_values()
self.browser.getControl("Save").click()
self.assertMatches('...Form has been saved...', self.browser.contents)
# Applicants can't see the application fee.
self.browser.open(self.container_path)
self.assertFalse('Application Fee' in self.browser.contents)
return
def image_url(self, filename):
return self.edit_path.replace('edit', filename)
def test_upload_passport_wo_permission(self):
# Create CRPU officer
self.app['users'].addUser('mrcrpu', 'mrCrpusecret1')
self.app['users']['mrcrpu'].email = 'mrcrpu@foo.ng'
self.app['users']['mrcrpu'].title = 'Carlo Pitter'
prmglobal = IPrincipalRoleManager(self.app)
prmglobal.assignRoleToPrincipal('waeup.CCOfficer', 'mrcrpu')
# Login as CRPU officer
self.browser.open(self.login_path)
self.browser.getControl(name="form.login").value = 'mrcrpu'
self.browser.getControl(name="form.password").value = 'mrCrpusecret1'
self.browser.getControl("Login").click()
self.assertMatches('...You logged in...', self.browser.contents)
# Let's try to change the passport image
self.browser.open(self.manage_path)
self.fill_correct_values()
# Create a pseudo image file and select it to be uploaded in form
pseudo_image = StringIO('I pretend to be a graphics file')
ctrl = self.browser.getControl(name='form.passport')
file_ctrl = ctrl.mech_control
file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
self.browser.getControl("Save").click()
self.assertMatches('...You are not entitled to upload passport pictures...',
self.browser.contents)
# The officer still sees the placeholder passport image
self.browser.open(self.image_url('passport.jpg'))
self.assertEqual(
self.browser.headers['content-type'], 'image/jpeg')
self.assertEqual(len(self.browser.contents), PH_LEN)
# After adding the additional role ...
prmglobal.assignRoleToPrincipal('waeup.PassportPictureManager', 'mrcrpu')
# ... passport pictures can be uploaded
self.browser.open(self.manage_path)
self.fill_correct_values()
pseudo_image = StringIO('I pretend to be a graphics file')
ctrl = self.browser.getControl(name='form.passport')
file_ctrl = ctrl.mech_control
file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
self.browser.getControl("Save").click()
self.assertMatches('...Form has been saved...', self.browser.contents)
# There is a correct link included
self.assertTrue(
'' in self.browser.contents)
# Browsing the link shows a real image
self.browser.open(self.image_url('passport.jpg'))
self.assertEqual(
self.browser.headers['content-type'], 'image/jpeg')
self.assertEqual(len(self.browser.contents), 31)
def test_pay_admission_checking_fee(self):
IWorkflowState(self.applicant).setState('admitted')
self.applicant.screening_score = 55.0
self.applicant.course_admitted = self.certificate
self.login()
# SessionConfiguration is not set, thus admission checking payment
# is not necessary. Screening results and course admitted are visible.
self.assertFalse(
'Add admission checking payment ticket' in self.browser.contents)
self.assertTrue('CERT1 - Unnamed Certificate' in self.browser.contents)
self.assertTrue('55.0' in self.browser.contents)
configuration = CustomSessionConfiguration()
configuration.academic_session = datetime.datetime.now().year - 2
self.app['configuration'].addSessionConfiguration(configuration)
# Admission checking fee is 0, thus admission checking payment
# is not necessary. Screening results and course admitted are visible.
self.browser.open(self.view_path)
self.assertFalse(
'Add admission checking payment ticket' in self.browser.contents)
self.assertTrue('CERT1 - Unnamed Certificate' in self.browser.contents)
self.assertTrue('55.0' in self.browser.contents)
configuration.admchecking_fee = 22.0
# Admission checking payment button is now visible, but screening results
# and course admitted are not.
self.browser.open(self.view_path)
self.assertTrue(
'Add admission checking payment ticket' in self.browser.contents)
self.assertFalse('CERT1 - Unnamed Certificate' in self.browser.contents)
self.assertFalse('55.0' in self.browser.contents)
# Application slip can't be downloaded
self.assertFalse('Download application slip' in self.browser.contents)
slip_path = self.view_path + '/application_slip.pdf'
self.browser.open(slip_path)
self.assertTrue(
'Please pay admission checking fee before trying to download'
in self.browser.contents)
# Pay admission checking fee.
self.browser.getControl("Add admission checking").click()
p_id = self.applicant.keys()[0]
self.applicant[p_id].p_state = 'paid'
# Screening results and course admitted are visible after payment.
self.browser.open(self.view_path)
self.assertFalse(
'Add admission checking payment ticket' in self.browser.contents)
self.assertTrue('CERT1 - Unnamed Certificate' in self.browser.contents)
self.assertTrue('55.0' in self.browser.contents)
# Application slip can be downloaded again.
self.browser.getLink("Download application slip").click()
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.assertEqual(self.browser.headers['Content-Type'],
'application/pdf')
return
def test_application_slips(self):
self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
self.browser.open(self.manage_path)
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.fill_correct_values()
self.browser.getControl("Save").click()
IWorkflowState(self.applicant).setState('submitted')
self.browser.open(self.view_path)
self.browser.getLink("Download application slip").click()
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.assertEqual(self.browser.headers['Content-Type'],
'application/pdf')
path = os.path.join(samples_dir(), 'application_slip.pdf')
open(path, 'wb').write(self.browser.contents)
print "Sample application_slip.pdf written to %s" % path
# Screening invitation letter is not yet available
self.browser.open(self.view_path)
self.assertFalse('invitation slip' in self.browser.contents)
self.browser.open(self.view_path + '/screening_invitation_slip.pdf')
self.assertTrue('Forbidden' in self.browser.contents)
self.applicant.screening_date = u'any date'
self.applicant.screening_venue = u'MAIN AUDITORIUM'
self.applicantscontainer.application_slip_notice = u'This is an additional notice.'
# The invitation letter can be printed
self.browser.open(self.view_path)
self.browser.getLink("invitation").click()
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.assertEqual(self.browser.headers['Content-Type'],
'application/pdf')
path = os.path.join(samples_dir(), 'screening_invitation_slip.pdf')
open(path, 'wb').write(self.browser.contents)
print "Sample screening_invitation_slip.pdf written to %s" % path
def test_akoka_application_slip(self):
# Remove required FieldProperty attribute first ...
delattr(ApplicantsContainer, 'prefix')
# ... and replace by akoka
self.applicantscontainer.prefix = 'akj'
self.applicantscontainer.title = u'FCET Akoka JUPEB Pre-Degree (Foundation) Studies 2016/2017'
self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
self.slip_path = self.view_path + '/application_slip.pdf'
self.browser.open(self.manage_path)
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.fill_correct_values()
self.browser.getControl("Save").click()
IWorkflowState(self.applicant).setState('submitted')
self.browser.open(self.view_path)
self.browser.getLink("Download application slip").click()
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.assertEqual(self.browser.headers['Content-Type'],
'application/pdf')
path = os.path.join(samples_dir(), 'akoka_application_slip.pdf')
open(path, 'wb').write(self.browser.contents)
print "Sample akoka_application_slip.pdf written to %s" % path
def test_nils_application_slip(self):
# Remove required FieldProperty attribute first ...
#delattr(ApplicantsContainer, 'prefix')
# ... and replace by akoka
self.applicantscontainer.prefix = 'pgn'
self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
self.slip_path = self.view_path + '/application_slip.pdf'
self.browser.open(self.manage_path)
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.fill_correct_values()
self.browser.getControl("Save").click()
IWorkflowState(self.applicant).setState('submitted')
self.browser.open(self.view_path)
self.browser.getLink("Download application slip").click()
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.assertEqual(self.browser.headers['Content-Type'],
'application/pdf')
path = os.path.join(samples_dir(), 'nils_application_slip.pdf')
open(path, 'wb').write(self.browser.contents)
print "Sample nils_application_slip.pdf written to %s" % path
def test_ictwk_application(self):
# Remove required FieldProperty attribute first ...
#delattr(ApplicantsContainer, 'prefix')
# ... and replace by ictw
self.applicantscontainer.prefix = 'ictwk'
self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
self.slip_path = self.view_path + '/application_slip.pdf'
self.browser.open(self.manage_path)
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.browser.getControl(name="form.firstname").value = 'John'
self.browser.getControl(name="form.middlename").value = 'Anthony'
self.browser.getControl(name="form.lastname").value = 'Tester'
#self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
self.browser.getControl(name="form.sex").value = ['m']
self.browser.getControl(name="form.email").value = 'xx@yy.zz'
image = open(SAMPLE_IMAGE, 'rb')
ctrl = self.browser.getControl(name='form.passport')
file_ctrl = ctrl.mech_control
file_ctrl.add_file(image, filename='myphoto.jpg')
self.browser.getControl("Save").click()
self.applicant.registration_cats = ['group', 'corporate']
IWorkflowState(self.applicant).setState('started')
configuration = CustomSessionConfiguration()
configuration.academic_session = session_1
configuration.application_fee = 0.0
self.app['configuration'].addSessionConfiguration(configuration)
self.browser.getControl("Create and make online").click()
self.assertMatches('...Payment ticket created...',
self.browser.contents)
self.assertEqual(self.applicant.values()[0].amount_auth, 450000)
IWorkflowState(self.applicant).setState('submitted')
self.browser.open(self.view_path)
self.assertTrue('Group Registration @ ₦ 200000' in self.browser.contents)
self.browser.open(self.view_path)
self.browser.getLink("Download application slip").click()
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.assertEqual(self.browser.headers['Content-Type'],
'application/pdf')
path = os.path.join(samples_dir(), 'ictwk_application_slip.pdf')
open(path, 'wb').write(self.browser.contents)
print "Sample ictwk_application_slip.pdf written to %s" % path
def test_transcript_application(self):
configuration = CustomSessionConfiguration()
configuration.academic_session = session_1
self.app['configuration'].addSessionConfiguration(configuration)
# Add special application container
applicantscontainer = ApplicantsContainer()
applicantscontainer.year = session_1
applicantscontainer.application_fee = 1.0 # Must be set but is not used.
applicantscontainer.code = u'tsc1234'
applicantscontainer.prefix = 'tscf'
applicantscontainer.title = u'This is a tsc container'
applicantscontainer.application_category = 'no'
applicantscontainer.mode = 'create'
applicantscontainer.strict_deadline = True
applicantscontainer.with_picture = True
delta = datetime.timedelta(days=10)
applicantscontainer.startdate = datetime.datetime.now(pytz.utc) - delta
applicantscontainer.enddate = datetime.datetime.now(pytz.utc) + delta
self.app['applicants']['tsc1234'] = applicantscontainer
# Add an applicant
applicant = createObject('waeup.Applicant')
# reg_number is the only field which has to be preset here
# because managers are allowed to edit this required field
applicant.reg_number = u'12345'
applicant.collected = True
self.app['applicants']['tsc1234'].addApplicant(applicant)
IUserAccount(
self.app['applicants']['tsc1234'][
applicant.application_number]).setPassword('apwd')
# Login
self.browser.open(self.login_path)
self.browser.getControl(
name="form.login").value = applicant.applicant_id
self.browser.getControl(name="form.password").value = 'apwd'
self.browser.getControl("Login").click()
self.browser.getLink("Application record").click()
self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
self.browser.getControl(name="form.email").value = 'xx@yy.zz'
self.browser.getControl(name="form.firstname").value = 'Angela'
self.browser.getControl(name="form.lastname").value = 'Merkel'
self.browser.getControl(name="form.sex").value = ['f']
self.browser.getControl(name="form.no_copies").value = ['2']
self.browser.getControl(name="form.course_studied").value = ['CERT1']
self.browser.getControl(name="form.matric_number").value = 'a234'
self.browser.getControl(name="form.dispatch_address").value = 'Kuensche\nMarsch 5'
self.browser.getControl(name="form.entry_mode").value = ['ug_ft']
self.browser.getControl(name="form.entry_session").value = ['2014']
self.browser.getControl(name="form.end_session").value = ['2015']
self.browser.getControl(name="form.phone.country").value = ['+234']
self.browser.getControl(name="form.phone.ext").value = '5678'
self.browser.getControl(name="form.charge").value = ['nigeria']
self.browser.getControl(name="form.order").value = ['o']
image = open(SAMPLE_IMAGE, 'rb')
ctrl = self.browser.getControl(name='form.passport')
file_ctrl = ctrl.mech_control
file_ctrl.add_file(image, filename='myphoto.jpg')
self.browser.getControl("Save").click()
applicant_url = self.browser.url
self.browser.getControl("Create and make online").click()
self.assertTrue('Payment ticket created' in self.browser.contents)
self.assertTrue('40000.0' in self.browser.contents)
self.assertEqual(applicant.values()[0].amount_auth, 40000.0)
applicant.values()[0].p_state = 'paid'
payment_url = self.browser.url
IWorkflowState(applicant).setState('submitted')
self.browser.open(payment_url)
self.browser.getLink("Download payment slip").click()
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.assertEqual(self.browser.headers['Content-Type'],
'application/pdf')
path = os.path.join(samples_dir(), 'tscf_payment_slip.pdf')
open(path, 'wb').write(self.browser.contents)
print "Sample tscf_payment_slip.pdf written to %s" % path
self.browser.open(applicant_url)
self.browser.getLink("My Data").click()
self.browser.getLink("Download application slip").click()
self.assertEqual(self.browser.headers['Status'], '200 Ok')
self.assertEqual(self.browser.headers['Content-Type'],
'application/pdf')
path = os.path.join(samples_dir(), 'tscf_application_slip.pdf')
open(path, 'wb').write(self.browser.contents)
print "Sample tscf_application_slip.pdf written to %s" % path
return