summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/patchwork/models.py11
-rw-r--r--apps/patchwork/tests/registration.py40
2 files changed, 46 insertions, 5 deletions
diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py
index 22062c2..bb8d8e7 100644
--- a/apps/patchwork/models.py
+++ b/apps/patchwork/models.py
@@ -136,13 +136,14 @@ class UserProfile(models.Model):
def __unicode__(self):
return self.name()
-def _user_created_callback(sender, created, instance, **kwargs):
- if not created:
- return
- profile = UserProfile(user = instance)
+def _user_saved_callback(sender, created, instance, **kwargs):
+ try:
+ profile = instance.get_profile()
+ except UserProfile.DoesNotExist:
+ profile = UserProfile(user = instance)
profile.save()
-models.signals.post_save.connect(_user_created_callback, sender = User)
+models.signals.post_save.connect(_user_saved_callback, sender = User)
class State(models.Model):
name = models.CharField(max_length = 100)
diff --git a/apps/patchwork/tests/registration.py b/apps/patchwork/tests/registration.py
index 18b781f..08ed66a 100644
--- a/apps/patchwork/tests/registration.py
+++ b/apps/patchwork/tests/registration.py
@@ -147,4 +147,44 @@ class RegistrationConfirmationTest(TestCase):
self.assertTrue(conf.user.is_active)
self.assertFalse(conf.active)
+ def testRegistrationNewPersonSetup(self):
+ """ Check that the person object created after registration has the
+ correct details """
+
+ # register
+ self.assertEqual(EmailConfirmation.objects.count(), 0)
+ response = self.client.post('/register/', self.default_data)
+ self.assertEquals(response.status_code, 200)
+
+ # confirm
+ conf = EmailConfirmation.objects.filter()[0]
+ response = self.client.get(_confirmation_url(conf))
+ self.assertEquals(response.status_code, 200)
+
+ person = Person.objects.get(email = self.user.email)
+
+ self.assertEquals(person.name,
+ self.user.firstname + ' ' + self.user.lastname)
+
+ def testRegistrationExistingPersonSetup(self):
+ """ Check that the person object created after registration has the
+ correct details """
+
+ fullname = self.user.firstname + ' ' + self.user.lastname
+ person = Person(name = fullname, email = self.user.email)
+ person.save()
+
+ # register
+ self.assertEqual(EmailConfirmation.objects.count(), 0)
+ response = self.client.post('/register/', self.default_data)
+ self.assertEquals(response.status_code, 200)
+
+ # confirm
+ conf = EmailConfirmation.objects.filter()[0]
+ response = self.client.get(_confirmation_url(conf))
+ self.assertEquals(response.status_code, 200)
+
+ person = Person.objects.get(email = self.user.email)
+
+ self.assertEquals(person.name, fullname)