Ticket #6943: 6943-nfa-admin-multiple-emails.diff

File 6943-nfa-admin-multiple-emails.diff, 2.4 KB (added by Michael Newman, 16 years ago)

New patch against New-Forms Admin r7612, with tests!

  • django/contrib/admin/sites.py

     
    231231                # Mistakenly entered e-mail address instead of username? Look it up.
    232232                try:
    233233                    user = User.objects.get(email=username)
    234                 except User.DoesNotExist:
     234                except (User.DoesNotExist, User.MultipleObjectsReturned):
    235235                    message = _("Usernames cannot contain the '@' character.")
    236236                else:
    237237                    message = _("Your e-mail address is not your username. Try '%s' instead.") % user.username
  • tests/regressiontests/admin_views/tests.py

     
    4646                     LOGIN_FORM_KEY: 1,
    4747                     'username': 'super',
    4848                     'password': 'secret'}
     49        self.super_email_login = {'post_data': _encode_post_data({}),
     50                     LOGIN_FORM_KEY: 1,
     51                     'username': 'super@example.com',
     52                     'password': 'secret'}
    4953        self.adduser_login = {'post_data': _encode_post_data({}),
    5054                     LOGIN_FORM_KEY: 1,
    5155                     'username': 'adduser',
     
    8084        self.assertFalse(login.context)
    8185        self.client.get('/test_admin/admin/logout/')
    8286       
     87        # Test if user enters e-mail address
     88        request = self.client.get('/test_admin/admin/')
     89        self.failUnlessEqual(request.status_code, 200)
     90        login = self.client.post('/test_admin/admin/', self.super_email_login)
     91        self.assertContains(login, "Your e-mail address is not your username")
     92        new_user = User(username='jondoe', password='secret', email='super@example.com')
     93        new_user.save()
     94        # check to ensure if there are multiple e-mail addresses a user doesn't get a 500
     95        login = self.client.post('/test_admin/admin/', self.super_email_login)
     96        self.assertContains(login, "Usernames cannot contain the '@' character")
     97       
    8398        # Add User
    8499        request = self.client.get('/test_admin/admin/')
    85100        self.failUnlessEqual(request.status_code, 200)
Back to Top