Ticket #12202: 12202_with_test.diff

File 12202_with_test.diff, 4.6 KB (added by Claude Paroz, 14 years ago)

Updated patch containing a test

  • new file django/contrib/admin/templates/registration/password_reset_subject.html

    diff --git a/django/contrib/admin/templates/registration/password_reset_subject.html b/django/contrib/admin/templates/registration/password_reset_subject.html
    new file mode 100644
    index 0000000..45a354b
    - +  
     1{% load i18n %}{% autoescape off %}
     2{% blocktrans %}Password reset on {{ site_name }}{% endblocktrans %}
     3{% endautoescape %}
     4 No newline at end of file
  • django/contrib/auth/fixtures/authtestdata.json

    diff --git a/django/contrib/auth/fixtures/authtestdata.json b/django/contrib/auth/fixtures/authtestdata.json
    index e0bdc24..c286743 100644
    a b  
    3131            "groups": [],
    3232            "user_permissions": [],
    3333            "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161",
    34             "email": "testclient@example.com",
     34            "email": "testclient2@example.com",
    3535            "date_joined": "2006-12-17 07:03:31"
    3636        }
    3737    },
  • django/contrib/auth/forms.py

    diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
    index 7473279..d692086 100644
    a b class PasswordResetForm(forms.Form):  
    117117            raise forms.ValidationError(_("That e-mail address doesn't have an associated user account. Are you sure you've registered?"))
    118118        return email
    119119
    120     def save(self, domain_override=None, email_template_name='registration/password_reset_email.html',
    121              use_https=False, token_generator=default_token_generator, from_email=None, request=None):
     120    def save(self, domain_override=None,
     121             subject_template_name='registration/password_reset_subject.html',
     122             email_template_name='registration/password_reset_email.html',
     123             use_https=False, token_generator=default_token_generator,
     124             from_email=None, request=None):
    122125        """
    123126        Generates a one-use only link for resetting password and sends to the user
    124127        """
    class PasswordResetForm(forms.Form):  
    130133                domain = current_site.domain
    131134            else:
    132135                site_name = domain = domain_override
    133             t = loader.get_template(email_template_name)
    134136            c = {
    135137                'email': user.email,
    136138                'domain': domain,
    class PasswordResetForm(forms.Form):  
    140142                'token': token_generator.make_token(user),
    141143                'protocol': use_https and 'https' or 'http',
    142144            }
    143             send_mail(_("Password reset on %s") % site_name,
    144                 t.render(Context(c)), from_email, [user.email])
     145            subject = loader.render_to_string(subject_template_name, c)
     146            subject = ''.join(subject.splitlines())
     147            email = loader.render_to_string(email_template_name, c)
     148            send_mail(subject, email, from_email, [user.email])
    145149
    146150class SetPasswordForm(forms.Form):
    147151    """
  • django/contrib/auth/tests/forms.py

    diff --git a/django/contrib/auth/tests/forms.py b/django/contrib/auth/tests/forms.py
    index 5aa49e0..993c12f 100644
    a b class PasswordResetFormTest(TestCase):  
    242242        self.assertTrue(form.is_valid())
    243243        self.assertEqual(form.cleaned_data['email'], u'jsmith3@example.com')
    244244
     245    def test_custom_email_subject(self):
     246        import os
     247        from django.conf import settings
     248        from django.core import mail
     249
     250        old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
     251        settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'),)
     252        data = {'email': 'testclient@example.com'}
     253        form = PasswordResetForm(data)
     254        try:
     255            self.assertTrue(form.is_valid())
     256            form.save()
     257
     258            self.assertEqual(len(mail.outbox), 1)
     259            self.assertEqual(mail.outbox[0].subject, u'Custom password reset on example.com')
     260        finally:
     261            settings.TEMPLATE_DIRS = old_TEMPLATE_DIRS
    245262
    246263    def test_bug_5605(self):
    247264        # bug #5605, preserve the case of the user name (before the @ in the
  • new file django/contrib/auth/tests/templates/registration/password_reset_subject.html

    diff --git a/django/contrib/auth/tests/templates/registration/password_reset_subject.html b/django/contrib/auth/tests/templates/registration/password_reset_subject.html
    new file mode 100644
    index 0000000..f0d0eac
    - +  
     1{% load i18n %}{% autoescape off %}
     2{% blocktrans %}Custom password reset on {{ site_name }}{% endblocktrans %}
     3{% endautoescape %}
Back to Top