2004-08-16 19:20:06 +00:00
|
|
|
# -*- coding: iso-8859-1 -*-
|
2009-01-08 14:18:03 +00:00
|
|
|
# Copyright (C) 2004-2009 Bastian Kleineidam
|
2004-08-16 19:20:06 +00:00
|
|
|
#
|
|
|
|
|
# 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.
|
|
|
|
|
#
|
2009-07-24 21:58:20 +00:00
|
|
|
# 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.,
|
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2005-01-19 15:08:02 +00:00
|
|
|
"""
|
|
|
|
|
Test cgi form routines.
|
|
|
|
|
"""
|
2004-08-16 19:20:06 +00:00
|
|
|
import unittest
|
|
|
|
|
import linkcheck.lc_cgi
|
|
|
|
|
|
2005-12-17 19:22:44 +00:00
|
|
|
|
2004-08-16 19:20:06 +00:00
|
|
|
class Store (object):
|
2005-01-19 14:38:01 +00:00
|
|
|
"""
|
|
|
|
|
Value storing class implementing FieldStorage interface.
|
|
|
|
|
"""
|
2004-08-16 19:20:06 +00:00
|
|
|
|
|
|
|
|
def __init__ (self, value):
|
2005-01-19 14:38:01 +00:00
|
|
|
"""
|
|
|
|
|
Store given value.
|
|
|
|
|
"""
|
2004-08-16 19:20:06 +00:00
|
|
|
self.value = value
|
|
|
|
|
|
|
|
|
|
|
2006-04-24 20:16:57 +00:00
|
|
|
class TestCgi (unittest.TestCase):
|
2005-01-19 14:38:01 +00:00
|
|
|
"""
|
|
|
|
|
Test cgi routines.
|
|
|
|
|
"""
|
2004-08-16 19:20:06 +00:00
|
|
|
|
|
|
|
|
def test_form_valid_url (self):
|
2005-01-19 14:38:01 +00:00
|
|
|
"""
|
|
|
|
|
Check url validity.
|
|
|
|
|
"""
|
2004-08-16 19:20:06 +00:00
|
|
|
form = {"url": Store("http://www.heise.de/"),
|
|
|
|
|
"level": Store("0"),
|
|
|
|
|
}
|
|
|
|
|
linkcheck.lc_cgi.checkform(form)
|
|
|
|
|
|
|
|
|
|
def test_form_empty_url (self):
|
2005-01-19 14:38:01 +00:00
|
|
|
"""
|
|
|
|
|
Check with empty url.
|
|
|
|
|
"""
|
2004-08-16 19:20:06 +00:00
|
|
|
form = {"url": Store(""),
|
|
|
|
|
"level": Store("0"),
|
|
|
|
|
}
|
2009-01-28 23:12:03 +00:00
|
|
|
self.assertRaises(linkcheck.lc_cgi.LCFormError,
|
2004-08-16 19:20:06 +00:00
|
|
|
linkcheck.lc_cgi.checkform, form)
|
|
|
|
|
|
|
|
|
|
def test_form_default_url (self):
|
2005-01-19 14:38:01 +00:00
|
|
|
"""
|
|
|
|
|
Check with default url.
|
|
|
|
|
"""
|
2004-08-16 19:20:06 +00:00
|
|
|
form = {"url": Store("http://"),
|
|
|
|
|
"level": Store("0"),
|
|
|
|
|
}
|
2009-01-28 23:12:03 +00:00
|
|
|
self.assertRaises(linkcheck.lc_cgi.LCFormError,
|
2004-08-16 19:20:06 +00:00
|
|
|
linkcheck.lc_cgi.checkform, form)
|
|
|
|
|
|
|
|
|
|
def test_form_invalid_url (self):
|
2005-01-19 14:38:01 +00:00
|
|
|
"""
|
|
|
|
|
Check url (in)validity.
|
|
|
|
|
"""
|
2004-08-16 19:20:06 +00:00
|
|
|
form = {"url": Store("http://www.foo bar/"),
|
|
|
|
|
"level": Store("0"),
|
|
|
|
|
}
|
2009-01-28 23:12:03 +00:00
|
|
|
self.assertRaises(linkcheck.lc_cgi.LCFormError,
|
2004-08-16 19:20:06 +00:00
|
|
|
linkcheck.lc_cgi.checkform, form)
|