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

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

Implement library clearance facilities.

  • Property svn:keywords set to Id
File size: 5.7 KB
Line 
1## $Id: test_browser.py 15859 2019-11-28 08:21:23Z 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)
Note: See TracBrowser for help on using the repository browser.