'Test connection argument to send_mail(), et. al.'

@override_settings(EMAIL_BACKEND=u'django.core.mail.backends.locmem.EmailBackend', ADMINS=[(u'nobody', u'nobody@example.com')], MANAGERS=[(u'nobody', u'nobody@example.com')])
def test_connection_arg(self):

    mail.outbox = []
    connection = mail.get_connection(u'mail.custombackend.EmailBackend')
    send_mail(u'Subject', u'Content', u'from@example.com', [u'to@example.com'], connection=connection)
    self.assertEqual(mail.outbox, [])
    self.assertEqual(len(connection.test_outbox), 1)
    self.assertEqual(connection.test_outbox[0].subject, u'Subject')
    connection = mail.get_connection(u'mail.custombackend.EmailBackend')
    send_mass_mail([(u'Subject1', u'Content1', u'from1@example.com', [u'to1@example.com']), (u'Subject2', u'Content2', u'from2@example.com', [u'to2@example.com'])], connection=connection)
    self.assertEqual(mail.outbox, [])
    self.assertEqual(len(connection.test_outbox), 2)
    self.assertEqual(connection.test_outbox[0].subject, u'Subject1')
    self.assertEqual(connection.test_outbox[1].subject, u'Subject2')
    connection = mail.get_connection(u'mail.custombackend.EmailBackend')
    mail_admins(u'Admin    message', u'Content', connection=connection)
    self.assertEqual(mail.outbox, [])
    self.assertEqual(len(connection.test_outbox), 1)
    self.assertEqual(connection.test_outbox[0].subject, u'[Django]    Admin    message')
    connection = mail.get_connection(u'mail.custombackend.EmailBackend')
    mail_managers(u'Manager    message', u'Content', connection=connection)
    self.assertEqual(mail.outbox, [])
    self.assertEqual(len(connection.test_outbox), 1)
    self.assertEqual(connection.test_outbox[0].subject, u'[Django]    Manager    message')
