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

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

Fix tests.

  • Property svn:keywords set to Id
File size: 10.9 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 6652 2011-08-29 12:28:54Z 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        # Add student with subobjects (done by addStudent)
74        student = Student()
75        student.name = u'Anna Tester'
76        self.test_student_id = self.app['students'].addStudent(student)
77
78        self.container_path = 'http://localhost/app/students'
79        self.manage_container_path = self.container_path + '/@@manage'
80        self.add_student_path = self.container_path + '/addstudent'
81        self.student_path = self.container_path + '/' + self.test_student_id
82        self.manage_student_path = self.student_path + '/edit_base'
83        self.clearance_student_path = self.student_path + '/view_clearance'
84        self.personal_student_path = self.student_path + '/view_personal'
85        self.edit_clearance_student_path = self.student_path + '/edit_clearance'
86        self.edit_personal_student_path = self.student_path + '/edit_personal'
87
88        self.studycourse_student_path = self.student_path + '/studycourse'
89        self.payments_student_path = self.student_path + '/payments'
90        self.accommodation_student_path = self.student_path + '/accommodation'
91        self.history_student_path = self.student_path + '/history'
92
93        # Populate university
94        certificate = createObject('waeup.Certificate')
95        certificate.code = 'CERT1'
96        certificate.application_category = 'basic'
97        self.app['faculties']['fac1'] = Faculty()
98        self.app['faculties']['fac1']['dep1'] = Department()
99        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
100            certificate)
101
102        # Put the prepopulated site into test ZODB and prepare test
103        # browser
104        self.browser = Browser()
105        self.browser.handleErrors = False
106
107    def tearDown(self):
108        super(StudentsFullSetup, self).tearDown()
109        clearSite()
110        shutil.rmtree(self.dc_root)
111
112
113
114class StudentsContainerUITests(StudentsFullSetup):
115    # Tests for StudentsContainer class views and pages
116
117    layer = FunctionalLayer
118
119    def test_anonymous_access(self):
120        # Anonymous users can't access students containers
121        self.assertRaises(
122            Unauthorized, self.browser.open, self.container_path)
123        self.assertRaises(
124            Unauthorized, self.browser.open, self.manage_container_path)
125        return
126
127    def test_manage_access(self):
128        # Managers can access the view page of students
129        # containers and can perform actions
130        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
131        self.browser.open(self.container_path)
132        self.assertEqual(self.browser.headers['Status'], '200 Ok')
133        self.assertEqual(self.browser.url, self.container_path)
134        self.browser.getLink("Manage student section").click()
135        self.assertEqual(self.browser.headers['Status'], '200 Ok')
136        self.assertEqual(self.browser.url, self.manage_container_path)
137        return
138
139    def test_add_search_delete_students(self):
140        # Managers can add search and remove students
141        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
142        self.browser.open(self.manage_container_path)
143        self.browser.getLink("Add student").click()
144        self.assertEqual(self.browser.headers['Status'], '200 Ok')
145        self.assertEqual(self.browser.url, self.add_student_path)
146        self.browser.getControl(name="form.name").value = 'Bob Tester'
147        self.browser.getControl("Create student record").click()
148        self.assertTrue('Student record created' in self.browser.contents)
149
150        self.browser.open(self.container_path)
151        self.browser.getControl("Search").click()
152        self.assertTrue('Empty search string' in self.browser.contents)
153        self.browser.getControl(name="searchtype").value = ['student_id']
154        self.browser.getControl(name="searchterm").value = self.test_student_id
155        self.browser.getControl("Search").click()
156        self.assertTrue('Anna Tester' in self.browser.contents)
157
158        self.browser.open(self.manage_container_path)
159        self.browser.getControl("Search").click()
160        self.assertTrue('Empty search string' in self.browser.contents)
161        self.browser.getControl(name="searchtype").value = ['name']
162        self.browser.getControl(name="searchterm").value = 'Anna Tester'
163        self.browser.getControl("Search").click()
164        self.assertTrue('Anna Tester' in self.browser.contents)
165        # The old searchterm will be used again
166        self.browser.getControl("Search").click()
167        self.assertTrue('Anna Tester' in self.browser.contents)
168
169        ctrl = self.browser.getControl(name='entries')
170        ctrl.getControl(value=self.test_student_id).selected = True
171        self.browser.getControl("Remove selected", index=0).click()
172        self.assertTrue('Successfully removed' in self.browser.contents)
173        self.browser.getControl(name="searchtype").value = ['student_id']
174        self.browser.getControl(name="searchterm").value = self.test_student_id
175        self.browser.getControl("Search").click()
176        self.assertTrue('No student found' in self.browser.contents)
177
178        self.browser.open(self.container_path)
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
184class StudentUITests(StudentsFullSetup):
185    # Tests for Student class views and pages
186
187    layer = FunctionalLayer
188
189    def test_manage_access(self):
190        # Managers can access the pages of students
191        # and can perform actions
192        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
193
194        self.browser.open(self.student_path)
195        self.assertEqual(self.browser.headers['Status'], '200 Ok')
196        self.assertEqual(self.browser.url, self.student_path)
197        self.browser.getLink("Edit").click()
198        self.assertEqual(self.browser.headers['Status'], '200 Ok')
199        self.assertEqual(self.browser.url, self.manage_student_path)
200        # Managers can edit base data and fire transitions
201        self.browser.getControl(name="transition").value = ['admit']
202        self.browser.getControl(name="form.name").value = 'John Tester'
203        self.browser.getControl("Save").click()
204        self.assertTrue('Form has been saved' in self.browser.contents)
205
206        self.browser.open(self.student_path)
207        self.browser.getLink("Clearance Data").click()
208        self.assertEqual(self.browser.headers['Status'], '200 Ok')
209        self.assertEqual(self.browser.url, self.clearance_student_path)
210        self.browser.getLink("Edit").click()
211        self.assertEqual(self.browser.headers['Status'], '200 Ok')
212        self.assertEqual(self.browser.url, self.edit_clearance_student_path)
213
214        self.browser.open(self.student_path)
215        self.browser.getLink("Personal Data").click()
216        self.assertEqual(self.browser.headers['Status'], '200 Ok')
217        self.assertEqual(self.browser.url, self.personal_student_path)
218        self.browser.getLink("Edit").click()
219        self.assertEqual(self.browser.headers['Status'], '200 Ok')
220        self.assertEqual(self.browser.url, self.edit_personal_student_path)
221
222        self.browser.open(self.student_path)
223        self.browser.getLink("Study Course").click()
224        self.assertEqual(self.browser.headers['Status'], '200 Ok')
225        self.assertEqual(self.browser.url, self.studycourse_student_path)
226        self.browser.getLink("Edit").click()
227        self.assertTrue('Edit study course' in self.browser.contents)
228
229        self.browser.open(self.student_path)
230        self.browser.getLink("Payments").click()
231        self.assertEqual(self.browser.headers['Status'], '200 Ok')
232        self.assertEqual(self.browser.url, self.payments_student_path)
233
234        self.browser.open(self.student_path)
235        self.browser.getLink("Accommodation").click()
236        self.assertEqual(self.browser.headers['Status'], '200 Ok')
237        self.assertEqual(self.browser.url, self.accommodation_student_path)
238
239        self.browser.open(self.student_path)
240        self.browser.getLink("History").click()
241        self.assertEqual(self.browser.headers['Status'], '200 Ok')
242        self.assertEqual(self.browser.url, self.history_student_path)
243        self.assertMatches('...Student admitted by zope.mgr...', self.browser.contents)
244
245        return
Note: See TracBrowser for help on using the repository browser.