~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to django/contrib/auth/tests/handlers.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from __future__ import unicode_literals
2
 
 
3
 
from django.contrib.auth.handlers.modwsgi import check_password, groups_for_user
4
 
from django.contrib.auth.models import User, Group
5
 
from django.contrib.auth.tests import CustomUser
6
 
from django.contrib.auth.tests.utils import skipIfCustomUser
7
 
from django.test import TransactionTestCase
8
 
from django.test.utils import override_settings
9
 
 
10
 
 
11
 
class ModWsgiHandlerTestCase(TransactionTestCase):
12
 
    """
13
 
    Tests for the mod_wsgi authentication handler
14
 
    """
15
 
    @skipIfCustomUser
16
 
    def test_check_password(self):
17
 
        """
18
 
        Verify that check_password returns the correct values as per
19
 
        http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms#Apache_Authentication_Provider
20
 
        """
21
 
        User.objects.create_user('test', 'test@example.com', 'test')
22
 
 
23
 
        # User not in database
24
 
        self.assertTrue(check_password({}, 'unknown', '') is None)
25
 
 
26
 
        # Valid user with correct password
27
 
        self.assertTrue(check_password({}, 'test', 'test'))
28
 
 
29
 
        # correct password, but user is inactive
30
 
        User.objects.filter(username='test').update(is_active=False)
31
 
        self.assertFalse(check_password({}, 'test', 'test'))
32
 
 
33
 
        # Valid user with incorrect password
34
 
        self.assertFalse(check_password({}, 'test', 'incorrect'))
35
 
 
36
 
    @override_settings(AUTH_USER_MODEL='auth.CustomUser')
37
 
    def test_check_password_custom_user(self):
38
 
        """
39
 
        Verify that check_password returns the correct values as per
40
 
        http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms#Apache_Authentication_Provider
41
 
 
42
 
        with custom user installed
43
 
        """
44
 
 
45
 
        CustomUser._default_manager.create_user('test@example.com', '1990-01-01', 'test')
46
 
 
47
 
        # User not in database
48
 
        self.assertTrue(check_password({}, 'unknown', '') is None)
49
 
 
50
 
        # Valid user with correct password'
51
 
        self.assertTrue(check_password({}, 'test@example.com', 'test'))
52
 
 
53
 
        # Valid user with incorrect password
54
 
        self.assertFalse(check_password({}, 'test@example.com', 'incorrect'))
55
 
 
56
 
    @skipIfCustomUser
57
 
    def test_groups_for_user(self):
58
 
        """
59
 
        Check that groups_for_user returns correct values as per
60
 
        http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms#Apache_Group_Authorisation
61
 
        """
62
 
        user1 = User.objects.create_user('test', 'test@example.com', 'test')
63
 
        User.objects.create_user('test1', 'test1@example.com', 'test1')
64
 
        group = Group.objects.create(name='test_group')
65
 
        user1.groups.add(group)
66
 
 
67
 
        # User not in database
68
 
        self.assertEqual(groups_for_user({}, 'unknown'), [])
69
 
 
70
 
        self.assertEqual(groups_for_user({}, 'test'), [b'test_group'])
71
 
        self.assertEqual(groups_for_user({}, 'test1'), [])