vigiboard / vigiboard / tests / functional / test_authentication.py @ 747e30c3
History | View | Annotate | Download (2.33 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
"""
|
3 |
Integration tests for the :mod:`repoze.who`-powered authentication sub-system.
|
4 |
|
5 |
As vigiboard grows and the authentication method changes, only these tests
|
6 |
should be updated.
|
7 |
|
8 |
"""
|
9 |
|
10 |
from vigiboard.tests import TestController |
11 |
|
12 |
|
13 |
class TestAuthentication(TestController): |
14 |
"""
|
15 |
Tests for the default authentication setup.
|
16 |
|
17 |
By default in TurboGears 2, :mod:`repoze.who` is configured with the same
|
18 |
plugins specified by repoze.what-quickstart (which are listed in
|
19 |
http://code.gustavonarea.net/repoze.what-quickstart/#repoze.what.plugins.quickstart.setup_sql_auth).
|
20 |
|
21 |
As the settings for those plugins change, or the plugins are replaced,
|
22 |
these tests should be updated.
|
23 |
|
24 |
"""
|
25 |
|
26 |
application_under_test = 'main'
|
27 |
|
28 |
def test_voluntary_login(self): |
29 |
"""Voluntary logins must work correctly"""
|
30 |
# Going to the login form voluntarily:
|
31 |
resp = self.app.get('/login', status=200) |
32 |
form = resp.form |
33 |
# Submitting the login form:
|
34 |
form['login'] = u'manager' |
35 |
form['password'] = u'managepass' |
36 |
post_login = form.submit(status=302)
|
37 |
# Being redirected to the home page:
|
38 |
assert post_login.location.startswith('http://localhost/post_login') |
39 |
home_page = post_login.follow(status=302)
|
40 |
assert 'authtkt' in home_page.request.cookies, \ |
41 |
'Session cookie was not defined: %s' % home_page.request.cookies
|
42 |
assert home_page.location == 'http://localhost/' |
43 |
|
44 |
def test_logout(self): |
45 |
"""Logouts must work correctly"""
|
46 |
# Logging in voluntarily the quick way:
|
47 |
resp = self.app.get('/login_handler?login=manager&password=managepass', |
48 |
status=302)
|
49 |
resp = resp.follow(status=302)
|
50 |
assert 'authtkt' in resp.request.cookies, \ |
51 |
'Session cookie was not defined: %s' % resp.request.cookies
|
52 |
# Logging out:
|
53 |
resp = self.app.get('/logout_handler', status=302) |
54 |
assert resp.location.startswith('http://localhost/post_logout') |
55 |
# Finally, redirected to the home page:
|
56 |
home_page = resp.follow(status=302)
|
57 |
assert home_page.request.cookies.get('authtkt') == '', \ |
58 |
'Session cookie was not deleted: %s' % home_page.request.cookies
|
59 |
assert home_page.location == 'http://localhost/', home_page.location |
60 |
|