1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
1
# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
2
2
# See LICENSE for details.
7
5
Test cases for twisted.protocols.postfix module.
10
8
from twisted.trial import unittest
11
from twisted import protocols
12
from twisted import internet
13
from twisted.protocols import loopback
14
9
from twisted.protocols import postfix
15
from twisted.internet import defer, protocol
16
from twisted.test.test_protocols import StringIOWithoutClosing
10
from twisted.test.proto_helpers import StringTransport
18
13
class PostfixTCPMapQuoteTestCase(unittest.TestCase):
45
40
# (input, expected_output),
45
Test that I{get} and I{put} commands are responded to correctly by
46
L{postfix.PostfixTCPMapServer} when its factory is an instance of
47
L{postifx.PostfixTCPMapDictServerFactory}.
49
49
factory = postfix.PostfixTCPMapDictServerFactory(self.data)
50
output = StringIOWithoutClosing()
51
transport = internet.protocol.FileWrapper(output)
50
transport = StringTransport()
53
52
protocol = postfix.PostfixTCPMapServer()
54
53
protocol.service = factory
58
57
for input, expected_output in self.chat:
59
58
protocol.lineReceived(input)
61
self.assertEquals(output.getvalue(), expected_output,
62
'For %r, expected %r but got %r' % (
63
input, expected_output, output.getvalue()
60
transport.value(), expected_output,
61
'For %r, expected %r but got %r' % (
62
input, expected_output, transport.value()))
66
64
protocol.setTimeout(None)
68
def testDeferredChat(self):
67
def test_deferredChat(self):
69
Test that I{get} and I{put} commands are responded to correctly by
70
L{postfix.PostfixTCPMapServer} when its factory is an instance of
71
L{postifx.PostfixTCPMapDeferringDictServerFactory}.
69
73
factory = postfix.PostfixTCPMapDeferringDictServerFactory(self.data)
70
output = StringIOWithoutClosing()
71
transport = internet.protocol.FileWrapper(output)
74
transport = StringTransport()
73
76
protocol = postfix.PostfixTCPMapServer()
74
77
protocol.service = factory
78
81
for input, expected_output in self.chat:
79
82
protocol.lineReceived(input)
81
self.assertEquals(output.getvalue(), expected_output,
82
'For %r, expected %r but got %r' % (
83
input, expected_output, output.getvalue()
84
transport.value(), expected_output,
85
'For %r, expected %r but got %r' % (
86
input, expected_output, transport.value()))
86
88
protocol.setTimeout(None)
88
92
class Valid(PostfixTCPMapServerTestCase, unittest.TestCase):
90
94
'foo': 'ThisIs Foo',