Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added basic tests for auth.views.password_reset

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7716 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fad8e8f7c2f1bfd563119404092b01cb402b1982 1 parent 5efb965
Luke Plant authored June 20, 2008
56  django/contrib/auth/fixtures/authtestdata.json
... ...
@@ -0,0 +1,56 @@
  1
+[
  2
+    {
  3
+        "pk": "1", 
  4
+        "model": "auth.user", 
  5
+        "fields": {
  6
+            "username": "testclient", 
  7
+            "first_name": "Test", 
  8
+            "last_name": "Client", 
  9
+            "is_active": true, 
  10
+            "is_superuser": false, 
  11
+            "is_staff": false, 
  12
+            "last_login": "2006-12-17 07:03:31", 
  13
+            "groups": [], 
  14
+            "user_permissions": [], 
  15
+            "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161", 
  16
+            "email": "testclient@example.com", 
  17
+            "date_joined": "2006-12-17 07:03:31"
  18
+        }
  19
+    },
  20
+    {
  21
+        "pk": "2", 
  22
+        "model": "auth.user", 
  23
+        "fields": {
  24
+            "username": "inactive", 
  25
+            "first_name": "Inactive", 
  26
+            "last_name": "User", 
  27
+            "is_active": false, 
  28
+            "is_superuser": false, 
  29
+            "is_staff": false, 
  30
+            "last_login": "2006-12-17 07:03:31", 
  31
+            "groups": [], 
  32
+            "user_permissions": [], 
  33
+            "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161", 
  34
+            "email": "testclient@example.com", 
  35
+            "date_joined": "2006-12-17 07:03:31"
  36
+        }
  37
+    },
  38
+    {
  39
+        "pk": "3", 
  40
+        "model": "auth.user", 
  41
+        "fields": {
  42
+            "username": "staff", 
  43
+            "first_name": "Staff", 
  44
+            "last_name": "Member", 
  45
+            "is_active": true, 
  46
+            "is_superuser": false, 
  47
+            "is_staff": true, 
  48
+            "last_login": "2006-12-17 07:03:31", 
  49
+            "groups": [], 
  50
+            "user_permissions": [], 
  51
+            "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161", 
  52
+            "email": "staffmember@example.com", 
  53
+            "date_joined": "2006-12-17 07:03:31"
  54
+        }
  55
+    }
  56
+]
21  django/contrib/auth/tests.py
... ...
@@ -1,5 +1,5 @@
1 1
 """
2  
->>> from models import User, AnonymousUser
  2
+>>> from django.contrib.auth.models import User, AnonymousUser
3 3
 >>> u = User.objects.create_user('testuser', 'test@example.com', 'testpw')
4 4
 >>> u.has_usable_password()
5 5
 True
@@ -52,4 +52,21 @@
52 52
 u'joe@somewhere.org'
53 53
 >>> u.password
54 54
 u'!'
55  
-"""
  55
+"""
  56
+
  57
+from django.test import TestCase
  58
+from django.core import mail
  59
+
  60
+class PasswordResetTest(TestCase):
  61
+    fixtures = ['authtestdata.json']
  62
+    def test_email_not_found(self):
  63
+        response = self.client.get('/auth/password_reset/')
  64
+        self.assertEquals(response.status_code, 200)
  65
+        response = self.client.post('/auth/password_reset/', {'email': 'not_a_real_email@email.com'} )
  66
+        self.assertContains(response, "That e-mail address doesn't have an associated user account")
  67
+        self.assertEquals(len(mail.outbox), 0)
  68
+
  69
+    def test_email_found(self):
  70
+        response = self.client.post('/auth/password_reset/', {'email': 'staffmember@example.com'} )
  71
+        self.assertEquals(response.status_code, 302)
  72
+        self.assertEquals(len(mail.outbox), 1)
12  django/contrib/auth/urls.py
... ...
@@ -0,0 +1,12 @@
  1
+# This exists for the sake of testing only.  Normally URLs are mapped in
  2
+# ../admin/urls.py
  3
+
  4
+from django.conf.urls.defaults import *
  5
+
  6
+urlpatterns = patterns('',
  7
+    ('^logout/$', 'django.contrib.auth.views.logout'),
  8
+    ('^password_change/$', 'django.contrib.auth.views.password_change'),
  9
+    ('^password_change/done/$', 'django.contrib.auth.views.password_change_done'),
  10
+    ('^password_reset/$', 'django.contrib.auth.views.password_reset')
  11
+)
  12
+
3  tests/urls.py
@@ -22,4 +22,7 @@
22 22
 
23 23
     # test urlconf for syndication tests
24 24
     (r'^syndication/', include('regressiontests.syndication.urls')),
  25
+
  26
+    # Other contrib apps
  27
+    (r'^auth/', include('django.contrib.auth.urls')),
25 28
 )

0 notes on commit fad8e8f

Please sign in to comment.
Something went wrong with that request. Please try again.