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

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

Add students_catalog and search facilities.

  • Property svn:keywords set to Id
File size: 7.0 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 6626 2011-08-25 12:01:37Z 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        self.container_path = 'http://localhost/app/students'
74        self.manage_container_path = self.container_path + '/@@manage'
75        self.add_student_path = self.container_path + '/addstudent'
76
77        # Populate university
78        certificate = createObject('waeup.Certificate')
79        certificate.code = 'CERT1'
80        certificate.application_category = 'basic'
81        self.app['faculties']['fac1'] = Faculty()
82        self.app['faculties']['fac1']['dep1'] = Department()
83        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
84            certificate)
85
86        # Put the prepopulated site into test ZODB and prepare test
87        # browser
88        self.browser = Browser()
89        self.browser.handleErrors = False
90
91    def tearDown(self):
92        super(StudentsFullSetup, self).tearDown()
93        clearSite()
94        shutil.rmtree(self.dc_root)
95
96
97
98class StudentsContainerUITests(StudentsFullSetup):
99    # Tests for StudentsContainer class views and pages
100
101    layer = FunctionalLayer
102
103    def test_anonymous_access(self):
104        # Anonymous users can't access students containers
105        self.assertRaises(
106            Unauthorized, self.browser.open, self.container_path)
107        self.assertRaises(
108            Unauthorized, self.browser.open, self.manage_container_path)
109        return
110
111    def test_manage_access(self):
112        # Managers can access the view page of students
113        # containers and can perform actions
114        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
115        self.browser.open(self.container_path)
116        self.assertEqual(self.browser.headers['Status'], '200 Ok')
117        self.assertEqual(self.browser.url, self.container_path)
118        self.browser.getLink("Manage students").click()
119        self.assertEqual(self.browser.headers['Status'], '200 Ok')
120        self.assertEqual(self.browser.url, self.manage_container_path)
121        return
122
123    def test_add_search_delete_students(self):
124        # Managers can add search and remove students
125        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
126        self.browser.open(self.manage_container_path)
127        self.browser.getLink("Add student").click()
128        self.assertEqual(self.browser.headers['Status'], '200 Ok')
129        self.assertEqual(self.browser.url, self.add_student_path)
130        self.browser.getControl(name="form.student_id").value = 'A123456'
131        self.browser.getControl(name="form.name").value = 'Bob Tester'
132        self.browser.getControl("Create student record").click()
133        self.assertTrue('Student record created' in self.browser.contents)
134
135        self.browser.open(self.container_path)
136        self.browser.getControl("Search").click()
137        self.assertTrue('Empty search string' in self.browser.contents)
138        self.browser.getControl(name="searchtype").value = ['student_id']
139        self.browser.getControl(name="searchterm").value = 'A123456'
140        self.browser.getControl("Search").click()
141        self.assertTrue('Bob Tester' in self.browser.contents)
142        # The old searchterm will be used again
143        self.browser.getControl("Search").click()
144        self.assertTrue('Bob Tester' in self.browser.contents)
145
146        self.browser.open(self.manage_container_path)
147        self.browser.getControl("Search").click()
148        self.assertTrue('Empty search string' in self.browser.contents)
149        self.browser.getControl(name="searchtype").value = ['name']
150        self.browser.getControl(name="searchterm").value = 'Bob Tester'
151        self.browser.getControl("Search").click()
152        self.assertTrue('A123456' in self.browser.contents)
153        ctrl = self.browser.getControl(name='entries')
154        ctrl.getControl(value='A123456').selected = True
155        self.browser.getControl("Remove selected", index=0).click()
156        self.assertTrue('Successfully removed' in self.browser.contents)
157        self.browser.getControl(name="searchtype").value = ['student_id']
158        self.browser.getControl(name="searchterm").value = 'A123456'
159        self.browser.getControl("Search").click()
160        self.assertTrue('No student found' in self.browser.contents)
161
162        self.browser.open(self.container_path)
163        self.browser.getControl(name="searchtype").value = ['student_id']
164        self.browser.getControl(name="searchterm").value = 'A123456'
165        self.browser.getControl("Search").click()
166        self.assertTrue('No student found' in self.browser.contents)
167
Note: See TracBrowser for help on using the repository browser.