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

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

Add interfaces for clearance and personal data.
Add display and manage views.

  • Property svn:keywords set to Id
File size: 9.2 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 6631 2011-08-26 08:00:10Z 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.students 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
75        student = Student()
76        student.name = u'Anna Tester'
77        student.student_id = u'Z654321'
78        self.app['students'][student.student_id] = 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        # Populate university
91        certificate = createObject('waeup.Certificate')
92        certificate.code = 'CERT1'
93        certificate.application_category = 'basic'
94        self.app['faculties']['fac1'] = Faculty()
95        self.app['faculties']['fac1']['dep1'] = Department()
96        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
97            certificate)
98
99        # Put the prepopulated site into test ZODB and prepare test
100        # browser
101        self.browser = Browser()
102        self.browser.handleErrors = False
103
104    def tearDown(self):
105        super(StudentsFullSetup, self).tearDown()
106        clearSite()
107        shutil.rmtree(self.dc_root)
108
109
110
111class StudentsContainerUITests(StudentsFullSetup):
112    # Tests for StudentsContainer class views and pages
113
114    layer = FunctionalLayer
115
116    def test_anonymous_access(self):
117        # Anonymous users can't access students containers
118        self.assertRaises(
119            Unauthorized, self.browser.open, self.container_path)
120        self.assertRaises(
121            Unauthorized, self.browser.open, self.manage_container_path)
122        return
123
124    def test_manage_access(self):
125        # Managers can access the view page of students
126        # containers and can perform actions
127        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
128        self.browser.open(self.container_path)
129        self.assertEqual(self.browser.headers['Status'], '200 Ok')
130        self.assertEqual(self.browser.url, self.container_path)
131        self.browser.getLink("Manage students").click()
132        self.assertEqual(self.browser.headers['Status'], '200 Ok')
133        self.assertEqual(self.browser.url, self.manage_container_path)
134        return
135
136    def test_add_search_delete_students(self):
137        # Managers can add search and remove students
138        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
139        self.browser.open(self.manage_container_path)
140        self.browser.getLink("Add student").click()
141        self.assertEqual(self.browser.headers['Status'], '200 Ok')
142        self.assertEqual(self.browser.url, self.add_student_path)
143        self.browser.getControl(name="form.student_id").value = 'A123456'
144        self.browser.getControl(name="form.name").value = 'Bob Tester'
145        self.browser.getControl("Create student record").click()
146        self.assertTrue('Student record created' in self.browser.contents)
147
148        self.browser.open(self.container_path)
149        self.browser.getControl("Search").click()
150        self.assertTrue('Empty search string' in self.browser.contents)
151        self.browser.getControl(name="searchtype").value = ['student_id']
152        self.browser.getControl(name="searchterm").value = 'A123456'
153        self.browser.getControl("Search").click()
154        self.assertTrue('Bob Tester' in self.browser.contents)
155        # The old searchterm will be used again
156        self.browser.getControl("Search").click()
157        self.assertTrue('Bob Tester' in self.browser.contents)
158
159        self.browser.open(self.manage_container_path)
160        self.browser.getControl("Search").click()
161        self.assertTrue('Empty search string' in self.browser.contents)
162        self.browser.getControl(name="searchtype").value = ['name']
163        self.browser.getControl(name="searchterm").value = 'Bob Tester'
164        self.browser.getControl("Search").click()
165        self.assertTrue('A123456' in self.browser.contents)
166        ctrl = self.browser.getControl(name='entries')
167        ctrl.getControl(value='A123456').selected = True
168        self.browser.getControl("Remove selected", index=0).click()
169        self.assertTrue('Successfully removed' in self.browser.contents)
170        self.browser.getControl(name="searchtype").value = ['student_id']
171        self.browser.getControl(name="searchterm").value = 'A123456'
172        self.browser.getControl("Search").click()
173        self.assertTrue('No student found' in self.browser.contents)
174
175        self.browser.open(self.container_path)
176        self.browser.getControl(name="searchtype").value = ['student_id']
177        self.browser.getControl(name="searchterm").value = 'A123456'
178        self.browser.getControl("Search").click()
179        self.assertTrue('No student found' in self.browser.contents)
180
181class StudentUITests(StudentsFullSetup):
182    # Tests for Student class views and pages
183
184    layer = FunctionalLayer
185
186    def test_manage_access(self):
187        # Managers can access the pages of students
188        # and can perform actions
189        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
190        self.browser.open(self.student_path)
191        self.assertEqual(self.browser.headers['Status'], '200 Ok')
192        self.assertEqual(self.browser.url, self.student_path)
193        self.browser.getLink("Edit base data").click()
194        self.assertEqual(self.browser.headers['Status'], '200 Ok')
195        self.assertEqual(self.browser.url, self.manage_student_path)
196        self.browser.open(self.student_path)
197        self.browser.getLink("View clearance data").click()
198        self.assertEqual(self.browser.headers['Status'], '200 Ok')
199        self.assertEqual(self.browser.url, self.clearance_student_path)
200        self.browser.getLink("Edit clearance data").click()
201        self.assertEqual(self.browser.headers['Status'], '200 Ok')
202        self.assertEqual(self.browser.url, self.edit_clearance_student_path)
203        self.browser.open(self.student_path)
204        self.browser.getLink("View personal data").click()
205        self.assertEqual(self.browser.headers['Status'], '200 Ok')
206        self.assertEqual(self.browser.url, self.personal_student_path)
207        self.browser.getLink("Edit personal data").click()
208        self.assertEqual(self.browser.headers['Status'], '200 Ok')
209        self.assertEqual(self.browser.url, self.edit_personal_student_path)
210        return
Note: See TracBrowser for help on using the repository browser.