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

Last change on this file since 6624 was 6622, checked in by Henrik Bettermann, 14 years ago

Add some basic UI stuff to start and to play with.

  • Property svn:keywords set to Id
File size: 5.3 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 6622 2011-08-24 20:25:44Z 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 + '/@@add'
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_students(self):
124        # Managers can add students
125        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
126        self.add_student_path = self.container_path + '/addstudent'
127        self.container_manage_path = self.container_path + '/@@manage'
128        self.browser.open(self.container_manage_path)
129        self.browser.getControl("Add student").click()
130        self.assertEqual(self.browser.headers['Status'], '200 Ok')
131        self.assertEqual(self.browser.url, self.add_student_path)
132        self.browser.getControl(name="form.student_id").value = 'A123456'
133        self.browser.getControl(name="form.name").value = 'Bob Tester'
134        self.browser.getControl("Create student record").click()
Note: See TracBrowser for help on using the repository browser.