~certify-web-dev/twisted/certify-staging

« back to all changes in this revision

Viewing changes to twisted/test/test_postfix.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-01-02 19:38:17 UTC
  • mfrom: (2.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100102193817-jphp464ppwh7dulg
Tags: 9.0.0-1
* python-twisted: Depend on the python-twisted-* 9.0 packages.
* python-twisted: Depend on python-zope.interface only. Closes: #557781.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
 
1
# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
2
2
# See LICENSE for details.
3
3
 
4
 
#
5
 
 
6
4
"""
7
5
Test cases for twisted.protocols.postfix module.
8
6
"""
9
7
 
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
 
11
 
17
12
 
18
13
class PostfixTCPMapQuoteTestCase(unittest.TestCase):
19
14
    data = [
45
40
        # (input, expected_output),
46
41
        ]
47
42
 
48
 
    def testChat(self):
 
43
    def test_chat(self):
 
44
        """
 
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}.
 
48
        """
49
49
        factory = postfix.PostfixTCPMapDictServerFactory(self.data)
50
 
        output = StringIOWithoutClosing()
51
 
        transport = internet.protocol.FileWrapper(output)
 
50
        transport = StringTransport()
52
51
 
53
52
        protocol = postfix.PostfixTCPMapServer()
54
53
        protocol.service = factory
57
56
 
58
57
        for input, expected_output in self.chat:
59
58
            protocol.lineReceived(input)
60
 
            # self.runReactor(1)
61
 
            self.assertEquals(output.getvalue(), expected_output,
62
 
                              'For %r, expected %r but got %r' % (
63
 
                input, expected_output, output.getvalue()
64
 
                ))
65
 
            output.truncate(0)
 
59
            self.assertEquals(
 
60
                transport.value(), expected_output,
 
61
                'For %r, expected %r but got %r' % (
 
62
                    input, expected_output, transport.value()))
 
63
            transport.clear()
66
64
        protocol.setTimeout(None)
67
65
 
68
 
    def testDeferredChat(self):
 
66
 
 
67
    def test_deferredChat(self):
 
68
        """
 
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}.
 
72
        """
69
73
        factory = postfix.PostfixTCPMapDeferringDictServerFactory(self.data)
70
 
        output = StringIOWithoutClosing()
71
 
        transport = internet.protocol.FileWrapper(output)
 
74
        transport = StringTransport()
72
75
 
73
76
        protocol = postfix.PostfixTCPMapServer()
74
77
        protocol.service = factory
77
80
 
78
81
        for input, expected_output in self.chat:
79
82
            protocol.lineReceived(input)
80
 
            # self.runReactor(1)
81
 
            self.assertEquals(output.getvalue(), expected_output,
82
 
                              'For %r, expected %r but got %r' % (
83
 
                input, expected_output, output.getvalue()
84
 
                ))
85
 
            output.truncate(0)
 
83
            self.assertEquals(
 
84
                transport.value(), expected_output,
 
85
                'For %r, expected %r but got %r' % (
 
86
                    input, expected_output, transport.value()))
 
87
            transport.clear()
86
88
        protocol.setTimeout(None)
87
89
 
 
90
 
 
91
 
88
92
class Valid(PostfixTCPMapServerTestCase, unittest.TestCase):
89
93
    data = {
90
94
        'foo': 'ThisIs Foo',