source: main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_browser.py @ 5895

Last change on this file since 5895 was 5895, checked in by uli, 13 years ago

Check that entered values are really displayed after submit.

File size: 4.8 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$
6##
7## Copyright (C) 2011 Uli Fouquet
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 applicant-related UI components.
24"""
25import shutil
26import tempfile
27import unittest
28from zope.app.testing.functional import FunctionalTestCase
29from zope.app.testing.functional import HTTPCaller as http
30from zope.component import createObject
31from zope.security.interfaces import Unauthorized
32from zope.testbrowser.testing import Browser
33from waeup.sirp.testing import FunctionalLayer
34from waeup.sirp.app import University
35from waeup.sirp.applicants.container import ApplicantsContainer
36
37class LoginTest(FunctionalTestCase):
38    # Here we check login view of applicants containers.
39   
40    layer = FunctionalLayer
41   
42    def setUp(self):
43        super(LoginTest, self).setUp()
44
45        # Setup a sample site for each test
46        app = University()
47        self.dc_root = tempfile.mkdtemp()
48        app['datacenter'].setStoragePath(self.dc_root)
49        self.login_path = 'http://localhost/app/applicants/testapplicants/login'
50
51        # Add an applicants container where we can login (or not)
52        app['applicants']['testapplicants'] = ApplicantsContainer()
53
54        # Put the prepopulated site into test ZODB and prepare test
55        # browser
56        self.getRootFolder()['app'] = app
57        self.browser = Browser()
58        self.browser.handleErrors = False
59
60    def tearDown(self):
61        super(LoginTest, self).tearDown()
62        shutil.rmtree(self.dc_root)
63
64    def test_anonymous_access(self):
65        # Anonymous users can access a login page
66        self.browser.open(self.login_path)
67        self.assertEqual(self.browser.headers['Status'], '200 Ok')
68        return
69
70    def test_anonymous_invalid_creds(self):
71        # Anonymous users giving invalid credentials stay at the page
72        self.browser.open(self.login_path)
73        # We do not give credentials but send the form as-is
74        submit = self.browser.getControl(name='SUBMIT')
75        submit.click()
76        # We are still at the same page...
77        self.assertEqual(self.browser.url, self.login_path)
78        self.assertEqual(self.browser.headers['Status'], '200 Ok')
79        return
80
81    def test_anonymous_invalid_creds_warning(self):
82        # Entering wrong credentials will yield a warning
83        self.browser.open(self.login_path)
84        # We do not give credentials but send the form as-is
85        submit = self.browser.getControl(name='SUBMIT')
86        submit.click()
87        self.assertTrue(
88            'Entered credentials are invalid' in self.browser.contents)
89        return
90
91    def test_manager_no_warnings(self):
92        # Browsing the login screen as a manager, won't raise warnings
93        # Authenticate ourself as manager
94        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
95        self.browser.open(self.login_path)
96        # Submit the form w/o any credentials
97        self.browser.getControl(name="SUBMIT").click()
98        self.assertTrue(
99            'Entered credentials are invalid' not in self.browser.contents)
100        return
101
102    def test_manager_no_redirect(self):
103        # Browsing the login screen as a manager won't trigger a redirect
104        # Authenticate ourself as manager
105        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
106        self.browser.open(self.login_path)
107        # Submit the form w/o any credentials
108        self.browser.getControl(name="SUBMIT").click()
109        self.assertEqual(self.browser.url, self.login_path)
110        return
111
112    def test_display_entered_values(self):
113        # After submit the entered values are displayed in the form
114        self.browser.open(self.login_path)
115        # Enter some value we can look for after submit
116        ac_series = self.browser.getControl(name="form.ac_series")
117        ac_series.value = '666'
118        self.browser.getControl(name="SUBMIT").click()
119        self.assertTrue('666' in self.browser.contents)
120        return
121       
122def suite():
123    suite = unittest.TestSuite()
124    for testcase in [
125        LoginTest,
126            ]:
127        suite.addTests(unittest.makeSuite(testcase))
128    return suite
129
130test_suite = suite
131
Note: See TracBrowser for help on using the repository browser.