source: main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/students/tests/test_browser.py @ 17110

Last change on this file since 17110 was 16603, checked in by Henrik Bettermann, 3 years ago

Change admission letter ogf Pharmacy students.

Add JUPEB admission letter.

  • Property svn:keywords set to Id
File size: 13.5 KB
Line 
1## $Id: test_browser.py 16603 2021-09-04 11:09:01Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18import os
19import shutil
20import tempfile
21from time import time
22from datetime import datetime, timedelta
23from StringIO import StringIO
24from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo
25from zope.securitypolicy.interfaces import IPrincipalRoleManager
26from zope.component.hooks import setSite, clearSite
27from zope.component import getUtility, createObject
28from zope.interface import verify
29from zope.event import notify
30from waeup.kofa.authentication import LocalRoleSetEvent
31from waeup.kofa.app import University
32from waeup.kofa.university.faculty import Faculty
33from waeup.kofa.university.department import Department
34from waeup.kofa.students.tests.test_browser import StudentsFullSetup
35from waeup.kofa.students.accommodation import BedTicket
36from waeup.kofa.testing import FunctionalTestCase
37from waeup.kofa.browser.tests.test_pdf import samples_dir
38from waeup.kofa.interfaces import (
39    IExtFileStore, IFileStoreNameChooser)
40from waeup.kofa.students.interfaces import IStudentsUtils
41from waeup.kofa.tests.test_authentication import SECRET
42from kofacustom.iuokada.testing import FunctionalLayer
43
44
45class StudentsContainerUITests(StudentsFullSetup):
46    # Tests for StudentsContainer class views and pages
47
48    layer = FunctionalLayer
49
50    def test_dummytest(self):
51        return
52
53class OfficerUITests(StudentsFullSetup):
54    # Tests for Student class views and pages
55
56    layer = FunctionalLayer
57
58    def test_lib_idcard_officer(self):
59        # Create library officer
60        self.app['users'].addUser('mrlibrary', SECRET)
61        self.app['users']['mrlibrary'].email = 'library@foo.ng'
62        self.app['users']['mrlibrary'].title = 'Carlo Pitter'
63        prmglobal = IPrincipalRoleManager(self.app)
64        prmglobal.assignRoleToPrincipal(
65            'waeup.LibraryClearanceOfficer', 'mrlibrary')
66        prmglobal.assignRoleToPrincipal(
67            'waeup.StudentsOfficer', 'mrlibrary')
68        self.browser.open(self.login_path)
69        self.browser.getControl(name="form.login").value = 'mrlibrary'
70        self.browser.getControl(name="form.password").value = SECRET
71        self.browser.getControl("Login").click()
72        self.assertMatches('...You logged in...', self.browser.contents)
73        self.browser.open(self.student_path)
74        self.assertFalse('Download Library Id Card' in self.browser.contents)
75        self.browser.getLink("Switch library access").click()
76        self.assertTrue('Library access enabled' in self.browser.contents)
77        self.browser.getLink("Download Library Id Card").click()
78        self.assertEqual(self.browser.headers['Status'], '200 Ok')
79        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
80        path = os.path.join(samples_dir(), 'lib_idcard_officer.pdf')
81        open(path, 'wb').write(self.browser.contents)
82        print "Sample PDF lib_idcard_officer.pdf written to %s" % path
83
84class StudentUITests(StudentsFullSetup):
85    # Tests for Student class views and pages
86
87    layer = FunctionalLayer
88
89    def test_student_course_registration(self):
90        IWorkflowState(self.student).setState('school fee paid')
91        self.browser.open(self.login_path)
92        self.browser.getControl(name="form.login").value = self.student_id
93        self.browser.getControl(name="form.password").value = 'spwd'
94        self.browser.getControl("Login").click()
95        # Now students can add the current study level
96        self.browser.getLink("Study Course").click()
97        self.browser.getLink("Add course list").click()
98        self.assertMatches('...Add current level 100 (Year 1)...',
99                           self.browser.contents)
100        self.browser.getControl("Create course list now").click()
101        # Students can open the pdf course registration slip
102        self.browser.open(
103            self.student_path + '/studycourse/100/course_registration_slip.pdf')
104        self.assertEqual(self.browser.headers['Status'], '200 Ok')
105        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
106        path = os.path.join(samples_dir(), 'course_registration_slip.pdf')
107        open(path, 'wb').write(self.browser.contents)
108        print "Sample PDF course_registration_slip.pdf written to %s" % path
109
110    def test_library_idcard(self):
111        IWorkflowState(self.student).setState('returning')
112        self.browser.open(self.login_path)
113        self.browser.getControl(name="form.login").value = self.student_id
114        self.browser.getControl(name="form.password").value = 'spwd'
115        self.browser.getControl("Login").click()
116        self.assertFalse('Download Library' in self.browser.contents)
117        self.student.library = True
118        self.browser.open(self.student_path)
119        self.browser.getLink("Download Library Id Card").click()
120        self.assertEqual(self.browser.headers['Status'], '200 Ok')
121        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
122        path = os.path.join(samples_dir(), 'lib_idcard_student.pdf')
123        open(path, 'wb').write(self.browser.contents)
124        print "Sample PDF lib_idcard_student.pdf written to %s" % path
125        self.assertTrue(self.student.library)
126        IWorkflowInfo(self.student).fireTransition('pay_school_fee')
127        self.assertFalse(self.student.library)
128
129    def test_student_studycourse_slip(self):
130        IWorkflowState(self.student).setState('school fee paid')
131        self.browser.open(self.login_path)
132        self.browser.getControl(name="form.login").value = self.student_id
133        self.browser.getControl(name="form.password").value = 'spwd'
134        self.browser.getControl("Login").click()
135        # Students can open base data slip
136        # (no button available in base package)
137        pdf_url = '%s/studycourse_slip.pdf' % self.studycourse_path
138        self.browser.open(pdf_url)
139        self.assertEqual(self.browser.headers['Status'], '200 Ok')
140        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
141        path = os.path.join(samples_dir(), 'studycourse_slip.pdf')
142        open(path, 'wb').write(self.browser.contents)
143        print "Sample PDF studycourse_slip.pdf written to %s" % path
144
145    def test_student_personal_edit(self):
146        IWorkflowState(self.student).setState('school fee paid')
147        self.browser.open(self.login_path)
148        self.browser.getControl(name="form.login").value = self.student_id
149        self.browser.getControl(name="form.password").value = 'spwd'
150        self.browser.getControl("Login").click()
151        self.browser.getLink("Bio Data").click()
152        self.browser.getLink("Edit registration bio data").click()
153        self.assertTrue("Please make 40% of your tution fee payments first." in self.browser.contents)
154        self.assertEqual(self.browser.url, self.personal_path)
155
156    def test_student_personal_slip(self):
157        payment1 = createObject(u'waeup.StudentOnlinePayment')
158        timestamp = ("%d" % int(time()*10000))[1:]
159        payment1.p_id = "LSCNEW-2-4153206270" # the longest possible p_id
160        payment1.p_category = 'schoolfee'
161        payment1.p_item = u'My School Fee'
162        payment1.p_session = 2015
163        payment1.p_level = 100
164        payment1.p_current = True
165        payment1.amount_auth = 23456.9
166        payment1.approve()
167        payment2 = createObject(u'waeup.StudentOnlinePayment')
168        timestamp = ("%d" % int(time()*10000))[1:]
169        payment2.p_id = "p%s" % timestamp
170        payment2.p_category = 'clearance'
171        payment2.p_item = u'My Clearance Fee'
172        payment2.p_session = 2015
173        payment2.p_level = 100
174        payment2.p_current = True
175        payment2.amount_auth = 5678.6
176        payment2.approve()
177        self.student['payments'][payment1.p_id] = payment1
178        self.student['payments'][payment2.p_id] = payment2
179        IWorkflowState(self.student).setState('school fee paid')
180        self.browser.open(self.login_path)
181        self.browser.getControl(name="form.login").value = self.student_id
182        self.browser.getControl(name="form.password").value = 'spwd'
183        self.browser.getControl("Login").click()
184        # Students can open base data slip
185        # (no button available in base package)
186        pdf_url = '%s/course_registration_clearance.pdf' % self.student_path
187        self.browser.open(pdf_url)
188        self.assertEqual(self.browser.headers['Status'], '200 Ok')
189        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
190        path = os.path.join(samples_dir(), 'course_registration_clearance.pdf')
191        open(path, 'wb').write(self.browser.contents)
192        print "Sample PDF course_registration_clearance.pdf written to %s" % path
193
194    def test_student_admission_letters(self):
195        self.certificate.study_mode = 'ug_ft'
196        # Student cant login if their password is not set
197        IWorkflowInfo(self.student).fireTransition('admit')
198        self.browser.open(self.login_path)
199        self.browser.getControl(name="form.login").value = self.student_id
200        self.browser.getControl(name="form.password").value = 'spwd'
201        self.browser.getControl("Login").click()
202        self.assertMatches(
203            '...You logged in...', self.browser.contents)
204        # Admitted student can upload a passport picture
205        #self.browser.open(self.student_path + '/change_portrait')
206        #ctrl = self.browser.getControl(name='passportuploadedit')
207        #file_obj = open(SAMPLE_IMAGE, 'rb')
208        #file_ctrl = ctrl.mech_control
209        #file_ctrl.add_file(file_obj, filename='my_photo.jpg')
210        #self.browser.getControl(
211        #    name='upload_passportuploadedit').click()
212        #self.assertTrue(
213        #    'src="http://localhost/app/students/K1000000/passport.jpg"'
214        #    in self.browser.contents)
215        # Students can open admission letter
216        self.browser.getLink("Base Data").click()
217        self.browser.getLink("Download admission letter").click()
218        self.assertEqual(self.browser.headers['Status'], '200 Ok')
219        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
220        path = os.path.join(samples_dir(), 'ug_admission_slip.pdf')
221        open(path, 'wb').write(self.browser.contents)
222        print "Sample PDF UG admission_slip.pdf written to %s" % path
223        self.certificate.study_mode = 'pg_ft'
224        self.browser.open(self.student_path)
225        self.browser.getLink("Base Data").click()
226        self.browser.getLink("Download admission letter").click()
227        self.assertEqual(self.browser.headers['Status'], '200 Ok')
228        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
229        path = os.path.join(samples_dir(), 'pg_admission_slip.pdf')
230        open(path, 'wb').write(self.browser.contents)
231        print "Sample PDF PG admission_slip.pdf written to %s" % path
232        self.certificate.study_mode = 'ug_pt'
233        self.browser.open(self.student_path)
234        self.browser.getLink("Base Data").click()
235        self.browser.getLink("Download admission letter").click()
236        self.assertEqual(self.browser.headers['Status'], '200 Ok')
237        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
238        path = os.path.join(samples_dir(), 'pt_admission_slip.pdf')
239        open(path, 'wb').write(self.browser.contents)
240        print "Sample PDF PT admission_slip.pdf written to %s" % path
241
242        # JUPEB is bit more complicated to test.
243        # Populate university with JUPEB first.
244        self.certificate = createObject('waeup.Certificate')
245        self.certificate.code = u'CERT2'
246        self.certificate.application_category = 'basic'
247        self.certificate.study_mode = 'ug_ft'
248        self.certificate.start_level = 100
249        self.certificate.end_level = 500
250        self.certificate.school_fee_1 = 40000.0
251        self.certificate.school_fee_2 = 20000.0
252        self.app['faculties']['jupeb'] = Faculty(code=u'JUPEB')
253        self.app['faculties']['jupeb']['dep2'] = Department(code=u'dep2')
254        self.app['faculties']['jupeb']['dep2'].certificates.addCertificate(
255            self.certificate)
256        self.course = createObject('waeup.Course')
257        self.course.code = 'COURSE2'
258        self.course.semester = 1
259        self.course.credits = 10
260        self.course.passmark = 40
261        self.app['faculties']['jupeb']['dep2'].courses.addCourse(
262            self.course)
263        self.app['faculties']['jupeb']['dep2'].certificates[
264            'CERT2'].addCertCourse(self.course, level=100)
265        # Now it should work
266        self.student['studycourse'].certificate = self.certificate
267        self.browser.open(self.student_path)
268        self.browser.getLink("Base Data").click()
269        self.browser.getLink("Download admission letter").click()
270        self.assertEqual(self.browser.headers['Status'], '200 Ok')
271        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
272        path = os.path.join(samples_dir(), 'jupeb_admission_slip.pdf')
273        open(path, 'wb').write(self.browser.contents)
274        print "Sample PDF JUPEB admission_slip.pdf written to %s" % path
Note: See TracBrowser for help on using the repository browser.