bug 558511, delete users good.

This commit is contained in:
Dave Dash 2010-08-19 16:38:11 -07:00
Родитель d1fb92ff06
Коммит 99e1ad8c96
3 изменённых файлов: 21 добавлений и 4 удалений

Просмотреть файл

@ -152,8 +152,17 @@ class UserProfile(amo.models.ModelBase):
if not self.resetcode_expires:
self.resetcode_expires = datetime.now()
delete_user = None
if self.deleted and self.user:
delete_user = self.user
self.user = None
# Delete user after saving this profile.
super(UserProfile, self).save(force_insert, force_update, using)
if self.deleted and delete_user:
delete_user.delete()
def check_password(self, raw_password):
if '$' not in self.password:
valid = (get_hexdigest('md5', '', raw_password) == self.password)

Просмотреть файл

@ -11,6 +11,7 @@ from nose.tools import eq_
import amo.test_utils
from amo.helpers import urlparams
from amo.urlresolvers import reverse
from users.models import UserProfile
class UserFormBase(amo.test_utils.ExtraSetup, test_utils.TestCase):
@ -104,7 +105,7 @@ class TestUserDeleteForm(UserFormBase):
data = {'password': 'foo', 'confirm': True, }
r = self.client.post('/en-US/firefox/users/delete', data, follow=True)
self.assertContains(r, "Profile Deleted")
u = User.objects.get(id='4043307').get_profile()
u = UserProfile.objects.get(id='4043307')
eq_(u.email, '')
@ -218,7 +219,8 @@ class TestUserLoginForm(UserFormBase):
r = self.client.post(url, {'username': 'jbalogh@mozilla.com',
'password': 'foo'}, follow=True)
self.assertNotContains(r, "Welcome, Jeff")
self.assertContains(r, "Wrong email address or password!")
self.assertContains(r, 'Please enter a correct username and password. '
'Note that both fields are case-sensitive.')
class TestUserRegisterForm(UserFormBase):

Просмотреть файл

@ -1,7 +1,6 @@
from datetime import date
import hashlib
from django import test
from django.contrib.auth.models import User
from django.core import mail
@ -23,9 +22,16 @@ class TestUserProfile(amo.test_utils.ExtraSetup, test_utils.TestCase):
u = User.objects.get(id='4043307').get_profile()
eq_(u.email, 'jbalogh@mozilla.com')
u.anonymize()
x = User.objects.get(id='4043307').get_profile()
x = UserProfile.objects.get(id='4043307')
eq_(x.email, "")
def test_delete(self):
"""Setting profile to delete should delete related User."""
u = User.objects.get(id='4043307').get_profile()
u.deleted = True
u.save()
eq_(len(User.objects.filter(id='4043307')), 0)
def test_email_confirmation_code(self):
u = User.objects.get(id='4043307').get_profile()
u.confirmationcode = 'blah'