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

Last change on this file since 16338 was 16296, checked in by Henrik Bettermann, 4 years ago

Add page with current session payments.

  • Property svn:keywords set to Id
File size: 10.7 KB
Line 
1## $Id: test_browser.py 16296 2020-11-02 18:08: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.students.tests.test_browser import StudentsFullSetup
33from waeup.kofa.students.accommodation import BedTicket
34from waeup.kofa.testing import FunctionalTestCase
35from waeup.kofa.browser.tests.test_pdf import samples_dir
36from waeup.kofa.interfaces import (
37    IExtFileStore, IFileStoreNameChooser)
38from waeup.kofa.students.interfaces import IStudentsUtils
39from waeup.kofa.tests.test_authentication import SECRET
40from kofacustom.iuokada.testing import FunctionalLayer
41
42
43class StudentsContainerUITests(StudentsFullSetup):
44    # Tests for StudentsContainer class views and pages
45
46    layer = FunctionalLayer
47
48    def test_dummytest(self):
49        return
50
51class OfficerUITests(StudentsFullSetup):
52    # Tests for Student class views and pages
53
54    layer = FunctionalLayer
55
56    def test_lib_idcard_officer(self):
57        # Create library officer
58        self.app['users'].addUser('mrlibrary', SECRET)
59        self.app['users']['mrlibrary'].email = 'library@foo.ng'
60        self.app['users']['mrlibrary'].title = 'Carlo Pitter'
61        prmglobal = IPrincipalRoleManager(self.app)
62        prmglobal.assignRoleToPrincipal(
63            'waeup.LibraryClearanceOfficer', 'mrlibrary')
64        prmglobal.assignRoleToPrincipal(
65            'waeup.StudentsOfficer', 'mrlibrary')
66        self.browser.open(self.login_path)
67        self.browser.getControl(name="form.login").value = 'mrlibrary'
68        self.browser.getControl(name="form.password").value = SECRET
69        self.browser.getControl("Login").click()
70        self.assertMatches('...You logged in...', self.browser.contents)
71        self.browser.open(self.student_path)
72        self.assertFalse('Download Library Id Card' in self.browser.contents)
73        self.browser.getLink("Switch library access").click()
74        self.assertTrue('Library access enabled' in self.browser.contents)
75        self.browser.getLink("Download Library Id Card").click()
76        self.assertEqual(self.browser.headers['Status'], '200 Ok')
77        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
78        path = os.path.join(samples_dir(), 'lib_idcard_officer.pdf')
79        open(path, 'wb').write(self.browser.contents)
80        print "Sample PDF lib_idcard_officer.pdf written to %s" % path
81
82class StudentUITests(StudentsFullSetup):
83    # Tests for Student class views and pages
84
85    layer = FunctionalLayer
86
87    def test_student_course_registration(self):
88        IWorkflowState(self.student).setState('school fee paid')
89        self.browser.open(self.login_path)
90        self.browser.getControl(name="form.login").value = self.student_id
91        self.browser.getControl(name="form.password").value = 'spwd'
92        self.browser.getControl("Login").click()
93        # Now students can add the current study level
94        self.browser.getLink("Study Course").click()
95        self.browser.getLink("Add course list").click()
96        self.assertMatches('...Add current level 100 (Year 1)...',
97                           self.browser.contents)
98        self.browser.getControl("Create course list now").click()
99        # Students can open the pdf course registration slip
100        self.browser.open(
101            self.student_path + '/studycourse/100/course_registration_slip.pdf')
102        self.assertEqual(self.browser.headers['Status'], '200 Ok')
103        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
104        path = os.path.join(samples_dir(), 'course_registration_slip.pdf')
105        open(path, 'wb').write(self.browser.contents)
106        print "Sample PDF course_registration_slip.pdf written to %s" % path
107
108    def test_library_idcard(self):
109        IWorkflowState(self.student).setState('returning')
110        self.browser.open(self.login_path)
111        self.browser.getControl(name="form.login").value = self.student_id
112        self.browser.getControl(name="form.password").value = 'spwd'
113        self.browser.getControl("Login").click()
114        self.assertFalse('Download Library' in self.browser.contents)
115        self.student.library = True
116        self.browser.open(self.student_path)
117        self.browser.getLink("Download Library Id Card").click()
118        self.assertEqual(self.browser.headers['Status'], '200 Ok')
119        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
120        path = os.path.join(samples_dir(), 'lib_idcard_student.pdf')
121        open(path, 'wb').write(self.browser.contents)
122        print "Sample PDF lib_idcard_student.pdf written to %s" % path
123        self.assertTrue(self.student.library)
124        IWorkflowInfo(self.student).fireTransition('pay_school_fee')
125        self.assertFalse(self.student.library)
126
127    def test_student_studycourse_slip(self):
128        IWorkflowState(self.student).setState('school fee paid')
129        self.browser.open(self.login_path)
130        self.browser.getControl(name="form.login").value = self.student_id
131        self.browser.getControl(name="form.password").value = 'spwd'
132        self.browser.getControl("Login").click()
133        # Students can open base data slip
134        # (no button available in base package)
135        pdf_url = '%s/studycourse_slip.pdf' % self.studycourse_path
136        self.browser.open(pdf_url)
137        self.assertEqual(self.browser.headers['Status'], '200 Ok')
138        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
139        path = os.path.join(samples_dir(), 'studycourse_slip.pdf')
140        open(path, 'wb').write(self.browser.contents)
141        print "Sample PDF studycourse_slip.pdf written to %s" % path
142
143    def test_student_personal_edit(self):
144        IWorkflowState(self.student).setState('school fee paid')
145        self.browser.open(self.login_path)
146        self.browser.getControl(name="form.login").value = self.student_id
147        self.browser.getControl(name="form.password").value = 'spwd'
148        self.browser.getControl("Login").click()
149        self.browser.getLink("Bio Data").click()
150        self.browser.getLink("Edit registration bio data").click()
151        self.assertTrue("Please make required payments first" in self.browser.contents)
152        self.assertEqual(self.browser.url, self.personal_path)
153
154    def test_student_personal_slip(self):
155        payment1 = createObject(u'waeup.StudentOnlinePayment')
156        timestamp = ("%d" % int(time()*10000))[1:]
157        payment1.p_id = "LSCNEW-2-4153206270" # the longest possible p_id
158        payment1.p_category = 'schoolfee'
159        payment1.p_item = u'My School Fee'
160        payment1.p_session = 2015
161        payment1.p_level = 100
162        payment1.p_current = True
163        payment1.amount_auth = 23456.9
164        payment1.approve()
165        payment2 = createObject(u'waeup.StudentOnlinePayment')
166        timestamp = ("%d" % int(time()*10000))[1:]
167        payment2.p_id = "p%s" % timestamp
168        payment2.p_category = 'clearance'
169        payment2.p_item = u'My Clearance Fee'
170        payment2.p_session = 2015
171        payment2.p_level = 100
172        payment2.p_current = True
173        payment2.amount_auth = 5678.6
174        payment2.approve()
175        self.student['payments'][payment1.p_id] = payment1
176        self.student['payments'][payment2.p_id] = payment2
177        IWorkflowState(self.student).setState('school fee paid')
178        self.browser.open(self.login_path)
179        self.browser.getControl(name="form.login").value = self.student_id
180        self.browser.getControl(name="form.password").value = 'spwd'
181        self.browser.getControl("Login").click()
182        # Students can open base data slip
183        # (no button available in base package)
184        pdf_url = '%s/course_registration_clearance.pdf' % self.student_path
185        self.browser.open(pdf_url)
186        self.assertEqual(self.browser.headers['Status'], '200 Ok')
187        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
188        path = os.path.join(samples_dir(), 'course_registration_clearance.pdf')
189        open(path, 'wb').write(self.browser.contents)
190        print "Sample PDF course_registration_clearance.pdf written to %s" % path
191
192    def test_student_admission_letter(self):
193        self.certificate.study_mode = 'ug_ft'
194        # Student cant login if their password is not set
195        IWorkflowInfo(self.student).fireTransition('admit')
196        self.browser.open(self.login_path)
197        self.browser.getControl(name="form.login").value = self.student_id
198        self.browser.getControl(name="form.password").value = 'spwd'
199        self.browser.getControl("Login").click()
200        self.assertMatches(
201            '...You logged in...', self.browser.contents)
202        # Admitted student can upload a passport picture
203        #self.browser.open(self.student_path + '/change_portrait')
204        #ctrl = self.browser.getControl(name='passportuploadedit')
205        #file_obj = open(SAMPLE_IMAGE, 'rb')
206        #file_ctrl = ctrl.mech_control
207        #file_ctrl.add_file(file_obj, filename='my_photo.jpg')
208        #self.browser.getControl(
209        #    name='upload_passportuploadedit').click()
210        #self.assertTrue(
211        #    'src="http://localhost/app/students/K1000000/passport.jpg"'
212        #    in self.browser.contents)
213        # Students can open admission letter
214        self.browser.getLink("Base Data").click()
215        self.browser.getLink("Download admission letter").click()
216        self.assertEqual(self.browser.headers['Status'], '200 Ok')
217        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
218        path = os.path.join(samples_dir(), 'admission_slip.pdf')
219        open(path, 'wb').write(self.browser.contents)
220        print "Sample PDF admission_slip.pdf written to %s" % path
Note: See TracBrowser for help on using the repository browser.