summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_nntplib.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-02-15 17:53:49 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-02-15 17:53:49 (GMT)
commit482ee66cb7075b917a0a93051536ed0c10586447 (patch)
tree22547386eefe3bcf0602aca835a649e82dacad75 /Lib/test/test_nntplib.py
parent43df889d63707081bca200db9c33f3d79ed616ad (diff)
parent2640b5223765f7a8e9c13a4a4c82dafa2c7cb59a (diff)
downloadcpython-482ee66cb7075b917a0a93051536ed0c10586447.zip
cpython-482ee66cb7075b917a0a93051536ed0c10586447.tar.gz
cpython-482ee66cb7075b917a0a93051536ed0c10586447.tar.bz2
Issue #7644: Add tests for the file argument of NNTP.head() and NNTP.body().
Patch by Hynek Schlawack.
Diffstat (limited to 'Lib/test/test_nntplib.py')
-rw-r--r--Lib/test/test_nntplib.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_nntplib.py b/Lib/test/test_nntplib.py
index bfc9f41..c5146c1 100644
--- a/Lib/test/test_nntplib.py
+++ b/Lib/test/test_nntplib.py
@@ -1000,6 +1000,26 @@ class NNTPv1v2TestsMixin:
self.server.head("<non-existent@example.com>")
self.assertEqual(cm.exception.response, "430 No Such Article Found")
+ def test_head_file(self):
+ f = io.BytesIO()
+ resp, info = self.server.head(file=f)
+ self.assertEqual(resp, "221 3000237 <45223423@example.com>")
+ art_num, message_id, lines = info
+ self.assertEqual(art_num, 3000237)
+ self.assertEqual(message_id, "<45223423@example.com>")
+ self.assertEqual(lines, [])
+ data = f.getvalue()
+ self.assertTrue(data.startswith(
+ b'From: "Demo User" <nobody@example.net>\r\n'
+ b'Subject: I am just a test article\r\n'
+ ), ascii(data))
+ self.assertFalse(data.endswith(
+ b'This is just a test article.\r\n'
+ b'.Here is a dot-starting line.\r\n'
+ b'\r\n'
+ b'-- Signed by Andr\xc3\xa9.\r\n'
+ ), ascii(data))
+
def test_body(self):
# BODY
resp, info = self.server.body()
@@ -1027,6 +1047,26 @@ class NNTPv1v2TestsMixin:
self.server.body("<non-existent@example.com>")
self.assertEqual(cm.exception.response, "430 No Such Article Found")
+ def test_body_file(self):
+ f = io.BytesIO()
+ resp, info = self.server.body(file=f)
+ self.assertEqual(resp, "222 3000237 <45223423@example.com>")
+ art_num, message_id, lines = info
+ self.assertEqual(art_num, 3000237)
+ self.assertEqual(message_id, "<45223423@example.com>")
+ self.assertEqual(lines, [])
+ data = f.getvalue()
+ self.assertFalse(data.startswith(
+ b'From: "Demo User" <nobody@example.net>\r\n'
+ b'Subject: I am just a test article\r\n'
+ ), ascii(data))
+ self.assertTrue(data.endswith(
+ b'This is just a test article.\r\n'
+ b'.Here is a dot-starting line.\r\n'
+ b'\r\n'
+ b'-- Signed by Andr\xc3\xa9.\r\n'
+ ), ascii(data))
+
def check_over_xover_resp(self, resp, overviews):
self.assertTrue(resp.startswith("224 "), resp)
self.assertEqual(len(overviews), 3)