101
101
conn = self.get_connection('[DEFAULT]\nsmtp_password=mypass\n')
102
102
self.assertEqual(u'mypass', conn._smtp_password)
104
def test_smtp_password_from_user(self):
107
conn = self.get_connection('[DEFAULT]\nsmtp_username=%s\n' % user,
108
smtp_factory=everybody_is_welcome)
109
self.assertIs(None, conn._smtp_password)
111
ui.ui_factory = tests.TestUIFactory(stdin=password + '\n',
112
stdout=tests.StringIOWrapper())
114
self.assertEqual(password, conn._smtp_password)
115
# stdin should be empty (the provided password have been consumed)
116
self.assertEqual('', ui.ui_factory.stdin.readline())
104
118
def test_smtp_password_from_auth_config(self):
106
120
password = 'hispass'
146
160
self.assertEqual('jrandom@example.com', from_)
147
161
self.assertEqual(sorted(['john@doe.com', 'jane@doe.com',
148
162
'pperez@ejemplo.com', 'user@localhost']), sorted(to))
149
164
def test_destination_address_required(self):
150
165
class FakeConfig:
151
166
def get_user_option(self, option):
166
181
self.assertRaises(
167
182
errors.NoDestinationAddress,
168
183
smtp_connection.SMTPConnection(FakeConfig()).send_email, msg)
171
class TestSMTPConnectionWithUI(tests.TestCaseInTempDir):
174
super(TestSMTPConnectionWithUI, self).setUp()
175
self.old_factory = ui.ui_factory
176
# The following has the unfortunate side-effect of hiding any ouput
177
# during the tests (including pdb prompts). Feel free to comment them
178
# for debugging purposes but leave them in place, there are needed to
179
# run the tests without any console
180
self.old_stdout = sys.stdout
181
sys.stdout = tests.StringIOWrapper()
182
self.addCleanup(self.restoreUIFactory)
184
def restoreUIFactory(self):
185
ui.ui_factory = self.old_factory
186
sys.stdout = self.old_stdout
188
def get_connection(self, text, smtp_factory=None):
189
return _get_connection(text, smtp_factory)
191
def test_smtp_password_from_user(self):
194
conn = self.get_connection('[DEFAULT]\nsmtp_username=%s\n' % user,
195
smtp_factory=everybody_is_welcome)
196
self.assertIs(None, conn._smtp_password)
198
ui.ui_factory = tests.TestUIFactory(stdin=password + '\n')
200
self.assertEqual(password, conn._smtp_password)
201
# stdin should be empty (the provided password have been consumed)
202
self.assertEqual('', ui.ui_factory.stdin.readline())