Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: third_party/twisted_8_1/twisted/test/test_postfix.py

Issue 12261012: Remove third_party/twisted_8_1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 #
5
6 """
7 Test cases for twisted.protocols.postfix module.
8 """
9
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
17
18 class PostfixTCPMapQuoteTestCase(unittest.TestCase):
19 data = [
20 # (raw, quoted, [aliasQuotedForms]),
21 ('foo', 'foo'),
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%0 abar'),
26 ('foo ', 'foo%20'),
27 (' foo', '%20foo'),
28 ]
29
30 def testData(self):
31 for entry in self.data:
32 raw = entry[0]
33 quoted = entry[1:]
34
35 self.assertEquals(postfix.quote(raw), quoted[0])
36 for q in quoted:
37 self.assertEquals(postfix.unquote(q), raw)
38
39 class PostfixTCPMapServerTestCase:
40 data = {
41 # 'key': 'value',
42 }
43
44 chat = [
45 # (input, expected_output),
46 ]
47
48 def testChat(self):
49 factory = postfix.PostfixTCPMapDictServerFactory(self.data)
50 output = StringIOWithoutClosing()
51 transport = internet.protocol.FileWrapper(output)
52
53 protocol = postfix.PostfixTCPMapServer()
54 protocol.service = factory
55 protocol.factory = factory
56 protocol.makeConnection(transport)
57
58 for input, expected_output in self.chat:
59 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)
66 protocol.setTimeout(None)
67
68 def testDeferredChat(self):
69 factory = postfix.PostfixTCPMapDeferringDictServerFactory(self.data)
70 output = StringIOWithoutClosing()
71 transport = internet.protocol.FileWrapper(output)
72
73 protocol = postfix.PostfixTCPMapServer()
74 protocol.service = factory
75 protocol.factory = factory
76 protocol.makeConnection(transport)
77
78 for input, expected_output in self.chat:
79 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)
86 protocol.setTimeout(None)
87
88 class Valid(PostfixTCPMapServerTestCase, unittest.TestCase):
89 data = {
90 'foo': 'ThisIs Foo',
91 'bar': ' bar really is found\r\n',
92 }
93 chat = [
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'),
104 ]
OLDNEW
« no previous file with comments | « third_party/twisted_8_1/twisted/test/test_policies.py ('k') | third_party/twisted_8_1/twisted/test/test_process.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698