Ejemplo n.º 1
0
 def test_can_properly_choose_standard_users_with_usable_passwords(self):
     # Setup
     self.user.email = '*****@*****.**'
     self.user.save()
     # Run & check
     form = PasswordResetForm({})
     self.assertEqual(list(form.get_users('*****@*****.**')), [self.user, ])
Ejemplo n.º 2
0
 def test_cannot_choose_users_without_usable_passwords(self):
     # Setup
     self.user.set_unusable_password()
     self.user.email = '*****@*****.**'
     self.user.save()
     # Run & check
     form = PasswordResetForm({})
     self.assertFalse(len(list(form.get_users('*****@*****.**'))))
Ejemplo n.º 3
0
 def send_emails(self):
     pass_q = Q(password__startswith=UNUSABLE_PASSWORD_PREFIX)
     auth_q = Q(authorization__authorization_codename=
                "editor:can_manage_issuesubmission")
     recipients = User.objects.filter(pass_q & auth_q).distinct()
     PasswordResetForm.get_users = self._auth_get_users
     for recipient in recipients:
         form = PasswordResetForm({'email': recipient.email})
         if form.is_valid():
             form.save(
                 email_template_name='emails/auth/password_reset_email.html',
                 subject_template_name=
                 'emails/auth/password_reset_subject.txt')
             logger.info("Email sent to {}".format(recipient))
Ejemplo n.º 4
0
 def test_can_properly_send_the_reset_email(self):
     # Setup
     self.user.email = '*****@*****.**'
     self.user.save()
     form_data = {
         'email': '*****@*****.**',
     }
     # Run & check
     form = PasswordResetForm(form_data)
     self.assertTrue(form.is_valid())
     form.save(
         domain_override=None,
         subject_template_name='emails/auth/password_reset_subject.txt',
         email_template_name='emails/auth/password_reset_email.html',
         use_https=False, token_generator=default_token_generator,
         from_email=None, request=None, html_email_template_name=None)
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].to[0], '*****@*****.**')