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

Last change on this file since 17421 was 17404, checked in by Henrik Bettermann, 19 months ago

New dates.

  • Property svn:keywords set to Id
File size: 14.6 KB
Line 
1## $Id: test_browser.py 17404 2023-05-05 06:06:34Z 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
224        self.certificate.code = 'MBBS'
225        self.browser.open(self.student_path)
226        self.browser.getLink("Base Data").click()
227        self.browser.getLink("Download admission letter").click()
228        self.assertEqual(self.browser.headers['Status'], '200 Ok')
229        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
230        path = os.path.join(samples_dir(), 'mbbs_admission_slip.pdf')
231        open(path, 'wb').write(self.browser.contents)
232        print "Sample PDF mbbs_admission_slip.pdf written to %s" % path
233
234        self.certificate.code = 'LAW'
235        self.browser.open(self.student_path)
236        self.browser.getLink("Base Data").click()
237        self.browser.getLink("Download admission letter").click()
238        self.assertEqual(self.browser.headers['Status'], '200 Ok')
239        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
240        path = os.path.join(samples_dir(), 'law_admission_slip.pdf')
241        open(path, 'wb').write(self.browser.contents)
242        print "Sample PDF law_admission_slip.pdf written to %s" % path
243
244        self.certificate.study_mode = 'pg_ft'
245        self.browser.open(self.student_path)
246        self.browser.getLink("Base Data").click()
247        self.browser.getLink("Download admission letter").click()
248        self.assertEqual(self.browser.headers['Status'], '200 Ok')
249        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
250        path = os.path.join(samples_dir(), 'pg_admission_slip.pdf')
251        open(path, 'wb').write(self.browser.contents)
252        print "Sample PDF PG admission_slip.pdf written to %s" % path
253        self.certificate.study_mode = 'ug_pt'
254        self.browser.open(self.student_path)
255        self.browser.getLink("Base Data").click()
256        self.browser.getLink("Download admission letter").click()
257        self.assertEqual(self.browser.headers['Status'], '200 Ok')
258        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
259        path = os.path.join(samples_dir(), 'pt_admission_slip.pdf')
260        open(path, 'wb').write(self.browser.contents)
261        print "Sample PDF PT admission_slip.pdf written to %s" % path
262
263        # JUPEB is bit more complicated to test.
264        # Populate university with JUPEB first.
265        self.certificate = createObject('waeup.Certificate')
266        self.certificate.code = u'CERT2'
267        self.certificate.application_category = 'basic'
268        self.certificate.study_mode = 'ug_ft'
269        self.certificate.start_level = 100
270        self.certificate.end_level = 500
271        self.certificate.school_fee_1 = 40000.0
272        self.certificate.school_fee_2 = 20000.0
273        self.app['faculties']['jupeb'] = Faculty(code=u'JUPEB')
274        self.app['faculties']['jupeb']['dep2'] = Department(code=u'dep2')
275        self.app['faculties']['jupeb']['dep2'].certificates.addCertificate(
276            self.certificate)
277        self.course = createObject('waeup.Course')
278        self.course.code = 'COURSE2'
279        self.course.semester = 1
280        self.course.credits = 10
281        self.course.passmark = 40
282        self.app['faculties']['jupeb']['dep2'].courses.addCourse(
283            self.course)
284        self.app['faculties']['jupeb']['dep2'].certificates[
285            'CERT2'].addCertCourse(self.course, level=100)
286        # Now it should work
287        self.student['studycourse'].certificate = self.certificate
288        self.browser.open(self.student_path)
289        self.browser.getLink("Base Data").click()
290        self.browser.getLink("Download admission letter").click()
291        self.assertEqual(self.browser.headers['Status'], '200 Ok')
292        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
293        path = os.path.join(samples_dir(), 'jupeb_admission_slip.pdf')
294        open(path, 'wb').write(self.browser.contents)
295        print "Sample PDF JUPEB admission_slip.pdf written to %s" % path
Note: See TracBrowser for help on using the repository browser.