Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions
test.test_nntplib.NetworkedNNTPTestsMixin Class Reference
Inheritance diagram for test.test_nntplib.NetworkedNNTPTestsMixin:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def test_welcome
def test_help
def test_list
def test_list_active
def test_unknown_command
def test_newgroups
def test_description
def test_descriptions
def test_group
def test_date
def test_xover
def test_over
def test_xhdr
def check_article_resp
def test_article_head_body
def test_capabilities
def test_starttls
def test_zlogin
def test_zzquit
def wrap_methods

Private Member Functions

def _check_art_dict

Detailed Description

Definition at line 22 of file test_nntplib.py.


Member Function Documentation

def test.test_nntplib.NetworkedNNTPTestsMixin._check_art_dict (   self,
  art_dict 
) [private]

Definition at line 104 of file test_nntplib.py.

00104 
00105     def _check_art_dict(self, art_dict):
00106         # Some sanity checks for a field dictionary returned by OVER / XOVER
00107         self.assertIsInstance(art_dict, dict)
00108         # NNTP has 7 mandatory fields
00109         self.assertGreaterEqual(art_dict.keys(),
00110             {"subject", "from", "date", "message-id",
00111              "references", ":bytes", ":lines"}
00112             )
00113         for v in art_dict.values():
00114             self.assertIsInstance(v, (str, type(None)))

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_nntplib.NetworkedNNTPTestsMixin.check_article_resp (   self,
  resp,
  article,
  art_num = None 
)

Definition at line 149 of file test_nntplib.py.

00149 
00150     def check_article_resp(self, resp, article, art_num=None):
00151         self.assertIsInstance(article, nntplib.ArticleInfo)
00152         if art_num is not None:
00153             self.assertEqual(article.number, art_num)
00154         for line in article.lines:
00155             self.assertIsInstance(line, bytes)
00156         # XXX this could exceptionally happen...
00157         self.assertNotIn(article.lines[-1], (b".", b".\n", b".\r\n"))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 158 of file test_nntplib.py.

00158 
00159     def test_article_head_body(self):
00160         resp, count, first, last, name = self.server.group(self.GROUP_NAME)
00161         # Try to find an available article
00162         for art_num in (last, first, last - 1):
00163             try:
00164                 resp, head = self.server.head(art_num)
00165             except nntplib.NNTPTemporaryError as e:
00166                 if not e.response.startswith("423 "):
00167                     raise
00168                 # "423 No such article" => choose another one
00169                 continue
00170             break
00171         else:
00172             self.skipTest("could not find a suitable article number")
00173         self.assertTrue(resp.startswith("221 "), resp)
00174         self.check_article_resp(resp, head, art_num)
00175         resp, body = self.server.body(art_num)
00176         self.assertTrue(resp.startswith("222 "), resp)
00177         self.check_article_resp(resp, body, art_num)
00178         resp, article = self.server.article(art_num)
00179         self.assertTrue(resp.startswith("220 "), resp)
00180         self.check_article_resp(resp, article, art_num)
00181         self.assertEqual(article.lines, head.lines + [b''] + body.lines)

Here is the call graph for this function:

Definition at line 182 of file test_nntplib.py.

00182 
00183     def test_capabilities(self):
00184         # The server under test implements NNTP version 2 and has a
00185         # couple of well-known capabilities. Just sanity check that we
00186         # got them.
00187         def _check_caps(caps):
00188             caps_list = caps['LIST']
00189             self.assertIsInstance(caps_list, (list, tuple))
00190             self.assertIn('OVERVIEW.FMT', caps_list)
00191         self.assertGreaterEqual(self.server.nntp_version, 2)
00192         _check_caps(self.server.getcapabilities())
00193         # This re-emits the command
00194         resp, caps = self.server.capabilities()
00195         _check_caps(caps)

Here is the call graph for this function:

Definition at line 97 of file test_nntplib.py.

00097 
00098     def test_date(self):
00099         resp, date = self.server.date()
00100         self.assertIsInstance(date, datetime.datetime)
00101         # Sanity check
00102         self.assertGreaterEqual(date.year, 1995)
00103         self.assertLessEqual(date.year, 2030)

Here is the call graph for this function:

Definition at line 61 of file test_nntplib.py.

00061 
00062     def test_description(self):
00063         def _check_desc(desc):
00064             # Sanity checks
00065             self.assertIsInstance(desc, str)
00066             self.assertNotIn(self.GROUP_NAME, desc)
00067         desc = self.server.description(self.GROUP_NAME)
00068         _check_desc(desc)
00069         # Another sanity check
00070         self.assertIn("Python", desc)
00071         # With a pattern
00072         desc = self.server.description(self.GROUP_PAT)
00073         _check_desc(desc)
00074         # Shouldn't exist
00075         desc = self.server.description("zk.brrtt.baz")
00076         self.assertEqual(desc, '')

Here is the call graph for this function:

Definition at line 77 of file test_nntplib.py.

00077 
00078     def test_descriptions(self):
00079         resp, descs = self.server.descriptions(self.GROUP_PAT)
00080         # 215 for LIST NEWSGROUPS, 282 for XGTITLE
00081         self.assertTrue(
00082             resp.startswith("215 ") or resp.startswith("282 "), resp)
00083         self.assertIsInstance(descs, dict)
00084         desc = descs[self.GROUP_NAME]
00085         self.assertEqual(desc, self.server.description(self.GROUP_NAME))

Here is the call graph for this function:

Definition at line 86 of file test_nntplib.py.

00086 
00087     def test_group(self):
00088         result = self.server.group(self.GROUP_NAME)
00089         self.assertEqual(5, len(result))
00090         resp, count, first, last, group = result
00091         self.assertEqual(group, self.GROUP_NAME)
00092         self.assertIsInstance(count, int)
00093         self.assertIsInstance(first, int)
00094         self.assertIsInstance(last, int)
00095         self.assertLessEqual(first, last)
00096         self.assertTrue(resp.startswith("211 "), resp)

Here is the call graph for this function:

Definition at line 28 of file test_nntplib.py.

00028 
00029     def test_help(self):
00030         resp, lines = self.server.help()
00031         self.assertTrue(resp.startswith("100 "), resp)
00032         for line in lines:
00033             self.assertEqual(str, type(line))

Here is the call graph for this function:

Definition at line 34 of file test_nntplib.py.

00034 
00035     def test_list(self):
00036         resp, groups = self.server.list()
00037         if len(groups) > 0:
00038             self.assertEqual(GroupInfo, type(groups[0]))
00039             self.assertEqual(str, type(groups[0].group))

Here is the call graph for this function:

Definition at line 40 of file test_nntplib.py.

00040 
00041     def test_list_active(self):
00042         resp, groups = self.server.list(self.GROUP_PAT)
00043         if len(groups) > 0:
00044             self.assertEqual(GroupInfo, type(groups[0]))
00045             self.assertEqual(str, type(groups[0].group))

Here is the call graph for this function:

Definition at line 52 of file test_nntplib.py.

00052 
00053     def test_newgroups(self):
00054         # gmane gets a constant influx of new groups.  In order not to stress
00055         # the server too much, we choose a recent date in the past.
00056         dt = datetime.date.today() - datetime.timedelta(days=7)
00057         resp, groups = self.server.newgroups(dt)
00058         if len(groups) > 0:
00059             self.assertIsInstance(groups[0], GroupInfo)
00060             self.assertIsInstance(groups[0].group, str)

Here is the call graph for this function:

Definition at line 126 of file test_nntplib.py.

00126 
00127     def test_over(self):
00128         resp, count, first, last, name = self.server.group(self.GROUP_NAME)
00129         start = last - 10
00130         # The "start-" article range form
00131         resp, lines = self.server.over((start, None))
00132         art_num, art_dict = lines[0]
00133         self._check_art_dict(art_dict)
00134         # The "start-end" article range form
00135         resp, lines = self.server.over((start, last))
00136         art_num, art_dict = lines[-1]
00137         # The 'last' article is not necessarily part of the output (cancelled?)
00138         self.assertGreaterEqual(art_num, start)
00139         self.assertLessEqual(art_num, last)
00140         self._check_art_dict(art_dict)
00141         # XXX The "message_id" form is unsupported by gmane
00142         # 503 Overview by message-ID unsupported

Here is the call graph for this function:

Definition at line 197 of file test_nntplib.py.

00197 
00198         def test_starttls(self):
00199             file = self.server.file
00200             sock = self.server.sock
00201             try:
00202                 self.server.starttls()
00203             except nntplib.NNTPPermanentError:
00204                 self.skipTest("STARTTLS not supported by server.")
00205             else:
00206                 # Check that the socket and internal pseudo-file really were
00207                 # changed.
00208                 self.assertNotEqual(file, self.server.file)
00209                 self.assertNotEqual(sock, self.server.sock)
00210                 # Check that the new socket really is an SSL one
00211                 self.assertIsInstance(self.server.sock, ssl.SSLSocket)
00212                 # Check that trying starttls when it's already active fails.
00213                 self.assertRaises(ValueError, self.server.starttls)

Here is the call graph for this function:

Definition at line 46 of file test_nntplib.py.

00046 
00047     def test_unknown_command(self):
00048         with self.assertRaises(nntplib.NNTPPermanentError) as cm:
00049             self.server._shortcmd("XYZZY")
00050         resp = cm.exception.response
00051         self.assertTrue(resp.startswith("500 "), resp)

Here is the call graph for this function:

Definition at line 24 of file test_nntplib.py.

00024 
00025     def test_welcome(self):
00026         welcome = self.server.getwelcome()
00027         self.assertEqual(str, type(welcome))

Here is the call graph for this function:

Definition at line 143 of file test_nntplib.py.

00143 
00144     def test_xhdr(self):
00145         resp, count, first, last, name = self.server.group(self.GROUP_NAME)
00146         resp, lines = self.server.xhdr('subject', last)
00147         for line in lines:
00148             self.assertEqual(str, type(line[1]))

Here is the call graph for this function:

Definition at line 115 of file test_nntplib.py.

00115 
00116     def test_xover(self):
00117         resp, count, first, last, name = self.server.group(self.GROUP_NAME)
00118         resp, lines = self.server.xover(last - 5, last)
00119         if len(lines) == 0:
00120             self.skipTest("no articles retrieved")
00121         # The 'last' article is not necessarily part of the output (cancelled?)
00122         art_num, art_dict = lines[0]
00123         self.assertGreaterEqual(art_num, last - 5)
00124         self.assertLessEqual(art_num, last)
00125         self._check_art_dict(art_dict)

Here is the call graph for this function:

Definition at line 214 of file test_nntplib.py.

00214 
00215     def test_zlogin(self):
00216         # This test must be the penultimate because further commands will be
00217         # refused.
00218         baduser = "notarealuser"
00219         badpw = "notarealpassword"
00220         # Check that bogus credentials cause failure
00221         self.assertRaises(nntplib.NNTPError, self.server.login,
00222                           user=baduser, password=badpw, usenetrc=False)
00223         # FIXME: We should check that correct credentials succeed, but that
00224         # would require valid details for some server somewhere to be in the
00225         # test suite, I think. Gmane is anonymous, at least as used for the
00226         # other tests.

Here is the call graph for this function:

Definition at line 227 of file test_nntplib.py.

00227 
00228     def test_zzquit(self):
00229         # This test must be called last, hence the name
00230         cls = type(self)
00231         try:
00232             self.server.quit()
00233         finally:
00234             cls.server = None

Definition at line 236 of file test_nntplib.py.

00236 
00237     def wrap_methods(cls):
00238         # Wrap all methods in a transient_internet() exception catcher
00239         # XXX put a generic version in test.support?
00240         def wrap_meth(meth):
00241             @functools.wraps(meth)
00242             def wrapped(self):
00243                 with support.transient_internet(self.NNTP_HOST):
00244                     meth(self)
00245             return wrapped
00246         for name in dir(cls):
00247             if not name.startswith('test_'):
00248                 continue
00249             meth = getattr(cls, name)
00250             if not isinstance(meth, collections.Callable):
00251                 continue
00252             # Need to use a closure so that meth remains bound to its current
00253             # value
00254             setattr(cls, name, wrap_meth(meth))
00255 
00256 NetworkedNNTPTestsMixin.wrap_methods()
00257 

Here is the call graph for this function:


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