Anonymous avatar Anonymous committed 310f561

changes to prepare for django > 1.3
some more test fixing

Comments (0)

Files changed (23)

Binary file added.

registration/models.py

 import datetime
 import random
 import re
+import hashlib
+
 
 from django.conf import settings
 from django.contrib.auth.models import User
 from django.db import models
 from django.db import transaction
 from django.template.loader import render_to_string
-from django.utils.hashcompat import sha_constructor
+#django pre 1.3 from django.utils.hashcompat import sha_constructor
 from django.utils.translation import ugettext_lazy as _
 
 
         username and a random salt.
         
         """
-        salt = sha_constructor(str(random.random())).hexdigest()[:5]
+        salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
         username = user.username
         if isinstance(username, unicode):
             username = username.encode('utf-8')
-        activation_key = sha_constructor(salt+username).hexdigest()
+        activation_key = hashlib.sha1(salt+username).hexdigest()
         return self.create(user=user,
                            activation_key=activation_key)
         

registration/tests/backends.py

         self.old_activation = getattr(settings, 'ACCOUNT_ACTIVATION_DAYS', None)
         if self.old_activation is None:
             settings.ACCOUNT_ACTIVATION_DAYS = 7
-            
-        self.old_template_dirs = getattr(settings, 'TEMPLATE_DIRS', None)
-        settings.TEMPLATE_DIRS = (os.path.join(os.path.abspath(os.path.dirname(__file__)), 'tests/templates'))
-
+          
+        new_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'templates')
+        settings.TEMPLATE_DIRS = (new_path,)
+        app_template_dirs = (new_path,)
+          
     def tearDown(self):
         """
         Yank out ``ACCOUNT_ACTIVATION_DAYS`` back out if it wasn't

registration/tests/models.py

 import datetime
 import re
+import hashlib
+
 
 from django.conf import settings
 from django.contrib.auth.models import User
 from django.core import mail
 from django.core import management
 from django.test import TestCase
-from django.utils.hashcompat import sha_constructor
+#from django.utils.hashcompat import sha_constructor
+from django.contrib.sites.models import RequestSite
 
-from registration.models import RegistrationProfile
+
+from registration.models import RegistrationProfile 
+from backends import _mock_request
 
 
 class RegistrationModelTests(TestCase):
     def setUp(self):
         self.old_activation = getattr(settings, 'ACCOUNT_ACTIVATION_DAYS', None)
         settings.ACCOUNT_ACTIVATION_DAYS = 7
+        if Site._meta.installed:
+            self.site = Site.objects.get_current()
+        else:
+            request = _mock_request()
+            self.site = RequestSite(request)
 
     def tearDown(self):
         settings.ACCOUNT_ACTIVATION_DAYS = self.old_activation
         """
         new_user = User.objects.create_user(**self.user_info)
         profile = RegistrationProfile.objects.create_profile(new_user)
-        profile.send_activation_email(Site.objects.get_current())
+        profile.send_activation_email(self.site.objects.get_current())
         self.assertEqual(len(mail.outbox), 1)
         self.assertEqual(mail.outbox[0].to, [self.user_info['email']])
 
         user's account inactive.
         
         """
-        new_user = RegistrationProfile.objects.create_inactive_user(site=Site.objects.get_current(),
+        new_user = RegistrationProfile.objects.create_inactive_user(site=self.site.objects.get_current(),
                                                                     **self.user_info)
         self.assertEqual(new_user.username, 'alice')
         self.assertEqual(new_user.email, 'alice@example.com')
         By default, creating a new user sends an activation email.
         
         """
-        new_user = RegistrationProfile.objects.create_inactive_user(site=Site.objects.get_current(),
+        new_user = RegistrationProfile.objects.create_inactive_user(site=self.site.objects.get_current(),
                                                                     **self.user_info)
         self.assertEqual(len(mail.outbox), 1)
 
         send an activation email.
         
         """
-        new_user = RegistrationProfile.objects.create_inactive_user(site=Site.objects.get_current(),
+        new_user = RegistrationProfile.objects.create_inactive_user(site=self.site.objects.get_current(),
                                                                     send_email=False,
                                                                     **self.user_info)
         self.assertEqual(len(mail.outbox), 0)
         within the activation window.
         
         """
-        new_user = RegistrationProfile.objects.create_inactive_user(site=Site.objects.get_current(),
+        new_user = RegistrationProfile.objects.create_inactive_user(site=self.site.objects.get_current(),
                                                                     **self.user_info)
         profile = RegistrationProfile.objects.get(user=new_user)
         self.failIf(profile.activation_key_expired())
         outside the activation window.
         
         """
-        new_user = RegistrationProfile.objects.create_inactive_user(site=Site.objects.get_current(),
+        new_user = RegistrationProfile.objects.create_inactive_user(site=self.site.objects.get_current(),
                                                                     **self.user_info)
         new_user.date_joined -= datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS + 1)
         new_user.save()
         account active, and resets the activation key.
         
         """
-        new_user = RegistrationProfile.objects.create_inactive_user(site=Site.objects.get_current(),
+        new_user = RegistrationProfile.objects.create_inactive_user(site=self.site.objects.get_current(),
                                                                     **self.user_info)
         profile = RegistrationProfile.objects.get(user=new_user)
         activated = RegistrationProfile.objects.activate_user(profile.activation_key)
         activate the account.
         
         """
-        new_user = RegistrationProfile.objects.create_inactive_user(site=Site.objects.get_current(),
+        new_user = RegistrationProfile.objects.create_inactive_user(site=self.site.objects.get_current(),
                                                                     **self.user_info)
         new_user.date_joined -= datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS + 1)
         new_user.save()
         Attempting to re-activate an already-activated account fails.
         
         """
-        new_user = RegistrationProfile.objects.create_inactive_user(site=Site.objects.get_current(),
+        new_user = RegistrationProfile.objects.create_inactive_user(site=self.site.objects.get_current(),
                                                                     **self.user_info)
         profile = RegistrationProfile.objects.get(user=new_user)
         RegistrationProfile.objects.activate_user(profile.activation_key)
         """
         # Due to the way activation keys are constructed during
         # registration, this will never be a valid key.
-        invalid_key = sha_constructor('foo').hexdigest()
+        invalid_key = hashlib.sha1('foo').hexdigest()
         self.failIf(RegistrationProfile.objects.activate_user(invalid_key))
 
     def test_expired_user_deletion(self):
         deletes inactive users whose activation window has expired.
         
         """
-        new_user = RegistrationProfile.objects.create_inactive_user(site=Site.objects.get_current(),
+        new_user = RegistrationProfile.objects.create_inactive_user(site=self.site.objects.get_current(),
                                                                     **self.user_info)
-        expired_user = RegistrationProfile.objects.create_inactive_user(site=Site.objects.get_current(),
+        expired_user = RegistrationProfile.objects.create_inactive_user(site=self.site.objects.get_current(),
                                                                         username='bob',
                                                                         password='secret',
                                                                         email='bob@example.com')
         deletes expired accounts.
         
         """
-        new_user = RegistrationProfile.objects.create_inactive_user(site=Site.objects.get_current(),
+        new_user = RegistrationProfile.objects.create_inactive_user(site=self.site.objects.get_current(),
                                                                     **self.user_info)
-        expired_user = RegistrationProfile.objects.create_inactive_user(site=Site.objects.get_current(),
+        expired_user = RegistrationProfile.objects.create_inactive_user(site=self.site.objects.get_current(),
                                                                         username='bob',
                                                                         password='secret',
                                                                         email='bob@example.com')
Add a comment to this file

registration/tests/templates/registration/activate.html

Empty file added.

Add a comment to this file

registration/tests/templates/registration/activation_complete.html

Empty file added.

Add a comment to this file

registration/tests/templates/registration/activation_email.txt

Empty file added.

Add a comment to this file

registration/tests/templates/registration/activation_email_subject.txt

Empty file added.

registration/tests/templates/registration/login.html

+{% extends "registration/registration_base.html" %}
Add a comment to this file

registration/tests/templates/registration/logout.html

Empty file added.

registration/tests/templates/registration/password_change_done.html

+{% extends "registration/registration_base.html" %}
+

registration/tests/templates/registration/password_change_form.html

+{% extends "registration/registration_base.html" %}

registration/tests/templates/registration/password_reset_complete.html

+{% extends "registration/registration_base.html" %}

registration/tests/templates/registration/password_reset_confirm.html

+{% extends "registration/registration_base.html" %}

registration/tests/templates/registration/password_reset_done.html

+{% extends "registration/registration_base.html" %}
+{% block title %}Password reset{% endblock %}
+{% block content %}
+<p>
+We have sent you an email with a link to reset your password.  Please check
+your email and click the link to continue.
+</p>
+{% endblock %}

registration/tests/templates/registration/password_reset_email.html

+Greetings {{ user }},
+
+You are receiving this email because you (or someone pretending to be you)
+requested that your password be reset on {{ site.name }}.  If you do not 
+wish to reset your password, please ignore this message.
+
+To reset your password, please click the following link, or copy and paste it
+into your web browser:
+
+{{ protocol }}://{{ domain }}{% url auth_password_reset_confirm uid token %}
+
+Best regards,
+{{ site_name }} Management

registration/tests/templates/registration/password_reset_form.html

+{% extends "registration/registration_base.html" %}
Add a comment to this file

registration/tests/templates/registration/registration_base.html

Empty file added.

Add a comment to this file

registration/tests/templates/registration/registration_closed.html

Empty file added.

Add a comment to this file

registration/tests/templates/registration/registration_complete.html

Empty file added.

registration/tests/templates/registration/registration_form.html

+{% extends "registration/registration_base.html" %}
+
Add a comment to this file

registration/tests/templates/registration/test_template_name.html

Empty file added.

registration/tests/views.py

 import datetime
+import os
 
 from django.conf import settings
 from django.contrib.auth.models import User
 from django.core import mail
 from django.core.urlresolvers import reverse
 from django.test import TestCase
+from django.template.loaders.app_directories import app_template_dirs
 
 from registration import forms
 from registration.models import RegistrationProfile
         if self.old_activation is None:
             settings.ACCOUNT_ACTIVATION_DAYS = 7
             
-        settings.TEMPLATE_DIRS = (os.path.join(os.path.abspath(os.path.dirname(__file__)), 'tests/templates'))
+        new_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'templates')
+        settings.TEMPLATE_DIRS = (new_path,)
+        app_template_dirs = (new_path,)
 
     def tearDown(self):
         """
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.