Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
test.test_nntplib.NNTPv1Tests Class Reference
Inheritance diagram for test.test_nntplib.NNTPv1Tests:
Inheritance graph
[legend]
Collaboration diagram for test.test_nntplib.NNTPv1Tests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_caps
def setUp
def test_welcome
def test_date
def test_quit
def test_help
def test_list
def test_stat
def test_next
def test_last
def test_description
def test_descriptions
def test_group
def test_newnews
def test_article
def test_article_file
def test_head
def test_body
def check_over_xover_resp
def test_xover
def test_over
def check_post_ihave
def test_post
def test_ihave
def setUp
def tearDown
def make_server

Public Attributes

 handler
 sio
 server

Static Public Attributes

int nntp_version = 1
 handler_class = NNTPv1Handler
tuple sample_post

Detailed Description

Tests an NNTP v1 server (no capabilities).

Definition at line 1041 of file test_nntplib.py.


Member Function Documentation

def test.test_nntplib.NNTPv1v2TestsMixin.check_over_xover_resp (   self,
  resp,
  overviews 
) [inherited]

Definition at line 934 of file test_nntplib.py.

00934 
00935     def check_over_xover_resp(self, resp, overviews):
00936         self.assertTrue(resp.startswith("224 "), resp)
00937         self.assertEqual(len(overviews), 3)
00938         art_num, over = overviews[0]
00939         self.assertEqual(art_num, 57)
00940         self.assertEqual(over, {
00941             "from": "Doug Hellmann <doug.hellmann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>",
00942             "subject": "Re: ANN: New Plone book with strong Python (and Zope) themes throughout",
00943             "date": "Sat, 19 Jun 2010 18:04:08 -0400",
00944             "message-id": "<4FD05F05-F98B-44DC-8111-C6009C925F0C@gmail.com>",
00945             "references": "<hvalf7$ort$1@dough.gmane.org>",
00946             ":bytes": "7103",
00947             ":lines": "16",
00948             "xref": "news.gmane.org gmane.comp.python.authors:57"
00949             })
00950         art_num, over = overviews[1]
00951         self.assertEqual(over["xref"], None)
00952         art_num, over = overviews[2]
00953         self.assertEqual(over["subject"],
00954                          "Re: Message d'erreur incompréhensible (par moi)")

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_nntplib.NNTPv1v2TestsMixin.check_post_ihave (   self,
  func,
  success_resp,
  args 
) [inherited]

Definition at line 1003 of file test_nntplib.py.

01003 
01004     def check_post_ihave(self, func, success_resp, *args):
01005         # With a bytes object
01006         resp = self._check_post_ihave_sub(func, *args, file_factory=bytes)
01007         self.assertEqual(resp, success_resp)
01008         # With a bytearray object
01009         resp = self._check_post_ihave_sub(func, *args, file_factory=bytearray)
01010         self.assertEqual(resp, success_resp)
01011         # With a file object
01012         resp = self._check_post_ihave_sub(func, *args, file_factory=io.BytesIO)
01013         self.assertEqual(resp, success_resp)
01014         # With an iterable of terminated lines
01015         def iterlines(b):
01016             return iter(b.splitlines(True))
01017         resp = self._check_post_ihave_sub(func, *args, file_factory=iterlines)
01018         self.assertEqual(resp, success_resp)
01019         # With an iterable of non-terminated lines
01020         def iterlines(b):
01021             return iter(b.splitlines(False))
01022         resp = self._check_post_ihave_sub(func, *args, file_factory=iterlines)
01023         self.assertEqual(resp, success_resp)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_nntplib.MockedNNTPTestsMixin.make_server (   self,
  args,
  kwargs 
) [inherited]

Definition at line 358 of file test_nntplib.py.

00358 
00359     def make_server(self, *args, **kwargs):
00360         self.handler = self.handler_class()
00361         self.sio = _NNTPServerIO(self.handler)
00362         # Using BufferedRWPair instead of BufferedRandom ensures the file
00363         # isn't seekable.
00364         file = io.BufferedRWPair(self.sio, self.sio)
00365         self.server = nntplib._NNTPBase(file, 'test.server', *args, **kwargs)
00366         return self.server
00367 

Here is the caller graph for this function:

Definition at line 350 of file test_nntplib.py.

00350 
00351     def setUp(self):
00352         super().setUp()
00353         self.make_server()

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_nntplib.NNTPv1v2TestsMixin.setUp (   self) [inherited]

Definition at line 693 of file test_nntplib.py.

00693 
00694     def setUp(self):
00695         super().setUp()

Here is the caller graph for this function:

Definition at line 354 of file test_nntplib.py.

00354 
00355     def tearDown(self):
00356         super().tearDown()
00357         del self.server

Here is the caller graph for this function:

Definition at line 832 of file test_nntplib.py.

00832 
00833     def test_article(self):
00834         # ARTICLE
00835         resp, info = self.server.article()
00836         self.assertEqual(resp, "220 3000237 <45223423@example.com>")
00837         art_num, message_id, lines = info
00838         self.assertEqual(art_num, 3000237)
00839         self.assertEqual(message_id, "<45223423@example.com>")
00840         self._check_article_data(lines)
00841         # ARTICLE num
00842         resp, info = self.server.article(3000234)
00843         self.assertEqual(resp, "220 3000234 <45223423@example.com>")
00844         art_num, message_id, lines = info
00845         self.assertEqual(art_num, 3000234)
00846         self.assertEqual(message_id, "<45223423@example.com>")
00847         self._check_article_data(lines)
00848         # ARTICLE id
00849         resp, info = self.server.article("<45223423@example.com>")
00850         self.assertEqual(resp, "220 0 <45223423@example.com>")
00851         art_num, message_id, lines = info
00852         self.assertEqual(art_num, 0)
00853         self.assertEqual(message_id, "<45223423@example.com>")
00854         self._check_article_data(lines)
00855         # Non-existent id
00856         with self.assertRaises(nntplib.NNTPTemporaryError) as cm:
00857             self.server.article("<non-existent@example.com>")
00858         self.assertEqual(cm.exception.response, "430 No Such Article Found")

Here is the call graph for this function:

Definition at line 859 of file test_nntplib.py.

00859 
00860     def test_article_file(self):
00861         # With a "file" argument
00862         f = io.BytesIO()
00863         resp, info = self.server.article(file=f)
00864         self.assertEqual(resp, "220 3000237 <45223423@example.com>")
00865         art_num, message_id, lines = info
00866         self.assertEqual(art_num, 3000237)
00867         self.assertEqual(message_id, "<45223423@example.com>")
00868         self.assertEqual(lines, [])
00869         data = f.getvalue()
00870         self.assertTrue(data.startswith(
00871             b'From: "Demo User" <nobody@example.net>\r\n'
00872             b'Subject: I am just a test article\r\n'
00873             ), ascii(data))
00874         self.assertTrue(data.endswith(
00875             b'This is just a test article.\r\n'
00876             b'.Here is a dot-starting line.\r\n'
00877             b'\r\n'
00878             b'-- Signed by Andr\xc3\xa9.\r\n'
00879             ), ascii(data))

Here is the call graph for this function:

Definition at line 907 of file test_nntplib.py.

00907 
00908     def test_body(self):
00909         # BODY
00910         resp, info = self.server.body()
00911         self.assertEqual(resp, "222 3000237 <45223423@example.com>")
00912         art_num, message_id, lines = info
00913         self.assertEqual(art_num, 3000237)
00914         self.assertEqual(message_id, "<45223423@example.com>")
00915         self._check_article_body(lines)
00916         # BODY num
00917         resp, info = self.server.body(3000234)
00918         self.assertEqual(resp, "222 3000234 <45223423@example.com>")
00919         art_num, message_id, lines = info
00920         self.assertEqual(art_num, 3000234)
00921         self.assertEqual(message_id, "<45223423@example.com>")
00922         self._check_article_body(lines)
00923         # BODY id
00924         resp, info = self.server.body("<45223423@example.com>")
00925         self.assertEqual(resp, "222 0 <45223423@example.com>")
00926         art_num, message_id, lines = info
00927         self.assertEqual(art_num, 0)
00928         self.assertEqual(message_id, "<45223423@example.com>")
00929         self._check_article_body(lines)
00930         # Non-existent id
00931         with self.assertRaises(nntplib.NNTPTemporaryError) as cm:
00932             self.server.body("<non-existent@example.com>")
00933         self.assertEqual(cm.exception.response, "430 No Such Article Found")

Here is the call graph for this function:

Definition at line 1047 of file test_nntplib.py.

01047 
01048     def test_caps(self):
01049         caps = self.server.getcapabilities()
01050         self.assertEqual(caps, {})
01051         self.assertEqual(self.server.nntp_version, 1)
01052         self.assertEqual(self.server.nntp_implementation, None)
01053 

Here is the call graph for this function:

Definition at line 699 of file test_nntplib.py.

00699 
00700     def test_date(self):
00701         resp, date = self.server.date()
00702         self.assertEqual(resp, "111 20100914001155")
00703         self.assertEqual(date, datetime.datetime(2010, 9, 14, 0, 11, 55))

Here is the call graph for this function:

Definition at line 762 of file test_nntplib.py.

00762 
00763     def test_description(self):
00764         desc = self.server.description("comp.lang.python")
00765         self.assertEqual(desc, "The Python computer language.")
00766         desc = self.server.description("comp.lang.pythonx")
00767         self.assertEqual(desc, "")

Here is the call graph for this function:

Definition at line 768 of file test_nntplib.py.

00768 
00769     def test_descriptions(self):
00770         resp, groups = self.server.descriptions("comp.lang.python")
00771         self.assertEqual(resp, '215 Descriptions in form "group description".')
00772         self.assertEqual(groups, {
00773             "comp.lang.python": "The Python computer language.",
00774             })
00775         resp, groups = self.server.descriptions("comp.lang.python*")
00776         self.assertEqual(groups, {
00777             "comp.lang.python": "The Python computer language.",
00778             "comp.lang.python.announce": "Announcements about the Python language. (Moderated)",
00779             })
00780         resp, groups = self.server.descriptions("comp.lang.pythonx")
00781         self.assertEqual(groups, {})

Here is the call graph for this function:

Definition at line 782 of file test_nntplib.py.

00782 
00783     def test_group(self):
00784         resp, count, first, last, group = self.server.group("fr.comp.lang.python")
00785         self.assertTrue(resp.startswith("211 "), resp)
00786         self.assertEqual(first, 761)
00787         self.assertEqual(last, 1265)
00788         self.assertEqual(count, 486)
00789         self.assertEqual(group, "fr.comp.lang.python")
00790         with self.assertRaises(nntplib.NNTPTemporaryError) as cm:
00791             self.server.group("comp.lang.python.devel")
00792         exc = cm.exception
00793         self.assertTrue(exc.response.startswith("411 No such group"),
00794                         exc.response)

Here is the call graph for this function:

Definition at line 880 of file test_nntplib.py.

00880 
00881     def test_head(self):
00882         # HEAD
00883         resp, info = self.server.head()
00884         self.assertEqual(resp, "221 3000237 <45223423@example.com>")
00885         art_num, message_id, lines = info
00886         self.assertEqual(art_num, 3000237)
00887         self.assertEqual(message_id, "<45223423@example.com>")
00888         self._check_article_head(lines)
00889         # HEAD num
00890         resp, info = self.server.head(3000234)
00891         self.assertEqual(resp, "221 3000234 <45223423@example.com>")
00892         art_num, message_id, lines = info
00893         self.assertEqual(art_num, 3000234)
00894         self.assertEqual(message_id, "<45223423@example.com>")
00895         self._check_article_head(lines)
00896         # HEAD id
00897         resp, info = self.server.head("<45223423@example.com>")
00898         self.assertEqual(resp, "221 0 <45223423@example.com>")
00899         art_num, message_id, lines = info
00900         self.assertEqual(art_num, 0)
00901         self.assertEqual(message_id, "<45223423@example.com>")
00902         self._check_article_head(lines)
00903         # Non-existent id
00904         with self.assertRaises(nntplib.NNTPTemporaryError) as cm:
00905             self.server.head("<non-existent@example.com>")
00906         self.assertEqual(cm.exception.response, "430 No Such Article Found")

Here is the call graph for this function:

Definition at line 710 of file test_nntplib.py.

00710 
00711     def test_help(self):
00712         resp, help = self.server.help()
00713         self.assertEqual(resp, "100 Legal commands")
00714         self.assertEqual(help, [
00715             '  authinfo user Name|pass Password|generic <prog> <args>',
00716             '  date',
00717             '  help',
00718             'Report problems to <root@example.org>',
00719         ])

Here is the call graph for this function:

Definition at line 1032 of file test_nntplib.py.

01032 
01033     def test_ihave(self):
01034         self.check_post_ihave(self.server.ihave, "235 Article transferred OK",
01035                               "<i.am.an.article.you.will.want@example.com>")
01036         with self.assertRaises(nntplib.NNTPTemporaryError) as cm:
01037             self.server.ihave("<another.message.id>", self.sample_post)
01038         self.assertEqual(cm.exception.response,
01039                          "435 Article not wanted")
01040 

Here is the call graph for this function:

Definition at line 756 of file test_nntplib.py.

00756 
00757     def test_last(self):
00758         resp, art_num, message_id = self.server.last()
00759         self.assertEqual(resp, "223 3000234 <45223423@example.com> retrieved")
00760         self.assertEqual(art_num, 3000234)
00761         self.assertEqual(message_id, "<45223423@example.com>")

Here is the call graph for this function:

Definition at line 720 of file test_nntplib.py.

00720 
00721     def test_list(self):
00722         resp, groups = self.server.list()
00723         self.assertEqual(len(groups), 6)
00724         g = groups[1]
00725         self.assertEqual(g,
00726             GroupInfo("comp.lang.python.announce", "0000001153",
00727                       "0000000993", "m"))
00728         resp, groups = self.server.list("*distutils*")
00729         self.assertEqual(len(groups), 2)
00730         g = groups[0]
00731         self.assertEqual(g,
00732             GroupInfo("gmane.comp.python.distutils.devel", "0000014104",
00733                       "0000000001", "m"))

Here is the call graph for this function:

Definition at line 795 of file test_nntplib.py.

00795 
00796     def test_newnews(self):
00797         # NEWNEWS comp.lang.python [20]100913 082004
00798         dt = datetime.datetime(2010, 9, 13, 8, 20, 4)
00799         resp, ids = self.server.newnews("comp.lang.python", dt)
00800         expected = (
00801             "230 list of newsarticles (NNTP v{0}) "
00802             "created after Mon Sep 13 08:20:04 2010 follows"
00803             ).format(self.nntp_version)
00804         self.assertEqual(resp, expected)
00805         self.assertEqual(ids, [
00806             "<a4929a40-6328-491a-aaaf-cb79ed7309a2@q2g2000vbk.googlegroups.com>",
00807             "<f30c0419-f549-4218-848f-d7d0131da931@y3g2000vbm.googlegroups.com>",
00808             ])
00809         # NEWNEWS fr.comp.lang.python [20]100913 082004
00810         dt = datetime.datetime(2010, 9, 13, 8, 20, 4)
00811         resp, ids = self.server.newnews("fr.comp.lang.python", dt)
00812         self.assertEqual(resp, "230 An empty list of newsarticles follows")
00813         self.assertEqual(ids, [])

Here is the call graph for this function:

Definition at line 750 of file test_nntplib.py.

00750 
00751     def test_next(self):
00752         resp, art_num, message_id = self.server.next()
00753         self.assertEqual(resp, "223 3000237 <668929@example.org> retrieved")
00754         self.assertEqual(art_num, 3000237)
00755         self.assertEqual(message_id, "<668929@example.org>")

Here is the call graph for this function:

Definition at line 959 of file test_nntplib.py.

00959 
00960     def test_over(self):
00961         # In NNTP "v1", this will fallback on XOVER
00962         resp, overviews = self.server.over((57, 59))
00963         self.check_over_xover_resp(resp, overviews)

Here is the call graph for this function:

Definition at line 1024 of file test_nntplib.py.

01024 
01025     def test_post(self):
01026         self.check_post_ihave(self.server.post, "240 Article received OK")
01027         self.handler.allow_posting = False
01028         with self.assertRaises(nntplib.NNTPTemporaryError) as cm:
01029             self.server.post(self.sample_post)
01030         self.assertEqual(cm.exception.response,
01031                          "440 Posting not permitted")

Here is the call graph for this function:

Definition at line 704 of file test_nntplib.py.

00704 
00705     def test_quit(self):
00706         self.assertFalse(self.sio.closed)
00707         resp = self.server.quit()
00708         self.assertEqual(resp, "205 Bye!")
00709         self.assertTrue(self.sio.closed)

Here is the call graph for this function:

Definition at line 734 of file test_nntplib.py.

00734 
00735     def test_stat(self):
00736         resp, art_num, message_id = self.server.stat(3000234)
00737         self.assertEqual(resp, "223 3000234 <45223423@example.com>")
00738         self.assertEqual(art_num, 3000234)
00739         self.assertEqual(message_id, "<45223423@example.com>")
00740         resp, art_num, message_id = self.server.stat("<45223423@example.com>")
00741         self.assertEqual(resp, "223 0 <45223423@example.com>")
00742         self.assertEqual(art_num, 0)
00743         self.assertEqual(message_id, "<45223423@example.com>")
00744         with self.assertRaises(nntplib.NNTPTemporaryError) as cm:
00745             self.server.stat("<non.existent.id>")
00746         self.assertEqual(cm.exception.response, "430 No Such Article Found")
00747         with self.assertRaises(nntplib.NNTPTemporaryError) as cm:
00748             self.server.stat()
00749         self.assertEqual(cm.exception.response, "412 No newsgroup selected")

Here is the call graph for this function:

Definition at line 696 of file test_nntplib.py.

00696 
00697     def test_welcome(self):
00698         self.assertEqual(self.server.welcome, self.handler.welcome)

Here is the call graph for this function:

Definition at line 955 of file test_nntplib.py.

00955 
00956     def test_xover(self):
00957         resp, overviews = self.server.xover(57, 59)
00958         self.check_over_xover_resp(resp, overviews)

Here is the call graph for this function:


Member Data Documentation

Definition at line 359 of file test_nntplib.py.

Reimplemented from test.test_nntplib.MockedNNTPTestsMixin.

Definition at line 1045 of file test_nntplib.py.

Definition at line 1044 of file test_nntplib.py.

Initial value:
(
        b'From: "Demo User" <nobody@example.net>\r\n'
        b'Subject: I am just a test article\r\n'
        b'Content-Type: text/plain; charset=UTF-8; format=flowed\r\n'
        b'Message-ID: <i.am.an.article.you.will.want@example.com>\r\n'
        b'\r\n'
        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'
    )

Definition at line 964 of file test_nntplib.py.

Definition at line 364 of file test_nntplib.py.

Definition at line 360 of file test_nntplib.py.


The documentation for this class was generated from the following file: