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

Last change on this file since 16137 was 16127, checked in by Henrik Bettermann, 5 years ago

Customize admission slip.

  • Property svn:keywords set to Id
File size: 8.1 KB
Line 
1## $Id: test_browser.py 16127 2020-06-25 05:18:16Z 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 StringIO import StringIO
22from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo
23from zope.securitypolicy.interfaces import IPrincipalRoleManager
24from zope.component.hooks import setSite, clearSite
25from zope.component import getUtility, createObject
26from zope.interface import verify
27from zope.event import notify
28from waeup.kofa.authentication import LocalRoleSetEvent
29from waeup.kofa.app import University
30from waeup.kofa.students.tests.test_browser import StudentsFullSetup
31from waeup.kofa.students.accommodation import BedTicket
32from waeup.kofa.testing import FunctionalTestCase
33from waeup.kofa.browser.tests.test_pdf import samples_dir
34from waeup.kofa.interfaces import (
35    IExtFileStore, IFileStoreNameChooser)
36from waeup.kofa.students.interfaces import IStudentsUtils
37from waeup.kofa.tests.test_authentication import SECRET
38from kofacustom.iuokada.testing import FunctionalLayer
39
40
41class StudentsContainerUITests(StudentsFullSetup):
42    # Tests for StudentsContainer class views and pages
43
44    layer = FunctionalLayer
45
46    def test_dummytest(self):
47        return
48
49class OfficerUITests(StudentsFullSetup):
50    # Tests for Student class views and pages
51
52    layer = FunctionalLayer
53
54    def test_lib_idcard_officer(self):
55        # Create library officer
56        self.app['users'].addUser('mrlibrary', SECRET)
57        self.app['users']['mrlibrary'].email = 'library@foo.ng'
58        self.app['users']['mrlibrary'].title = 'Carlo Pitter'
59        prmglobal = IPrincipalRoleManager(self.app)
60        prmglobal.assignRoleToPrincipal(
61            'waeup.LibraryClearanceOfficer', 'mrlibrary')
62        prmglobal.assignRoleToPrincipal(
63            'waeup.StudentsOfficer', 'mrlibrary')
64        self.browser.open(self.login_path)
65        self.browser.getControl(name="form.login").value = 'mrlibrary'
66        self.browser.getControl(name="form.password").value = SECRET
67        self.browser.getControl("Login").click()
68        self.assertMatches('...You logged in...', self.browser.contents)
69        self.browser.open(self.student_path)
70        self.assertFalse('Download Library Id Card' in self.browser.contents)
71        self.browser.getLink("Switch library access").click()
72        self.assertTrue('Library access enabled' in self.browser.contents)
73        self.browser.getLink("Download Library Id Card").click()
74        self.assertEqual(self.browser.headers['Status'], '200 Ok')
75        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
76        path = os.path.join(samples_dir(), 'lib_idcard_officer.pdf')
77        open(path, 'wb').write(self.browser.contents)
78        print "Sample PDF lib_idcard_officer.pdf written to %s" % path
79
80class StudentUITests(StudentsFullSetup):
81    # Tests for Student class views and pages
82
83    layer = FunctionalLayer
84
85    def test_student_course_registration(self):
86        IWorkflowState(self.student).setState('school fee paid')
87        self.browser.open(self.login_path)
88        self.browser.getControl(name="form.login").value = self.student_id
89        self.browser.getControl(name="form.password").value = 'spwd'
90        self.browser.getControl("Login").click()
91        # Now students can add the current study level
92        self.browser.getLink("Study Course").click()
93        self.browser.getLink("Add course list").click()
94        self.assertMatches('...Add current level 100 (Year 1)...',
95                           self.browser.contents)
96        self.browser.getControl("Create course list now").click()
97        # Students can open the pdf course registration slip
98        self.browser.open(
99            self.student_path + '/studycourse/100/course_registration_slip.pdf')
100        self.assertEqual(self.browser.headers['Status'], '200 Ok')
101        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
102        path = os.path.join(samples_dir(), 'course_registration_slip.pdf')
103        open(path, 'wb').write(self.browser.contents)
104        print "Sample PDF course_registration_slip.pdf written to %s" % path
105
106    def test_library_idcard(self):
107        IWorkflowState(self.student).setState('returning')
108        self.browser.open(self.login_path)
109        self.browser.getControl(name="form.login").value = self.student_id
110        self.browser.getControl(name="form.password").value = 'spwd'
111        self.browser.getControl("Login").click()
112        self.assertFalse('Library' in self.browser.contents)
113        self.student.library = True
114        self.browser.open(self.student_path)
115        self.browser.getLink("Download Library Id Card").click()
116        self.assertEqual(self.browser.headers['Status'], '200 Ok')
117        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
118        path = os.path.join(samples_dir(), 'lib_idcard_student.pdf')
119        open(path, 'wb').write(self.browser.contents)
120        print "Sample PDF lib_idcard_student.pdf written to %s" % path
121        self.assertTrue(self.student.library)
122        IWorkflowInfo(self.student).fireTransition('pay_school_fee')
123        self.assertFalse(self.student.library)
124
125    def test_student_basedata_slip(self):
126        IWorkflowState(self.student).setState('school fee paid')
127        self.browser.open(self.login_path)
128        self.browser.getControl(name="form.login").value = self.student_id
129        self.browser.getControl(name="form.password").value = 'spwd'
130        self.browser.getControl("Login").click()
131        # Students can open base data slip
132        # (no button available in base package)
133        pdf_url = '%s/basedata_slip.pdf' % self.studycourse_path
134        self.browser.open(pdf_url)
135        self.assertEqual(self.browser.headers['Status'], '200 Ok')
136        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
137        path = os.path.join(samples_dir(), 'basedata_slip.pdf')
138        open(path, 'wb').write(self.browser.contents)
139        print "Sample PDF basedata_slip.pdf written to %s" % path
140
141    def test_student_admission_letter(self):
142        # Student cant login if their password is not set
143        IWorkflowInfo(self.student).fireTransition('admit')
144        self.browser.open(self.login_path)
145        self.browser.getControl(name="form.login").value = self.student_id
146        self.browser.getControl(name="form.password").value = 'spwd'
147        self.browser.getControl("Login").click()
148        self.assertMatches(
149            '...You logged in...', self.browser.contents)
150        # Admitted student can upload a passport picture
151        #self.browser.open(self.student_path + '/change_portrait')
152        #ctrl = self.browser.getControl(name='passportuploadedit')
153        #file_obj = open(SAMPLE_IMAGE, 'rb')
154        #file_ctrl = ctrl.mech_control
155        #file_ctrl.add_file(file_obj, filename='my_photo.jpg')
156        #self.browser.getControl(
157        #    name='upload_passportuploadedit').click()
158        #self.assertTrue(
159        #    'src="http://localhost/app/students/K1000000/passport.jpg"'
160        #    in self.browser.contents)
161        # Students can open admission letter
162        self.browser.getLink("Base Data").click()
163        self.browser.getLink("Download admission letter").click()
164        self.assertEqual(self.browser.headers['Status'], '200 Ok')
165        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
166        path = os.path.join(samples_dir(), 'admission_slip.pdf')
167        open(path, 'wb').write(self.browser.contents)
168        print "Sample PDF admission_slip.pdf written to %s" % path
Note: See TracBrowser for help on using the repository browser.