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

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

Fix tests: Use functional tests instead of unit tests to test the new students logger correctly.

  • Property svn:keywords set to Id
File size: 10.7 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 6641 2011-08-28 08:33:12Z 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 FunctionalLayer, FunctionalTestCase
36from waeup.sirp.app import University
37from waeup.sirp.students.container import StudentsContainer
38from waeup.sirp.students.student import Student
39from waeup.sirp.university.faculty import Faculty
40from waeup.sirp.university.department import Department
41
42PH_LEN = 2059  # Length of placeholder file
43
44class StudentsFullSetup(FunctionalTestCase):
45    # A test case that only contains a setup and teardown
46    #
47    # Complete setup for students handlings is rather complex and
48    # requires lots of things created before we can start. This is a
49    # setup that does all this, creates a university, creates PINs,
50    # etc.  so that we do not have to bother with that in different
51    # test cases.
52
53    layer = FunctionalLayer
54
55    def setUp(self):
56        super(StudentsFullSetup, self).setUp()
57
58        # Setup a sample site for each test
59        app = University()
60        self.dc_root = tempfile.mkdtemp()
61        app['datacenter'].setStoragePath(self.dc_root)
62
63        # Prepopulate the ZODB...
64        self.getRootFolder()['app'] = app
65        # we add the site immediately after creation to the
66        # ZODB. Catalogs and other local utilities are not setup
67        # before that step.
68        self.app = self.getRootFolder()['app']
69        # Set site here. Some of the following setup code might need
70        # to access grok.getSite() and should get our new app then
71        setSite(app)
72
73
74        # Add student with subobjects (done by addStudent)
75        student = Student()
76        student.name = u'Anna Tester'
77        student.student_id = u'Z654321'
78        self.app['students'].addStudent(student)
79
80        self.container_path = 'http://localhost/app/students'
81        self.manage_container_path = self.container_path + '/@@manage'
82        self.add_student_path = self.container_path + '/addstudent'
83        self.student_path = self.container_path + '/Z654321'
84        self.manage_student_path = self.student_path + '/edit_base'
85        self.clearance_student_path = self.student_path + '/view_clearance'
86        self.personal_student_path = self.student_path + '/view_personal'
87        self.edit_clearance_student_path = self.student_path + '/edit_clearance'
88        self.edit_personal_student_path = self.student_path + '/edit_personal'
89
90        self.studycourse_student_path = self.student_path + '/studycourse'
91        self.payments_student_path = self.student_path + '/payments'
92        self.accommodation_student_path = self.student_path + '/accommodation'
93        self.history_student_path = self.student_path + '/history'
94
95        # Populate university
96        certificate = createObject('waeup.Certificate')
97        certificate.code = 'CERT1'
98        certificate.application_category = 'basic'
99        self.app['faculties']['fac1'] = Faculty()
100        self.app['faculties']['fac1']['dep1'] = Department()
101        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
102            certificate)
103
104        # Put the prepopulated site into test ZODB and prepare test
105        # browser
106        self.browser = Browser()
107        self.browser.handleErrors = False
108
109    def tearDown(self):
110        super(StudentsFullSetup, self).tearDown()
111        clearSite()
112        shutil.rmtree(self.dc_root)
113
114
115
116class StudentsContainerUITests(StudentsFullSetup):
117    # Tests for StudentsContainer class views and pages
118
119    layer = FunctionalLayer
120
121    def test_anonymous_access(self):
122        # Anonymous users can't access students containers
123        self.assertRaises(
124            Unauthorized, self.browser.open, self.container_path)
125        self.assertRaises(
126            Unauthorized, self.browser.open, self.manage_container_path)
127        return
128
129    def test_manage_access(self):
130        # Managers can access the view page of students
131        # containers and can perform actions
132        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
133        self.browser.open(self.container_path)
134        self.assertEqual(self.browser.headers['Status'], '200 Ok')
135        self.assertEqual(self.browser.url, self.container_path)
136        self.browser.getLink("Manage students").click()
137        self.assertEqual(self.browser.headers['Status'], '200 Ok')
138        self.assertEqual(self.browser.url, self.manage_container_path)
139        return
140
141    def test_add_search_delete_students(self):
142        # Managers can add search and remove students
143        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
144        self.browser.open(self.manage_container_path)
145        self.browser.getLink("Add student").click()
146        self.assertEqual(self.browser.headers['Status'], '200 Ok')
147        self.assertEqual(self.browser.url, self.add_student_path)
148        self.browser.getControl(name="form.student_id").value = 'A123456'
149        self.browser.getControl(name="form.name").value = 'Bob Tester'
150        self.browser.getControl("Create student record").click()
151        self.assertTrue('Student record created' in self.browser.contents)
152
153        self.browser.open(self.container_path)
154        self.browser.getControl("Search").click()
155        self.assertTrue('Empty search string' in self.browser.contents)
156        self.browser.getControl(name="searchtype").value = ['student_id']
157        self.browser.getControl(name="searchterm").value = 'A123456'
158        self.browser.getControl("Search").click()
159        self.assertTrue('Bob Tester' in self.browser.contents)
160        # The old searchterm will be used again
161        self.browser.getControl("Search").click()
162        self.assertTrue('Bob 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 = 'Bob Tester'
169        self.browser.getControl("Search").click()
170        self.assertTrue('A123456' in self.browser.contents)
171        ctrl = self.browser.getControl(name='entries')
172        ctrl.getControl(value='A123456').selected = True
173        self.browser.getControl("Remove selected", index=0).click()
174        self.assertTrue('Successfully removed' in self.browser.contents)
175        self.browser.getControl(name="searchtype").value = ['student_id']
176        self.browser.getControl(name="searchterm").value = 'A123456'
177        self.browser.getControl("Search").click()
178        self.assertTrue('No student found' in self.browser.contents)
179
180        self.browser.open(self.container_path)
181        self.browser.getControl(name="searchtype").value = ['student_id']
182        self.browser.getControl(name="searchterm").value = 'A123456'
183        self.browser.getControl("Search").click()
184        self.assertTrue('No student found' in self.browser.contents)
185
186class StudentUITests(StudentsFullSetup):
187    # Tests for Student class views and pages
188
189    layer = FunctionalLayer
190
191    def test_manage_access(self):
192        # Managers can access the pages of students
193        # and can perform actions
194        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
195
196        self.browser.open(self.student_path)
197        self.assertEqual(self.browser.headers['Status'], '200 Ok')
198        self.assertEqual(self.browser.url, self.student_path)
199        self.browser.getLink("Edit").click()
200        self.assertEqual(self.browser.headers['Status'], '200 Ok')
201        self.assertEqual(self.browser.url, self.manage_student_path)
202        # Managers can fire transitions
203        self.browser.getControl(name="transition").value = ['admit']
204        self.browser.getControl("Save").click()
205        self.assertTrue('Form has been saved' in self.browser.contents)
206
207        self.browser.open(self.student_path)
208        self.browser.getLink("Clearance Data").click()
209        self.assertEqual(self.browser.headers['Status'], '200 Ok')
210        self.assertEqual(self.browser.url, self.clearance_student_path)
211        self.browser.getLink("Edit").click()
212        self.assertEqual(self.browser.headers['Status'], '200 Ok')
213        self.assertEqual(self.browser.url, self.edit_clearance_student_path)
214
215        self.browser.open(self.student_path)
216        self.browser.getLink("Personal Data").click()
217        self.assertEqual(self.browser.headers['Status'], '200 Ok')
218        self.assertEqual(self.browser.url, self.personal_student_path)
219        self.browser.getLink("Edit").click()
220        self.assertEqual(self.browser.headers['Status'], '200 Ok')
221        self.assertEqual(self.browser.url, self.edit_personal_student_path)
222
223        self.browser.open(self.student_path)
224        self.browser.getLink("Study Course").click()
225        self.assertEqual(self.browser.headers['Status'], '200 Ok')
226        self.assertEqual(self.browser.url, self.studycourse_student_path)
227
228        self.browser.open(self.student_path)
229        self.browser.getLink("Payments").click()
230        self.assertEqual(self.browser.headers['Status'], '200 Ok')
231        self.assertEqual(self.browser.url, self.payments_student_path)
232
233        self.browser.open(self.student_path)
234        self.browser.getLink("Accommodation").click()
235        self.assertEqual(self.browser.headers['Status'], '200 Ok')
236        self.assertEqual(self.browser.url, self.accommodation_student_path)
237
238        self.browser.open(self.student_path)
239        self.browser.getLink("History").click()
240        self.assertEqual(self.browser.headers['Status'], '200 Ok')
241        self.assertEqual(self.browser.url, self.history_student_path)
242        self.assertMatches('...Student admitted by zope.mgr...', self.browser.contents)
243
244        return
Note: See TracBrowser for help on using the repository browser.