diff --git a/linkcheck/ftests/__init__.py b/linkcheck/ftests/__init__.py new file mode 100644 index 00000000..7bd37c38 --- /dev/null +++ b/linkcheck/ftests/__init__.py @@ -0,0 +1,126 @@ +# -*- coding: iso-8859-1 -*- +"""define standard test support classes funtional for LinkChecker tests""" +# Copyright (C) 2004 Bastian Kleineidam +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import os +import unittest +import difflib + +import linkcheck.checker +import linkcheck.configuration +import linkcheck.logger + + +class TestLogger (linkcheck.logger.Logger): + """Output logger for automatic regression tests""" + + def __init__ (self, **kwargs): + """kwargs must have "expected" keyword with the expected logger + output lines""" + super(TestLogger, self).__init__(**kwargs) + self.expected = kwargs['expected'] + self.result = [] + self.diff = [] + + def start_output (self): + """nothing to do here""" + pass + + def new_url (self, url_data): + """append logger output to self.result""" + if self.has_field('url'): + url = "url %s" % url_data.base_url + if url_data.cached: + url += " (cached)" + self.result.append(url) + if self.has_field('name') and url_data.name: + self.result.append("name %s" % url_data.name) + if self.has_field('base') and url_data.base_ref: + self.result.append("baseurl %s" % url_data.base_ref) + if self.has_field('info'): + for info in url_data.info: + self.result.append("info %s" % info) + if self.has_field('warning'): + for warning in url_data.warning: + self.result.append("warning %s" % warning) + if self.has_field('result'): + self.result.append(url_data.valid and "valid" or "error") + # note: do not append url_data.result since this is + # platform dependent + + def end_output (self, linknumber=-1): + """stores differences between expected and result in self.diff""" + for line in difflib.unified_diff(self.expected, self.result): + self.diff.append(line) + + +def get_test_config (confargs, logargs): + """initialize a test configuration object""" + config = linkcheck.configuration.Configuration() + config.logger_add('test', TestLogger) + config['recursionlevel'] = 1 + config['logger'] = config.logger_new('test', **logargs) + config["anchors"] = True + config["verbose"] = True + config.set_threads(0) + for key, value in confargs.items(): + config[key] = value + return config + + +class StandardTest (unittest.TestCase, object): + """functional test class with ability to test local files""" + + def quote (self, url): + """helper function quote a url""" + return linkcheck.url.url_norm(url) + + def get_file (self, filename): + """get absolute file name, located within 'data' directory""" + return os.path.join("linkcheck", "ftests", "data", filename) + + def get_resultlines (self, filename): + """return contents of file, as list of lines""" + resultfile = self.get_file(filename+".result") + f = open(resultfile) + resultlines = [line.rstrip('\r\n') % {'curdir': os.getcwd()} \ + for line in f] + f.close() + return resultlines + + def file_test (self, filename): + """check with expected result in .result""" + url = self.get_file(filename) + confargs = {} + logargs = {'expected': self.get_resultlines(filename)} + config = get_test_config(confargs, logargs) + config.append_url(linkcheck.checker.get_url_from(url, 0, config)) + linkcheck.checker.check_urls(config) + if config['logger'].diff: + self.fail(os.linesep.join([url] + config['logger'].diff)) + + def direct (self, url, resultlines, fields=None, recursionlevel=0): + """check url with expected result""" + confargs = {'recursionlevel': recursionlevel} + logargs = {'expected': resultlines} + if fields is not None: + logargs['fields'] = fields + config = get_test_config(confargs, logargs) + config.append_url(linkcheck.checker.get_url_from(url, 0, config)) + linkcheck.checker.check_urls(config) + if config['logger'].diff: + self.fail(os.linesep.join([url]+config['logger'].diff)) diff --git a/linkcheck/ftests/data/anchor.html b/linkcheck/ftests/data/anchor.html new file mode 100644 index 00000000..a0a25eb8 --- /dev/null +++ b/linkcheck/ftests/data/anchor.html @@ -0,0 +1,4 @@ +Bla + diff --git a/linkcheck/ftests/data/anchor.html.result b/linkcheck/ftests/data/anchor.html.result new file mode 100644 index 00000000..5f16c8b0 --- /dev/null +++ b/linkcheck/ftests/data/anchor.html.result @@ -0,0 +1,5 @@ +url file://%(curdir)s/linkcheck/ftests/data/anchor.html +valid +url #myid +name Bla +valid diff --git a/linkcheck/ftests/data/base/test.txt b/linkcheck/ftests/data/base/test.txt new file mode 100644 index 00000000..e69de29b diff --git a/linkcheck/ftests/data/base1.html b/linkcheck/ftests/data/base1.html new file mode 100644 index 00000000..06c1d5ac --- /dev/null +++ b/linkcheck/ftests/data/base1.html @@ -0,0 +1,8 @@ + + + + + + diff --git a/linkcheck/ftests/data/base1.html.result b/linkcheck/ftests/data/base1.html.result new file mode 100644 index 00000000..b3e90227 --- /dev/null +++ b/linkcheck/ftests/data/base1.html.result @@ -0,0 +1,6 @@ +url file://%(curdir)s/linkcheck/ftests/data/base1.html +valid +url base2.html +valid +url base2.html (cached) +valid diff --git a/linkcheck/ftests/data/base2.html b/linkcheck/ftests/data/base2.html new file mode 100644 index 00000000..d6d51698 --- /dev/null +++ b/linkcheck/ftests/data/base2.html @@ -0,0 +1,3 @@ + + + diff --git a/linkcheck/ftests/data/base2.html.result b/linkcheck/ftests/data/base2.html.result new file mode 100644 index 00000000..92f200c4 --- /dev/null +++ b/linkcheck/ftests/data/base2.html.result @@ -0,0 +1,5 @@ +url file://%(curdir)s/linkcheck/ftests/data/base2.html +valid +url test.txt +baseurl file://%(curdir)s/linkcheck/ftests/data/base/ +valid diff --git a/linkcheck/ftests/data/base3.html b/linkcheck/ftests/data/base3.html new file mode 100644 index 00000000..eed04b7c --- /dev/null +++ b/linkcheck/ftests/data/base3.html @@ -0,0 +1,2 @@ + + diff --git a/linkcheck/ftests/data/base3.html.result b/linkcheck/ftests/data/base3.html.result new file mode 100644 index 00000000..09688388 --- /dev/null +++ b/linkcheck/ftests/data/base3.html.result @@ -0,0 +1,5 @@ +url file://%(curdir)s/linkcheck/ftests/data/base3.html +valid +url test.txt +baseurl file://%(curdir)s/linkcheck/ftests/data/base/ +valid diff --git a/linkcheck/ftests/data/file.asc b/linkcheck/ftests/data/file.asc new file mode 100644 index 00000000..8a8fc5cd --- /dev/null +++ b/linkcheck/ftests/data/file.asc @@ -0,0 +1 @@ +file:///etc/group diff --git a/linkcheck/ftests/data/file.asc.result b/linkcheck/ftests/data/file.asc.result new file mode 100644 index 00000000..5487b9be --- /dev/null +++ b/linkcheck/ftests/data/file.asc.result @@ -0,0 +1,2 @@ +url file://%(curdir)s/linkcheck/ftests/data/file.asc +valid diff --git a/linkcheck/ftests/data/file.css b/linkcheck/ftests/data/file.css new file mode 100644 index 00000000..55ee1ade --- /dev/null +++ b/linkcheck/ftests/data/file.css @@ -0,0 +1,4 @@ +@font-face { + src:url(file.html) +} +background-image:url(file.html) diff --git a/linkcheck/ftests/data/file.css.result b/linkcheck/ftests/data/file.css.result new file mode 100644 index 00000000..85694f0d --- /dev/null +++ b/linkcheck/ftests/data/file.css.result @@ -0,0 +1,6 @@ +url file://%(curdir)s/linkcheck/ftests/data/file.css +valid +url file.html +valid +url file.html (cached) +valid diff --git a/linkcheck/ftests/data/file.html b/linkcheck/ftests/data/file.html new file mode 100644 index 00000000..575da2d6 --- /dev/null +++ b/linkcheck/ftests/data/file.html @@ -0,0 +1,9 @@ +relative url +bad anchor +good anchor +bad anchor +good anchor +bad scheme +javascript url + +anchor diff --git a/linkcheck/ftests/data/file.html.result b/linkcheck/ftests/data/file.html.result new file mode 100644 index 00000000..d50c8001 --- /dev/null +++ b/linkcheck/ftests/data/file.html.result @@ -0,0 +1,26 @@ +url file://%(curdir)s/linkcheck/ftests/data/file.html +valid +url file.html (cached) +name relative url +valid +url file.html#isnix +name bad anchor +warning anchor #isnix not found +valid +url file.html#iswas +name good anchor +valid +url #isnix (cached) +name bad anchor +warning anchor #isnix not found +valid +url #iswas (cached) +name good anchor +valid +url hutzli:nixgutt +name bad scheme +error +url javascript:loadthis() +name javascript url +warning Javascript url ignored +valid diff --git a/linkcheck/ftests/data/file.txt b/linkcheck/ftests/data/file.txt new file mode 100644 index 00000000..8a8fc5cd --- /dev/null +++ b/linkcheck/ftests/data/file.txt @@ -0,0 +1 @@ +file:///etc/group diff --git a/linkcheck/ftests/data/file.txt.result b/linkcheck/ftests/data/file.txt.result new file mode 100644 index 00000000..c55ae5f7 --- /dev/null +++ b/linkcheck/ftests/data/file.txt.result @@ -0,0 +1,2 @@ +url file://%(curdir)s/linkcheck/ftests/data/file.txt +valid diff --git a/linkcheck/ftests/data/frames.html b/linkcheck/ftests/data/frames.html new file mode 100644 index 00000000..70d9a80d --- /dev/null +++ b/linkcheck/ftests/data/frames.html @@ -0,0 +1,5 @@ + + + + + diff --git a/linkcheck/ftests/data/frames.html.result b/linkcheck/ftests/data/frames.html.result new file mode 100644 index 00000000..82b83685 --- /dev/null +++ b/linkcheck/ftests/data/frames.html.result @@ -0,0 +1,6 @@ +url file://%(curdir)s/linkcheck/ftests/data/frames.html +valid +url frames.html (cached) +valid +url frames.html (cached) +valid diff --git a/linkcheck/ftests/data/http.html b/linkcheck/ftests/data/http.html new file mode 100644 index 00000000..aaef5897 --- /dev/null +++ b/linkcheck/ftests/data/http.html @@ -0,0 +1,31 @@ +Just some HTTP links +bad url +ok +one slash +no slash +no url +no url, one slash +no url, no slash +unquoted ampersand +unquoted +should be cached +should be cached + +html entities + + + + + + + + + + +no beginning quote + tag parsing""" +# Copyright (C) 2004 Bastian Kleineidam +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import unittest + +import linkcheck.ftests + +class TestBase (linkcheck.ftests.StandardTest): + """test links of base*.html files""" + + def test_base1 (self): + """test links of base1.html""" + self.file_test("base1.html") + + def test_base2 (self): + """test links of base2.html""" + self.file_test("base2.html") + + def test_base3 (self): + """test links of base3.html""" + self.file_test("base3.html") + + +def test_suite (): + """build and return a TestSuite""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestBase)) + return suite + +if __name__ == '__main__': + unittest.main() diff --git a/linkcheck/ftests/test_fcgi.py b/linkcheck/ftests/test_fcgi.py new file mode 100644 index 00000000..c7a0b40a --- /dev/null +++ b/linkcheck/ftests/test_fcgi.py @@ -0,0 +1,72 @@ +# -*- coding: iso-8859-1 -*- +"""test container routines""" + +import unittest +import os + +class TestFcgi (unittest.TestCase): + """test FastCGI request parsing routines""" + + def _test_fcgi (self): + """test FastCGI request parsing routines""" + # XXX inactive + counter = 0 + try: + while isFCGI(): + req = FCGI() + counter += 1 + try: + fs = req.getFieldStorage() + size = int(fs['size'].value) + doc = ['*' * size] + except: + doc = ['FCGI TestApp\n' + '\n'] + doc.append('

FCGI TestApp

') + doc.append('request count = %d
' % counter) + doc.append('pid = %s
' % os.getpid()) + if req.env.has_key('CONTENT_LENGTH'): + cl = int(req.env['CONTENT_LENGTH']) + doc.append('
POST data (%s):

' % cl)
+                        keys = fs.keys()
+                        keys.sort()
+                        for k in keys:
+                            val = fs[k]
+                            if type(val) == type([]):
+                                doc.append('    %-15s :  %s\n' %
+                                           (k, val))
+                            else:
+                                doc.append('    %-15s :  %s\n' %
+                                           (k, val.value))
+                        doc.append('
') + doc.append('


')
+                    keys = req.env.keys()
+                    keys.sort()
+                    for k in keys:
+                        doc.append('%-20s :  %s\n' % (k, req.env[k]))
+                    doc.append('\n


\n') + doc.append('\n') + doc = ''.join(doc) + req.out.write('Content-length: %s\r\n' + 'Content-type: text/html\r\n' + 'Cache-Control: no-cache\r\n' + '\r\n' + % len(doc)) + req.out.write(doc) + req.finish() + except: + import traceback + f = file('traceback', 'w') + traceback.print_exc(file = f) + #f.write('%s' % doc) + + +def test_suite (): + """build and return a TestSuite""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestFcgi)) + return suite + + +if __name__ == '__main__': + unittest.main() diff --git a/linkcheck/ftests/test_file.py b/linkcheck/ftests/test_file.py new file mode 100644 index 00000000..8d96b73c --- /dev/null +++ b/linkcheck/ftests/test_file.py @@ -0,0 +1,75 @@ +# -*- coding: iso-8859-1 -*- +"""test file parsing""" +# Copyright (C) 2004 Bastian Kleineidam +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import unittest +import os + +import linkcheck.ftests + + +class TestFile (linkcheck.ftests.StandardTest): + """test file:// link checking (and file content parsing)""" + + def test_html (self): + """test links of file.html""" + self.file_test("file.html") + + def test_text (self): + """test links of file.txt""" + self.file_test("file.txt") + + def test_asc (self): + """test links of file.asc""" + self.file_test("file.asc") + + def test_css (self): + """test links of file.css""" + self.file_test("file.css") + + def test_files (self): + """test some direct file links""" + attrs = {'curdir': os.getcwd(), + 'datadir': 'linkcheck/ftests/data', + } + # good file + url = "file://%(curdir)s/%(datadir)s/file.txt"%attrs + resultlines = ["url %s" % url, "valid"] + self.direct(url, resultlines) + # bad file + url = "file:/%(curdir)s/%(datadir)s/file.txt"%attrs + resultlines = ["url %s" % url, "error"] + self.direct(url, resultlines) + # good file + url = "file:%(curdir)s/%(datadir)s/file.txt"%attrs + resultlines = ["url %s" % url, "valid"] + self.direct(url, resultlines) + # good dir + url = "file://%(curdir)s/%(datadir)s/"%attrs + resultlines = ["url %s" % url, "valid"] + self.direct(url, resultlines) + + +def test_suite (): + """build and return a TestSuite""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestFile)) + return suite + + +if __name__ == '__main__': + unittest.main() diff --git a/linkcheck/ftests/test_frames.py b/linkcheck/ftests/test_frames.py new file mode 100644 index 00000000..3e15b696 --- /dev/null +++ b/linkcheck/ftests/test_frames.py @@ -0,0 +1,38 @@ +# -*- coding: iso-8859-1 -*- +"""test html tag parsing""" +# Copyright (C) 2004 Bastian Kleineidam +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import unittest + +import linkcheck.ftests + +class TestFrames (linkcheck.ftests.StandardTest): + """test link checking of HTML framesets""" + + def test_frames (self): + """test links of frames.html""" + self.file_test("frames.html") + + +def test_suite (): + """build and return a TestSuite""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestFrames)) + return suite + +if __name__ == '__main__': + unittest.main() diff --git a/linkcheck/ftests/test_ftp.py b/linkcheck/ftests/test_ftp.py new file mode 100644 index 00000000..c0d48416 --- /dev/null +++ b/linkcheck/ftests/test_ftp.py @@ -0,0 +1,67 @@ +# -*- coding: iso-8859-1 -*- +"""test ftp checking""" +# Copyright (C) 2004 Bastian Kleineidam +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import unittest + +import linkcheck.ftests + + +class TestFtp (linkcheck.ftests.StandardTest): + """test ftp: link checking""" + + def test_ftp (self): + """test some ftp links""" + # ftp one slash + url = "ftp:/ftp.debian.org/" + resultlines = ["url %s" % url, "error"] + self.direct(url, resultlines) + # ftp two slashes + url = "ftp://ftp.debian.org/" + resultlines = ["url %s" % url, "valid"] + self.direct(url, resultlines) + # ftp two dir slashes + url = "ftp://ftp.debian.org//debian/" + resultlines = ["url %s" % url, "valid"] + self.direct(url, resultlines) + # missing trailing dir slash + url = "ftp://ftp.debian.org/debian" + resultlines = [ + "url %s" % url, + "warning Missing trailing directory slash in ftp url", + "valid", + ] + self.direct(url, resultlines) + # ftp many dir slashes + url = "ftp://ftp.debian.org////////debian/" + resultlines = ["url %s" % url, "valid"] + self.direct(url, resultlines) + # ftp three slashes + url = "ftp:///ftp.debian.org/" + resultlines = ["url %s" % url, "error"] + self.direct(url, resultlines) + + +def test_suite (): + """build and return a TestSuite""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestFtp)) + return suite + + +if __name__ == '__main__': + unittest.main() diff --git a/linkcheck/ftests/test_http.py b/linkcheck/ftests/test_http.py new file mode 100644 index 00000000..2376c444 --- /dev/null +++ b/linkcheck/ftests/test_http.py @@ -0,0 +1,46 @@ +# -*- coding: iso-8859-1 -*- +"""test http checking""" +# Copyright (C) 2004 Bastian Kleineidam +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import unittest +import os + +import linkcheck.ftests.httptest + + +class TestHttp (linkcheck.ftests.httptest.HttpServerTest): + """test http:// link checking""" + + def test_html (self): + self.start_server() + url = "http://localhost:%d/linkcheck/ftests/data/http.html"%self.port + resultlines = self.get_resultlines("http.html") + try: + self.direct(url, resultlines, recursionlevel=1) + finally: + self.stop_server() + + +def test_suite (): + """build and return a TestSuite""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestHttp)) + return suite + + +if __name__ == '__main__': + unittest.main() diff --git a/linkcheck/ftests/test_https.py b/linkcheck/ftests/test_https.py new file mode 100644 index 00000000..3a6b4a12 --- /dev/null +++ b/linkcheck/ftests/test_https.py @@ -0,0 +1,41 @@ +# -*- coding: iso-8859-1 -*- +"""test news checking""" +# Copyright (C) 2004 Bastian Kleineidam +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import unittest + +import linkcheck.ftests + +class TestHttps (linkcheck.ftests.StandardTest): + """test https: link checking""" + + def test_mail (self): + """test some https links""" + url = "https://sourceforge.net/" + resultlines = ["url %s" % url, "valid"] + self.direct(url, resultlines) + + +def test_suite (): + """build and return a TestSuite""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestHttps)) + return suite + + +if __name__ == '__main__': + unittest.main() diff --git a/linkcheck/ftests/test_mail.py b/linkcheck/ftests/test_mail.py new file mode 100644 index 00000000..13933985 --- /dev/null +++ b/linkcheck/ftests/test_mail.py @@ -0,0 +1,123 @@ +# -*- coding: iso-8859-1 -*- +"""test mail checking""" +# Copyright (C) 2004 Bastian Kleineidam +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import unittest +import urllib +import os + +import linkcheck.ftests + +class TestMail (linkcheck.ftests.StandardTest): + """test mailto: link checking""" + + def test_good_mail (self): + """test some good mailto addrs""" + url = self.quote("mailto:Dude , "\ + "Killer ?subject=bla") + resultlines = [ + "url %s" % url, + "info Verified adress: is deliverable", + "valid", + ] + self.direct(url, resultlines) + url = self.quote("mailto:Bastian Kleineidam ?"\ + "bcc=calvin%40users.sf.net") + resultlines = [ + "url %s" % url, + "info Verified adress: is deliverable", + "valid", + ] + self.direct(url, resultlines) + url = self.quote("mailto:Bastian Kleineidam ") + resultlines = [ + "url %s" % url, + "info Verified adress: is deliverable", + "valid", + ] + self.direct(url, resultlines) + url = self.quote("mailto:o'hara@users.sf.net") + resultlines = [ + "url %s" % url, + "info Verified adress: is deliverable", + "valid", + ] + self.direct(url, resultlines) + url = self.quote("mailto:?to=calvin@users.sf.net&subject=blubb&"\ + "cc=calvin_cc@users.sf.net&CC=calvin_CC@users.sf.net") + resultlines = [ + "url %s" % url, + "info Verified adress: is deliverable", + "info Verified adress: is deliverable", + "info Verified adress: is deliverable", + "valid", + ] + self.direct(url, resultlines) + url = self.quote("mailto:news-admins@freshmeat.net?subject="\ + "Re:%20[fm%20#11093]%20(news-admins)%20Submission%20"\ + "report%20-%20Pretty%20CoLoRs") + resultlines = ["url %s" % url, "valid"] + self.direct(url, resultlines) + url = self.quote("mailto:"+"foo@foo-bar.de?subject=test") + resultlines = ["url %s" % url, "valid"] + self.direct(url, resultlines) + + def test_warn_mail (self): + """test some mailto addrs with warnings""" + # contains non-quoted characters + url = "calvin@users.sf.net?subject=äöü" + resultlines = [ + "url %s" % self.quote("mailto:"+url), + "info Verified adress: is deliverable", + "warning Base URL is not properly quoted", + "valid", + ] + self.direct("mailto:"+url, resultlines) + url = "calvin@users.sf.net?subject=Halli hallo" + resultlines = [ + "url %s" % self.quote("mailto:"+url), + "info Verified adress: is deliverable", + "warning Base URL is not properly quoted", + "valid", + ] + self.direct("mailto:"+url, resultlines) + url = self.quote("mailto:") + resultlines = [ + "url %s" % url, + "warning No adresses found", + "valid", + ] + self.direct(url, resultlines) + + def test_bad_mail (self): + """test some mailto addrs with bad syntax""" + # ? extension forbidden in <> construct + url = self.quote("mailto:Bastian Kleineidam "\ + "") + resultlines = ["url %s" % url, "error"] + self.direct(url, resultlines) + + +def test_suite (): + """build and return a TestSuite""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestMail)) + return suite + + +if __name__ == '__main__': + unittest.main() diff --git a/linkcheck/ftests/test_news.py b/linkcheck/ftests/test_news.py new file mode 100644 index 00000000..f75dcdd8 --- /dev/null +++ b/linkcheck/ftests/test_news.py @@ -0,0 +1,100 @@ +# -*- coding: iso-8859-1 -*- +"""test news checking""" +# Copyright (C) 2004 Bastian Kleineidam +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import unittest + +import linkcheck.ftests + + +class TestNews (linkcheck.ftests.StandardTest): + """test nntp: and news: link checking""" + + def newstest (self, url, resultlines): + fields = ['url', 'warning', 'result', ] + self.direct(url, resultlines, fields=fields) + + def test_news (self): + """test some news links""" + # news testing + url = "news:comp.os.linux.misc" + resultlines = [ + "url %s" % url, + "warning No NNTP server specified, skipping this URL", + "valid", + ] + self.newstest(url, resultlines) + # snews + url = "snews:de.comp.os.unix.linux.misc" + resultlines = [ + "url %s" % url, + "warning No NNTP server specified, skipping this URL", + "valid", + ] + self.newstest(url, resultlines) + # no group + url = "news:" + resultlines = [ + "url %s" % url, + "warning No NNTP server specified, skipping this URL", + "valid", + ] + self.newstest(url, resultlines) + # illegal syntax + url = "§$%&/´`(§%" + resultlines = [ + "url %s" % self.quote("news:"+url), + "warning Base URL is not properly quoted", + "warning No NNTP server specified, skipping this URL", + "valid", + ] + self.newstest("news:"+url, resultlines) + # nttp scheme with host + url = "nntp://news.yaako.com/comp.lang.python" + resultlines = ["url %s" % url, "valid"] + self.newstest(url, resultlines) + # article span + url = "nntp://news.yaako.com/comp.lang.python/1-5" + resultlines = ["url %s" % url, "valid"] + self.newstest(url, resultlines) + # host but no group + url = "nntp://news.yaako.com/" + resultlines = [ + "url %s" % url, + "warning No newsgroup specified in NNTP URL", + "valid", + ] + self.newstest(url, resultlines) + # article span + url = "news:comp.lang.python/1-5" + resultlines = [ + "url %s" % url, + "warning No NNTP server specified, skipping this URL", + "valid", + ] + self.newstest(url, resultlines) + + +def test_suite (): + """build and return a TestSuite""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestNews)) + return suite + + +if __name__ == '__main__': + unittest.main() diff --git a/linkcheck/ftests/test_telnet.py b/linkcheck/ftests/test_telnet.py new file mode 100644 index 00000000..c4d25806 --- /dev/null +++ b/linkcheck/ftests/test_telnet.py @@ -0,0 +1,50 @@ +# -*- coding: iso-8859-1 -*- +"""test news checking""" +# Copyright (C) 2004 Bastian Kleineidam +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import unittest + +import linkcheck.ftests + + +class TestTelnet (linkcheck.ftests.StandardTest): + """test telnet: link checking""" + + def test_telnet (self): + url = "telnet:" + resultlines = ["url %s" % url, "error"] + self.direct(url, resultlines) + url = "telnet://swindon.city.ac.uk" + resultlines = ["url %s" % url, "valid"] + self.direct(url, resultlines) + url = "telnet://user@swindon.city.ac.uk" + resultlines = ["url %s" % url, "valid"] + self.direct(url, resultlines) + url = "telnet://user:password@swindon.city.ac.uk" + resultlines = ["url %s" % url, "valid"] + self.direct(url, resultlines) + + +def test_suite (): + """build and return a TestSuite""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestTelnet)) + return suite + + +if __name__ == '__main__': + unittest.main()