/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smtp_connection.py

  • Committer: James Henstridge
  • Date: 2007-10-10 03:43:04 UTC
  • mto: This revision was merged to the branch mainline in revision 2925.
  • Revision ID: james@jamesh.id.au-20071010034304-pnj843bv68xy151f
Fix test helper class naming, per John's review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    return smtp
39
39
 
40
40
 
41
 
class MockSMTPFactory(object):
 
41
class StubSMTPFactory(object):
42
42
    """A fake SMTP connection to test the connection setup."""
43
43
    def __init__(self, fail_on=None, smtp_features=None):
44
44
        self._fail_on = fail_on or []
121
121
        self.assertEqual(u'mypass', conn._smtp_password)
122
122
 
123
123
    def test_create_connection(self):
124
 
        mock = MockSMTPFactory()
125
 
        conn = self.get_connection('', smtp_factory=mock)
 
124
        factory = StubSMTPFactory()
 
125
        conn = self.get_connection('', smtp_factory=factory)
126
126
        conn._create_connection()
127
127
        self.assertEqual([('connect', 'localhost'),
128
128
                          ('ehlo',),
129
 
                          ('has_extn', 'starttls')], mock._calls)
 
129
                          ('has_extn', 'starttls')], factory._calls)
130
130
 
131
131
    def test_create_connection_ehlo_fails(self):
132
132
        # Check that we call HELO if EHLO failed.
133
 
        mock = MockSMTPFactory(fail_on=['ehlo'])
134
 
        conn = self.get_connection('', smtp_factory=mock)
 
133
        factory = StubSMTPFactory(fail_on=['ehlo'])
 
134
        conn = self.get_connection('', smtp_factory=factory)
135
135
        conn._create_connection()
136
136
        self.assertEqual([('connect', 'localhost'),
137
137
                          ('ehlo',),
138
138
                          ('helo',),
139
 
                          ('has_extn', 'starttls')], mock._calls)
 
139
                          ('has_extn', 'starttls')], factory._calls)
140
140
 
141
141
    def test_create_connection_ehlo_helo_fails(self):
142
142
        # Check that we raise an exception if both EHLO and HELO fail.
143
 
        mock = MockSMTPFactory(fail_on=['ehlo', 'helo'])
144
 
        conn = self.get_connection('', smtp_factory=mock)
 
143
        factory = StubSMTPFactory(fail_on=['ehlo', 'helo'])
 
144
        conn = self.get_connection('', smtp_factory=factory)
145
145
        self.assertRaises(errors.SMTPError, conn._create_connection)
146
146
        self.assertEqual([('connect', 'localhost'),
147
147
                          ('ehlo',),
148
 
                          ('helo',)], mock._calls)
 
148
                          ('helo',)], factory._calls)
149
149
 
150
150
    def test_create_connection_starttls(self):
151
151
        # Check that STARTTLS plus a second EHLO are called if the
152
152
        # server says it supports the feature.
153
 
        mock = MockSMTPFactory(smtp_features=['starttls'])
154
 
        conn = self.get_connection('', smtp_factory=mock)
 
153
        factory = StubSMTPFactory(smtp_features=['starttls'])
 
154
        conn = self.get_connection('', smtp_factory=factory)
155
155
        conn._create_connection()
156
156
        self.assertEqual([('connect', 'localhost'),
157
157
                          ('ehlo',),
158
158
                          ('has_extn', 'starttls'),
159
159
                          ('starttls',),
160
 
                          ('ehlo',)], mock._calls)
 
160
                          ('ehlo',)], factory._calls)
161
161
 
162
162
    def test_create_connection_starttls_fails(self):
163
163
        # Check that we raise an exception if the server claims to
164
164
        # support STARTTLS, but then fails when we try to activate it.
165
 
        mock = MockSMTPFactory(fail_on=['starttls'], smtp_features=['starttls'])
166
 
        conn = self.get_connection('', smtp_factory=mock)
 
165
        factory = StubSMTPFactory(fail_on=['starttls'],
 
166
                                  smtp_features=['starttls'])
 
167
        conn = self.get_connection('', smtp_factory=factory)
167
168
        self.assertRaises(errors.SMTPError, conn._create_connection)
168
169
        self.assertEqual([('connect', 'localhost'),
169
170
                          ('ehlo',),
170
171
                          ('has_extn', 'starttls'),
171
 
                          ('starttls',)], mock._calls)
 
172
                          ('starttls',)], factory._calls)
172
173
 
173
174
    def test_get_message_addresses(self):
174
175
        msg = Message()