Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(245882)

Side by Side Diff: Lib/test/test_poplib.py

Issue 21804: Implement thr UTF8 command (RFC 6856) in poplib.
Patch Set: Created 5 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/poplib.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Test script for poplib module.""" 1 """Test script for poplib module."""
2 2
3 # Modified by Giampaolo Rodola' to give poplib.POP3 and poplib.POP3_SSL 3 # Modified by Giampaolo Rodola' to give poplib.POP3 and poplib.POP3_SSL
4 # a real test suite 4 # a real test suite
5 5
6 import poplib 6 import poplib
7 import asyncore 7 import asyncore
8 import asynchat 8 import asynchat
9 import socket 9 import socket
10 import os 10 import os
(...skipping 29 matching lines...) Expand all
40 \r\n\ 40 \r\n\
41 line1\r\n\ 41 line1\r\n\
42 line2\r\n\ 42 line2\r\n\
43 line3\r\n\ 43 line3\r\n\
44 .\r\n""" 44 .\r\n"""
45 45
46 46
47 class DummyPOP3Handler(asynchat.async_chat): 47 class DummyPOP3Handler(asynchat.async_chat):
48 48
49 CAPAS = {'UIDL': [], 'IMPLEMENTATION': ['python-testlib-pop-server']} 49 CAPAS = {'UIDL': [], 'IMPLEMENTATION': ['python-testlib-pop-server']}
50 enable_UTF8 = False
50 51
51 def __init__(self, conn): 52 def __init__(self, conn):
52 asynchat.async_chat.__init__(self, conn) 53 asynchat.async_chat.__init__(self, conn)
53 self.set_terminator(b"\r\n") 54 self.set_terminator(b"\r\n")
54 self.in_buffer = [] 55 self.in_buffer = []
55 self.push('+OK dummy pop3 server ready. <timestamp>') 56 self.push('+OK dummy pop3 server ready. <timestamp>')
56 self.tls_active = False 57 self.tls_active = False
57 self.tls_starting = False 58 self.tls_starting = False
58 59
59 def collect_incoming_data(self, data): 60 def collect_incoming_data(self, data):
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 138
138 def cmd_capa(self, arg): 139 def cmd_capa(self, arg):
139 self.push('+OK Capability list follows') 140 self.push('+OK Capability list follows')
140 if self._get_capas(): 141 if self._get_capas():
141 for cap, params in self._get_capas().items(): 142 for cap, params in self._get_capas().items():
142 _ln = [cap] 143 _ln = [cap]
143 if params: 144 if params:
144 _ln.extend(params) 145 _ln.extend(params)
145 self.push(' '.join(_ln)) 146 self.push(' '.join(_ln))
146 self.push('.') 147 self.push('.')
148
149 def cmd_utf8(self, arg):
150 self.push('+OK I know RFC6856'
151 if self.enable_UTF8
152 else '-ERR What is UTF8?!')
147 153
148 if SUPPORTS_SSL: 154 if SUPPORTS_SSL:
149 155
150 def cmd_stls(self, arg): 156 def cmd_stls(self, arg):
151 if self.tls_active is False: 157 if self.tls_active is False:
152 self.push('+OK Begin TLS negotiation') 158 self.push('+OK Begin TLS negotiation')
153 tls_sock = ssl.wrap_socket(self.socket, certfile=CERTFILE, 159 tls_sock = ssl.wrap_socket(self.socket, certfile=CERTFILE,
154 server_side=True, 160 server_side=True,
155 do_handshake_on_connect=False, 161 do_handshake_on_connect=False,
156 suppress_ragged_eofs=False) 162 suppress_ragged_eofs=False)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 expected = (b'+OK 116 bytes', 310 expected = (b'+OK 116 bytes',
305 [b'From: postmaster@python.org', b'Content-Type: text/plain ', 311 [b'From: postmaster@python.org', b'Content-Type: text/plain ',
306 b'MIME-Version: 1.0', b'Subject: Dummy', b'', 312 b'MIME-Version: 1.0', b'Subject: Dummy', b'',
307 b'line1', b'line2', b'line3'], 313 b'line1', b'line2', b'line3'],
308 113) 314 113)
309 self.assertEqual(self.client.top(1, 1), expected) 315 self.assertEqual(self.client.top(1, 1), expected)
310 316
311 def test_uidl(self): 317 def test_uidl(self):
312 self.client.uidl() 318 self.client.uidl()
313 self.client.uidl('foo') 319 self.client.uidl('foo')
320
321 def test_utf8_raises_if_unsupported(self):
322 self.server.handler.enable_UTF8 = False
323 self.assertRaises(poplib.error_proto, self.client.utf8)
324
325 def test_utf8(self):
326 self.server.handler.enable_UTF8 = True
327 expected = b'+OK I know RFC6856'
328 result = self.client.utf8()
329 self.assertEqual(result, expected)
314 330
315 def test_capa(self): 331 def test_capa(self):
316 capa = self.client.capa() 332 capa = self.client.capa()
317 self.assertTrue('IMPLEMENTATION' in capa.keys()) 333 self.assertTrue('IMPLEMENTATION' in capa.keys())
318 334
319 def test_quit(self): 335 def test_quit(self):
320 resp = self.client.quit() 336 resp = self.client.quit()
321 self.assertTrue(resp) 337 self.assertTrue(resp)
322 self.assertIsNone(self.client.sock) 338 self.assertIsNone(self.client.sock)
323 self.assertIsNone(self.client.file) 339 self.assertIsNone(self.client.file)
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 TestPOP3_SSLClass, TestPOP3_TLSClass] 509 TestPOP3_SSLClass, TestPOP3_TLSClass]
494 thread_info = test_support.threading_setup() 510 thread_info = test_support.threading_setup()
495 try: 511 try:
496 test_support.run_unittest(*tests) 512 test_support.run_unittest(*tests)
497 finally: 513 finally:
498 test_support.threading_cleanup(*thread_info) 514 test_support.threading_cleanup(*thread_info)
499 515
500 516
501 if __name__ == '__main__': 517 if __name__ == '__main__':
502 test_main() 518 test_main()
OLDNEW
« no previous file with comments | « Lib/poplib.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+