61
59
self.assertEquals(warnings[0]['message'], msg)
64
def test_barePort(self):
66
A bare port passed to I{--pop3} results in deprecation warning in
67
addition to a TCP4ServerEndpoint.
70
options.parseOptions(['--pop3', '8110'])
71
self.assertEquals(len(options['pop3']), 1)
72
self.assertIsInstance(
73
options['pop3'][0], endpoints.TCP4ServerEndpoint)
74
warnings = self.flushWarnings([options.opt_pop3])
75
self.assertEquals(len(warnings), 1)
76
self.assertEquals(warnings[0]['category'], DeprecationWarning)
78
warnings[0]['message'],
79
"Specifying plain ports and/or a certificate is deprecated since "
80
"Twisted 11.0; use endpoint descriptions instead.")
83
def _endpointTest(self, service):
85
Use L{Options} to parse a single service configuration parameter and
86
verify that an endpoint of the correct type is added to the list for
90
options.parseOptions(['--' + service, 'tcp:1234'])
91
self.assertEquals(len(options[service]), 1)
92
self.assertIsInstance(
93
options[service][0], endpoints.TCP4ServerEndpoint)
96
def test_endpointSMTP(self):
98
When I{--smtp} is given a TCP endpoint description as an argument, a
99
TCPServerEndpoint is added to the list of SMTP endpoints.
101
self._endpointTest('smtp')
104
def test_endpointPOP3(self):
106
When I{--pop3} is given a TCP endpoint description as an argument, a
107
TCPServerEndpoint is added to the list of POP3 endpoints.
109
self._endpointTest('pop3')
112
def test_protoDefaults(self):
114
POP3 and SMTP each listen on a TCP4ServerEndpoint by default.
117
options.parseOptions([])
119
self.assertEquals(len(options['pop3']), 1)
120
self.assertIsInstance(
121
options['pop3'][0], endpoints.TCP4ServerEndpoint)
123
self.assertEquals(len(options['smtp']), 1)
124
self.assertIsInstance(
125
options['smtp'][0], endpoints.TCP4ServerEndpoint)
128
def test_protoDisable(self):
130
The I{--no-pop3} and I{--no-smtp} options disable POP3 and SMTP
134
options.parseOptions(['--no-pop3'])
135
self.assertEquals(options._getEndpoints(None, 'pop3'), [])
136
self.assertNotEquals(options._getEndpoints(None, 'smtp'), [])
139
options.parseOptions(['--no-smtp'])
140
self.assertNotEquals(options._getEndpoints(None, 'pop3'), [])
141
self.assertEquals(options._getEndpoints(None, 'smtp'), [])
144
def test_allProtosDisabledError(self):
146
If all protocols are disabled, L{UsageError} is raised.
150
UsageError, options.parseOptions, (['--no-pop3', '--no-smtp']))
153
def test_pop3sBackwardCompatibility(self):
155
The deprecated I{--pop3s} and I{--certificate} options set up a POP3 SSL
159
options.parseOptions(['--pop3s', '8995',
160
'--certificate', '/dev/null'])
161
self.assertEquals(len(options['pop3']), 2)
162
self.assertIsInstance(
163
options['pop3'][0], endpoints.SSL4ServerEndpoint)
164
self.assertIsInstance(
165
options['pop3'][1], endpoints.TCP4ServerEndpoint)
167
warnings = self.flushWarnings([options.postOptions])
168
self.assertEquals(len(warnings), 1)
169
self.assertEquals(warnings[0]['category'], DeprecationWarning)
171
warnings[0]['message'],
172
"Specifying plain ports and/or a certificate is deprecated since "
173
"Twisted 11.0; use endpoint descriptions instead.")
177
class SpyEndpoint(object):
179
SpyEndpoint remembers what factory it is told to listen with.
182
def listen(self, factory):
183
self.listeningWith = factory
184
return defer.succeed(None)
188
class MakeServiceTests(TestCase):
190
Tests for L{twisted.mail.tap.makeService}
192
def _endpointServerTest(self, key, factoryClass):
194
Configure a service with two endpoints for the protocol associated with
195
C{key} and verify that when the service is started a factory of type
196
C{factoryClass} is used to listen on each of them.
198
cleartext = SpyEndpoint()
199
secure = SpyEndpoint()
201
config[key] = [cleartext, secure]
202
service = makeService(config)
203
service.privilegedStartService()
204
service.startService()
205
self.addCleanup(service.stopService)
206
self.assertIsInstance(cleartext.listeningWith, factoryClass)
207
self.assertIsInstance(secure.listeningWith, factoryClass)
212
If one or more endpoints is included in the configuration passed to
213
L{makeService} for the C{"pop3"} key, a service for starting a POP3
214
server is constructed for each of them and attached to the returned
217
self._endpointServerTest("pop3", protocols.POP3Factory)
222
If one or more endpoints is included in the configuration passed to
223
L{makeService} for the C{"smtp"} key, a service for starting an SMTP
224
server is constructed for each of them and attached to the returned
227
self._endpointServerTest("smtp", protocols.SMTPFactory)