summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2008-06-30 13:11:12 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2008-06-30 13:11:12 +0000
commit8cb128e57c08de54e8947a00f0d17fd02bff90df (patch)
treeb57c9595255978dd4888114730a24c8060736eb3
parent4b93eed185c52a422bea3e73fe215db7c2746595 (diff)
Refs #7521 -- Re-reverted [7716] (originally reverted in [7726]), now modified to use the new TestCase urlpattern framework.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7808 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/auth/fixtures/authtestdata.json56
-rw-r--r--django/contrib/auth/tests.py24
-rw-r--r--django/contrib/auth/urls.py13
3 files changed, 91 insertions, 2 deletions
diff --git a/django/contrib/auth/fixtures/authtestdata.json b/django/contrib/auth/fixtures/authtestdata.json
new file mode 100644
index 0000000000..e0bdc24e72
--- /dev/null
+++ b/django/contrib/auth/fixtures/authtestdata.json
@@ -0,0 +1,56 @@
+[
+ {
+ "pk": "1",
+ "model": "auth.user",
+ "fields": {
+ "username": "testclient",
+ "first_name": "Test",
+ "last_name": "Client",
+ "is_active": true,
+ "is_superuser": false,
+ "is_staff": false,
+ "last_login": "2006-12-17 07:03:31",
+ "groups": [],
+ "user_permissions": [],
+ "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161",
+ "email": "testclient@example.com",
+ "date_joined": "2006-12-17 07:03:31"
+ }
+ },
+ {
+ "pk": "2",
+ "model": "auth.user",
+ "fields": {
+ "username": "inactive",
+ "first_name": "Inactive",
+ "last_name": "User",
+ "is_active": false,
+ "is_superuser": false,
+ "is_staff": false,
+ "last_login": "2006-12-17 07:03:31",
+ "groups": [],
+ "user_permissions": [],
+ "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161",
+ "email": "testclient@example.com",
+ "date_joined": "2006-12-17 07:03:31"
+ }
+ },
+ {
+ "pk": "3",
+ "model": "auth.user",
+ "fields": {
+ "username": "staff",
+ "first_name": "Staff",
+ "last_name": "Member",
+ "is_active": true,
+ "is_superuser": false,
+ "is_staff": true,
+ "last_login": "2006-12-17 07:03:31",
+ "groups": [],
+ "user_permissions": [],
+ "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161",
+ "email": "staffmember@example.com",
+ "date_joined": "2006-12-17 07:03:31"
+ }
+ }
+]
diff --git a/django/contrib/auth/tests.py b/django/contrib/auth/tests.py
index 81094ca85f..ea1ac26c21 100644
--- a/django/contrib/auth/tests.py
+++ b/django/contrib/auth/tests.py
@@ -1,5 +1,5 @@
"""
->>> from models import User, AnonymousUser
+>>> from django.contrib.auth.models import User, AnonymousUser
>>> u = User.objects.create_user('testuser', 'test@example.com', 'testpw')
>>> u.has_usable_password()
True
@@ -52,4 +52,24 @@ Superuser created successfully.
u'joe@somewhere.org'
>>> u.password
u'!'
-""" \ No newline at end of file
+"""
+
+from django.test import TestCase
+from django.core import mail
+
+class PasswordResetTest(TestCase):
+ fixtures = ['authtestdata.json']
+ urls = 'django.contrib.auth.urls'
+ def test_email_not_found(self):
+ "Error is raised if the provided email address isn't currently registered"
+ response = self.client.get('/password_reset/')
+ self.assertEquals(response.status_code, 200)
+ response = self.client.post('/password_reset/', {'email': 'not_a_real_email@email.com'})
+ self.assertContains(response, "That e-mail address doesn&#39;t have an associated user account")
+ self.assertEquals(len(mail.outbox), 0)
+
+ def test_email_found(self):
+ "Email is sent if a valid email address is provided for password reset"
+ response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})
+ self.assertEquals(response.status_code, 302)
+ self.assertEquals(len(mail.outbox), 1)
diff --git a/django/contrib/auth/urls.py b/django/contrib/auth/urls.py
new file mode 100644
index 0000000000..5ddfcf15e8
--- /dev/null
+++ b/django/contrib/auth/urls.py
@@ -0,0 +1,13 @@
+# These URLs are normally mapped to /admin/urls.py. This URLs file is
+# provided as a convenience to those who want to deploy these URLs elsewhere.
+# This file is also used to provide a reliable view deployment for test purposes.
+
+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('',
+ ('^logout/$', 'django.contrib.auth.views.logout'),
+ ('^password_change/$', 'django.contrib.auth.views.password_change'),
+ ('^password_change/done/$', 'django.contrib.auth.views.password_change_done'),
+ ('^password_reset/$', 'django.contrib.auth.views.password_reset')
+)
+