Commits

James Bennett  committed daa764e

Restore the ability to disable email sending on creation of an account.

  • Participants
  • Parent commits 8ca23d5

Comments (0)

Files changed (2)

File registration/models.py

                 return user
         return False
     
-    def create_inactive_user(self, username, email, password, site):
+    def create_inactive_user(self, username, email, password,
+                             site, send_email=True):
         """
         Create a new, inactive ``User``, generate a
         ``RegistrationProfile`` and email its activation key to the
         ``User``, returning the new ``User``.
+
+        By default, an activation email will be sent to the new
+        user. To disable this, pass ``send_email=False``.
         
         """
         new_user = User.objects.create_user(username, email, password)
         new_user.save()
 
         registration_profile = self.create_profile(new_user)
-        self.send_activation_email(registration_profile, site)
+
+        if send_email:
+            self.send_activation_email(registration_profile, site)
 
         return new_user
     create_inactive_user = transaction.commit_on_success(create_inactive_user)

File registration/tests/models.py

                                                                     **self.user_info)
         self.assertEqual(len(mail.outbox), 1)
 
+    def test_user_creation_no_email(self):
+        """
+        Passing ``send_email=False`` when creating a new user will not
+        send an activation email.
+        
+        """
+        new_user = RegistrationProfile.objects.create_inactive_user(site=Site.objects.get_current(),
+                                                                    send_email=False,
+                                                                    **self.user_info)
+        self.assertEqual(len(mail.outbox), 0)
+
     def test_unexpired_account(self):
         """
         ``RegistrationProfile.activation_key_expired()`` is ``False``