1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2
# See LICENSE for details.
7
Test cases for twisted.protocols.postfix module.
10
from twisted.trial import unittest
11
from twisted import protocols
12
from twisted import internet
13
from twisted.protocols import loopback
14
from twisted.protocols import postfix
15
from twisted.internet import defer, protocol
16
from twisted.test.test_protocols import StringIOWithoutClosing
18
class PostfixTCPMapQuoteTestCase(unittest.TestCase):
20
# (raw, quoted, [aliasQuotedForms]),
22
('foo bar', 'foo%20bar'),
23
('foo\tbar', 'foo%09bar'),
24
('foo\nbar', 'foo%0Abar', 'foo%0abar'),
25
('foo\r\nbar', 'foo%0D%0Abar', 'foo%0D%0abar', 'foo%0d%0Abar', 'foo%0d%0abar'),
31
for entry in self.data:
35
self.assertEquals(postfix.quote(raw), quoted[0])
37
self.assertEquals(postfix.unquote(q), raw)
39
class PostfixTCPMapServerTestCase:
45
# (input, expected_output),
49
factory = postfix.PostfixTCPMapDictServerFactory(self.data)
50
output = StringIOWithoutClosing()
51
transport = internet.protocol.FileWrapper(output)
53
protocol = postfix.PostfixTCPMapServer()
54
protocol.service = factory
55
protocol.factory = factory
56
protocol.makeConnection(transport)
58
for input, expected_output in self.chat:
59
protocol.lineReceived(input)
61
self.assertEquals(output.getvalue(), expected_output,
62
'For %r, expected %r but got %r' % (
63
input, expected_output, output.getvalue()
66
protocol.setTimeout(None)
68
def testDeferredChat(self):
69
factory = postfix.PostfixTCPMapDeferringDictServerFactory(self.data)
70
output = StringIOWithoutClosing()
71
transport = internet.protocol.FileWrapper(output)
73
protocol = postfix.PostfixTCPMapServer()
74
protocol.service = factory
75
protocol.factory = factory
76
protocol.makeConnection(transport)
78
for input, expected_output in self.chat:
79
protocol.lineReceived(input)
81
self.assertEquals(output.getvalue(), expected_output,
82
'For %r, expected %r but got %r' % (
83
input, expected_output, output.getvalue()
86
protocol.setTimeout(None)
88
class Valid(PostfixTCPMapServerTestCase, unittest.TestCase):
91
'bar': ' bar really is found\r\n',
94
('get', "400 Command 'get' takes 1 parameters.\n"),
95
('get foo bar', "500 \n"),
96
('put', "400 Command 'put' takes 2 parameters.\n"),
97
('put foo', "400 Command 'put' takes 2 parameters.\n"),
98
('put foo bar baz', "500 put is not implemented yet.\n"),
99
('put foo bar', '500 put is not implemented yet.\n'),
100
('get foo', '200 ThisIs%20Foo\n'),
101
('get bar', '200 %20bar%20really%20is%20found%0D%0A\n'),
102
('get baz', '500 \n'),
103
('foo', '400 unknown command\n'),