'Make sure opening a connection creates a new file'

def test_file_sessions(self):

    msg = EmailMessage(u'Subject', u'Content', u'bounce@example.com', [u'to@example.com'], headers={u'From': u'from@example.com'})
    connection = mail.get_connection()
    connection.send_messages([msg])
    self.assertEqual(len(os.listdir(self.tmp_dir)), 1)
    with open(os.path.join(self.tmp_dir, os.listdir(self.tmp_dir)[0]), u'rb') as fp:
        message = message_from_binary_file(fp)
    self.assertEqual(message.get_content_type(), u'text/plain')
    self.assertEqual(message.get(u'subject'), u'Subject')
    self.assertEqual(message.get(u'from'), u'from@example.com')
    self.assertEqual(message.get(u'to'), u'to@example.com')
    connection2 = mail.get_connection()
    connection2.send_messages([msg])
    self.assertEqual(len(os.listdir(self.tmp_dir)), 2)
    connection.send_messages([msg])
    self.assertEqual(len(os.listdir(self.tmp_dir)), 2)
    msg.connection = mail.get_connection()
    self.assertTrue(connection.open())
    msg.send()
    self.assertEqual(len(os.listdir(self.tmp_dir)), 3)
    msg.send()
    self.assertEqual(len(os.listdir(self.tmp_dir)), 3)
    connection.close()
