1
# django-openid-auth - OpenID integration for django.contrib.auth
3
# Copyright (C) 2009-2012 Canonical Ltd.
5
# Redistribution and use in source and binary forms, with or without
6
# modification, are permitted provided that the following conditions
9
# * Redistributions of source code must retain the above copyright
10
# notice, this list of conditions and the following disclaimer.
12
# * Redistributions in binary form must reproduce the above copyright
13
# notice, this list of conditions and the following disclaimer in the
14
# documentation and/or other materials provided with the distribution.
16
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
29
Tests for the django_openid_auth Admin login form replacement.
35
from django.conf import settings
36
from django.contrib.auth.models import User, AnonymousUser
38
settings.OPENID_USE_AS_ADMIN_LOGIN = True
39
from django_openid_auth import admin
41
from django.test import TestCase
44
def create_user(is_staff=False, authenticated=True):
46
Create and return a user, either the AnonymousUser or a normal Django user,
47
setting the is_staff attribute if appropriate.
50
return AnonymousUser()
53
username=u'testing', email='testing@example.com',
55
user.set_password(u'test')
59
class SiteAdminTests(TestCase):
61
TestCase for accessing /admin/ when the django_openid_auth form replacement
65
def test_admin_site_with_openid_login_authenticated_non_staff(self):
67
If the request has an authenticated user, who is not flagged as a
68
staff member, then they get a failure response.
71
self.client.login(username='testing', password='test')
72
response = self.client.get('/admin/')
73
self.assertTrue('User testing does not have admin access.' in
74
response.content, 'Missing error message in response')
76
def test_admin_site_with_openid_login_non_authenticated_user(self):
78
Unauthenticated users accessing the admin page should be directed to
81
response = self.client.get('/admin/')
82
self.assertEqual(302, response.status_code)
83
self.assertEqual('http://testserver/openid/login/?next=/admin/',
88
return unittest.TestLoader().loadTestsFromName(__name__)