Ticket #15750: previous_patch_and_tests.diff

File previous_patch_and_tests.diff, 2.3 KB (added by bedmondmark, 13 years ago)

Updated the previous patch to include passing tests.

  • django/core/mail/backends/smtp.py

     
    1818        super(EmailBackend, self).__init__(fail_silently=fail_silently)
    1919        self.host = host or settings.EMAIL_HOST
    2020        self.port = port or settings.EMAIL_PORT
    21         self.username = username or settings.EMAIL_HOST_USER
    22         self.password = password or settings.EMAIL_HOST_PASSWORD
     21        if username is None:
     22            self.username = settings.EMAIL_HOST_USER
     23        else:
     24            self.username = username
     25        if password is None:
     26            self.password = settings.EMAIL_HOST_PASSWORD
     27        else:
     28            self.password = password
    2329        if use_tls is None:
    2430            self.use_tls = settings.EMAIL_USE_TLS
    2531        else:
  • tests/regressiontests/mail/tests.py

     
    635635
    636636    def get_mailbox_content(self):
    637637        return self.server.get_sink()
     638
     639    @override_settings(EMAIL_HOST_USER="not empty username",
     640                        EMAIL_HOST_PASSWORD="not empty password")
     641    def test_email_authentication_use_settings(self):
     642        backend = smtp.EmailBackend()
     643        self.assertEqual(backend.username, 'not empty username')
     644        self.assertEqual(backend.password, 'not empty password')
     645
     646    @override_settings(EMAIL_HOST_USER="not empty username",
     647                        EMAIL_HOST_PASSWORD="not empty password")
     648    def test_email_authentication_override_settings(self):
     649        backend = smtp.EmailBackend(username='username', password='password')
     650        self.assertEqual(backend.username, 'username')
     651        self.assertEqual(backend.password, 'password')
     652
     653    @override_settings(EMAIL_HOST_USER="not empty username",
     654                        EMAIL_HOST_PASSWORD="not empty password")
     655    def test_email_disabled_authentication(self):
     656        backend = smtp.EmailBackend(username='', password='')
     657        self.assertEqual(backend.username, '')
     658        self.assertEqual(backend.password, '')
Back to Top