source: main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py @ 6706

Last change on this file since 6706 was 6702, checked in by Henrik Bettermann, 13 years ago

Found out by trial and error:

remove_logger('waeup.sirp.app.students') at the beginning of the second test method of StudentUITests fixes the AssertionError? self.assertTrue(filename1 != filename2)

  • Property svn:keywords set to Id
File size: 13.1 KB
Line 
1##
2## test_browser.py
3## Login : <uli@pu.smp.net>
4## Started on  Tue Mar 29 11:31:11 2011 Uli Fouquet
5## $Id: test_browser.py 6702 2011-09-09 18:06:30Z henrik $
6##
7## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
8## This program is free software; you can redistribute it and/or modify
9## it under the terms of the GNU General Public License as published by
10## the Free Software Foundation; either version 2 of the License, or
11## (at your option) any later version.
12##
13## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16## GNU General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with this program; if not, write to the Free Software
20## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21##
22"""
23Test the student-related UI components.
24"""
25import shutil
26import tempfile
27from StringIO import StringIO
28from datetime import datetime
29from mechanize import LinkNotFoundError
30from zope.component import createObject
31from zope.component.hooks import setSite, clearSite
32from zope.security.interfaces import Unauthorized
33from zope.testbrowser.testing import Browser
34from hurry.workflow.interfaces import IWorkflowInfo
35from waeup.sirp.testing import (
36    FunctionalLayer, FunctionalTestCase, remove_logger
37    )
38from waeup.sirp.app import University
39from waeup.sirp.students.container import StudentsContainer
40from waeup.sirp.students.student import Student
41from waeup.sirp.university.faculty import Faculty
42from waeup.sirp.university.department import Department
43from waeup.sirp.interfaces import IUserAccount
44
45PH_LEN = 2059  # Length of placeholder file
46
47class StudentsFullSetup(FunctionalTestCase):
48    # A test case that only contains a setup and teardown
49    #
50    # Complete setup for students handlings is rather complex and
51    # requires lots of things created before we can start. This is a
52    # setup that does all this, creates a university, creates PINs,
53    # etc.  so that we do not have to bother with that in different
54    # test cases.
55
56    layer = FunctionalLayer
57
58    def setUp(self):
59        super(StudentsFullSetup, self).setUp()
60
61        # Setup a sample site for each test
62        app = University()
63        self.dc_root = tempfile.mkdtemp()
64        app['datacenter'].setStoragePath(self.dc_root)
65
66        # Prepopulate the ZODB...
67        self.getRootFolder()['app'] = app
68        # we add the site immediately after creation to the
69        # ZODB. Catalogs and other local utilities are not setup
70        # before that step.
71        self.app = self.getRootFolder()['app']
72        # Set site here. Some of the following setup code might need
73        # to access grok.getSite() and should get our new app then
74        setSite(app)
75
76        # Add student with subobjects (done by addStudent)
77        student = Student()
78        student.name = u'Anna Tester'
79        self.test_student_id = self.app['students'].addStudent(student)
80        # Set password
81        IUserAccount(self.app['students'][self.test_student_id]).setPassword('spwd')
82
83        self.login_path = 'http://localhost/app/login'
84        self.container_path = 'http://localhost/app/students'
85        self.manage_container_path = self.container_path + '/@@manage'
86        self.add_student_path = self.container_path + '/addstudent'
87        self.student_path = self.container_path + '/' + self.test_student_id
88        self.manage_student_path = self.student_path + '/edit_base'
89        self.clearance_student_path = self.student_path + '/view_clearance'
90        self.personal_student_path = self.student_path + '/view_personal'
91        self.edit_clearance_student_path = self.student_path + '/edit_clearance'
92        self.edit_personal_student_path = self.student_path + '/edit_personal'
93
94        self.studycourse_student_path = self.student_path + '/studycourse'
95        self.payments_student_path = self.student_path + '/payments'
96        self.accommodation_student_path = self.student_path + '/accommodation'
97        self.history_student_path = self.student_path + '/history'
98
99        # Populate university
100        certificate = createObject('waeup.Certificate')
101        certificate.code = 'CERT1'
102        certificate.application_category = 'basic'
103        self.app['faculties']['fac1'] = Faculty()
104        self.app['faculties']['fac1']['dep1'] = Department()
105        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
106            certificate)
107
108        # Put the prepopulated site into test ZODB and prepare test
109        # browser
110        self.browser = Browser()
111        self.browser.handleErrors = False
112
113    def tearDown(self):
114        super(StudentsFullSetup, self).tearDown()
115        clearSite()
116        shutil.rmtree(self.dc_root)
117
118
119
120class StudentsContainerUITests(StudentsFullSetup):
121    # Tests for StudentsContainer class views and pages
122
123    layer = FunctionalLayer
124
125    def test_anonymous_access(self):
126        # Anonymous users can't access students containers
127        self.assertRaises(
128            Unauthorized, self.browser.open, self.container_path)
129        self.assertRaises(
130            Unauthorized, self.browser.open, self.manage_container_path)
131        return
132
133    def test_manage_access(self):
134        # Managers can access the view page of students
135        # containers and can perform actions
136        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
137        self.browser.open(self.container_path)
138        self.assertEqual(self.browser.headers['Status'], '200 Ok')
139        self.assertEqual(self.browser.url, self.container_path)
140        self.browser.getLink("Manage student section").click()
141        self.assertEqual(self.browser.headers['Status'], '200 Ok')
142        self.assertEqual(self.browser.url, self.manage_container_path)
143        return
144
145    def test_add_search_delete_students(self):
146        # Managers can add search and remove students
147        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
148        self.browser.open(self.manage_container_path)
149        self.browser.getLink("Add student").click()
150        self.assertEqual(self.browser.headers['Status'], '200 Ok')
151        self.assertEqual(self.browser.url, self.add_student_path)
152        self.browser.getControl(name="form.name").value = 'Bob Tester'
153        self.browser.getControl("Create student record").click()
154        self.assertTrue('Student record created' in self.browser.contents)
155
156        self.browser.open(self.container_path)
157        self.browser.getControl("Search").click()
158        self.assertTrue('Empty search string' in self.browser.contents)
159        self.browser.getControl(name="searchtype").value = ['student_id']
160        self.browser.getControl(name="searchterm").value = self.test_student_id
161        self.browser.getControl("Search").click()
162        self.assertTrue('Anna Tester' in self.browser.contents)
163
164        self.browser.open(self.manage_container_path)
165        self.browser.getControl("Search").click()
166        self.assertTrue('Empty search string' in self.browser.contents)
167        self.browser.getControl(name="searchtype").value = ['name']
168        self.browser.getControl(name="searchterm").value = 'Anna Tester'
169        self.browser.getControl("Search").click()
170        self.assertTrue('Anna Tester' in self.browser.contents)
171        # The old searchterm will be used again
172        self.browser.getControl("Search").click()
173        self.assertTrue('Anna Tester' in self.browser.contents)
174
175        ctrl = self.browser.getControl(name='entries')
176        ctrl.getControl(value=self.test_student_id).selected = True
177        self.browser.getControl("Remove selected", index=0).click()
178        self.assertTrue('Successfully removed' in self.browser.contents)
179        self.browser.getControl(name="searchtype").value = ['student_id']
180        self.browser.getControl(name="searchterm").value = self.test_student_id
181        self.browser.getControl("Search").click()
182        self.assertTrue('No student found' in self.browser.contents)
183
184        self.browser.open(self.container_path)
185        self.browser.getControl(name="searchtype").value = ['student_id']
186        self.browser.getControl(name="searchterm").value = self.test_student_id
187        self.browser.getControl("Search").click()
188        self.assertTrue('No student found' in self.browser.contents)
189
190class StudentUITests(StudentsFullSetup):
191    # Tests for Student class views and pages
192
193    layer = FunctionalLayer
194
195    def test_manage_access(self):
196        # Managers can access the pages of students
197        # and can perform actions
198        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
199
200        self.browser.open(self.student_path)
201        self.assertEqual(self.browser.headers['Status'], '200 Ok')
202        self.assertEqual(self.browser.url, self.student_path)
203        self.browser.getLink("Manage").click()
204        self.assertEqual(self.browser.headers['Status'], '200 Ok')
205        self.assertEqual(self.browser.url, self.manage_student_path)
206        # Managers can edit base data and fire transitions
207        self.browser.getControl(name="transition").value = ['admit']
208        self.browser.getControl(name="form.name").value = 'John Tester'
209        self.browser.getControl(name="form.reg_number").value = '123'
210        self.browser.getControl(name="password").value = 'secret'
211        self.browser.getControl(name="control_password").value = 'secret'
212        self.browser.getControl("Save").click()
213        self.assertMatches('...Form has been saved...',
214                           self.browser.contents)
215        self.browser.open(self.student_path)
216        self.browser.getLink("Clearance Data").click()
217        self.assertEqual(self.browser.headers['Status'], '200 Ok')
218        self.assertEqual(self.browser.url, self.clearance_student_path)
219        self.browser.getLink("Manage").click()
220        self.assertEqual(self.browser.headers['Status'], '200 Ok')
221        self.assertEqual(self.browser.url, self.edit_clearance_student_path)
222
223        self.browser.open(self.student_path)
224        self.browser.getLink("Personal Data").click()
225        self.assertEqual(self.browser.headers['Status'], '200 Ok')
226        self.assertEqual(self.browser.url, self.personal_student_path)
227        self.browser.getLink("Manage").click()
228        self.assertEqual(self.browser.headers['Status'], '200 Ok')
229        self.assertEqual(self.browser.url, self.edit_personal_student_path)
230
231        self.browser.open(self.student_path)
232        self.browser.getLink("Study Course").click()
233        self.assertEqual(self.browser.headers['Status'], '200 Ok')
234        self.assertEqual(self.browser.url, self.studycourse_student_path)
235        self.browser.getLink("Manage").click()
236        self.assertTrue('Manage study course' in self.browser.contents)
237
238        self.browser.open(self.student_path)
239        self.browser.getLink("Payments").click()
240        self.assertEqual(self.browser.headers['Status'], '200 Ok')
241        self.assertEqual(self.browser.url, self.payments_student_path)
242
243        self.browser.open(self.student_path)
244        self.browser.getLink("Accommodation").click()
245        self.assertEqual(self.browser.headers['Status'], '200 Ok')
246        self.assertEqual(self.browser.url, self.accommodation_student_path)
247
248        self.browser.open(self.student_path)
249        self.browser.getLink("History").click()
250        self.assertEqual(self.browser.headers['Status'], '200 Ok')
251        self.assertEqual(self.browser.url, self.history_student_path)
252        self.assertMatches('...Student admitted by zope.mgr...',
253                           self.browser.contents)
254        return
255
256    def test_student_access(self):
257        # Students can access their own objects
258        # and can perform actions
259        remove_logger('waeup.sirp.app.students')
260        self.browser.open(self.login_path)
261        self.browser.getControl(name="form.login").value = self.test_student_id
262        self.browser.getControl(name="form.password").value = 'spwd'
263        self.browser.getControl("Login").click()
264        self.assertEqual(self.browser.url, self.student_path)
265        self.assertTrue('You logged in' in self.browser.contents)
266        # Change password
267        self.browser.getLink("Change password").click()
268        self.browser.getControl(name="password").value = 'new_password'
269        self.browser.getControl(name="control_password").value = 'new_password'
270        self.browser.getControl("Save").click()
271        self.assertTrue('Form has been saved' in self.browser.contents)
272        # We are still logged in. Changing the password hasn't thrown us out.
273        self.browser.getLink("My Data").click()
274        self.assertEqual(self.browser.url, self.student_path)
275        # We can logout
276        self.browser.getLink("Logout").click()
277        self.assertTrue('You have been logged out' in self.browser.contents)
278        self.assertEqual(self.browser.url, 'http://localhost/app')
279        # We can login again with the new password
280        self.browser.getLink("Login").click()
281        self.browser.open(self.login_path)
282        self.browser.getControl(name="form.login").value = self.test_student_id
283        self.browser.getControl(name="password").value = 'new_password'
284        self.browser.getControl("Login").click()
285        self.assertEqual(self.browser.url, self.student_path)
286        self.assertTrue('You logged in' in self.browser.contents)
287
288        return
Note: See TracBrowser for help on using the repository browser.