diff options
author | Brian C. Lane <bcl@redhat.com> | 2010-06-17 11:51:36 -0700 |
---|---|---|
committer | Brian C. Lane <bcl@redhat.com> | 2010-06-17 13:10:18 -0700 |
commit | 7a5dbbca6bbcfd66d6f762856a565af96729b8f1 (patch) | |
tree | 1aab76c9e728f0a8f1bfede46de234a2b09a841f /tests | |
parent | 68e82b6994e1a88ecd9d19e2a79fc4a93573f6b6 (diff) | |
download | anaconda-7a5dbbca6bbcfd66d6f762856a565af96729b8f1.tar.gz anaconda-7a5dbbca6bbcfd66d6f762856a565af96729b8f1.tar.xz anaconda-7a5dbbca6bbcfd66d6f762856a565af96729b8f1.zip |
Add test cases for proxy regex (#602712)
Check for proper operation of the proxy regex. The regex neeeds to be
copied over from yuminstall.py if it changes.
Related: rhbz#602712
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/regex/Makefile.am | 22 | ||||
-rw-r--r-- | tests/regex/__init__.py | 0 | ||||
-rw-r--r-- | tests/regex/proxy.py | 111 |
4 files changed, 134 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 6ee2cea41..ee05e4815 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -17,6 +17,6 @@ # # Author: David Cantrell <dcantrell@redhat.com> -SUBDIRS = mock kickstart_test storage_test +SUBDIRS = mock kickstart_test storage_test regex MAINTAINERCLEANFILES = Makefile.in diff --git a/tests/regex/Makefile.am b/tests/regex/Makefile.am new file mode 100644 index 000000000..af1bd58fd --- /dev/null +++ b/tests/regex/Makefile.am @@ -0,0 +1,22 @@ +# tests/regex/Makefile.am for anaconda +# +# Copyright (C) 2010 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# Author: Brian C. Lane <bcl@redhat.com> + +EXTRA_DIST = *.py + +MAINTAINERCLEANFILES = Makefile.in diff --git a/tests/regex/__init__.py b/tests/regex/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/regex/__init__.py diff --git a/tests/regex/proxy.py b/tests/regex/proxy.py new file mode 100644 index 000000000..767330d39 --- /dev/null +++ b/tests/regex/proxy.py @@ -0,0 +1,111 @@ +import unittest +import re +import traceback + + +class ProxyRegexTestCase(unittest.TestCase): + def testProxy(self): + """ + Run a list of possible proxy= values through the regex and check for + correct results. + + tests are in the form of: (proxy string, match.groups() tuple) + """ + tests = [ ( "proxy.host", + (None, None, None, None, 'proxy.host', None, None) ), + + ( "proxy.host:3128", + (None, None, None, None, 'proxy.host', ':3128', None) ), + + ( "user:password@proxy.host", + (None, 'user:password@', 'user', ':password', 'proxy.host', None, None) ), + + ( "user@proxy.host", + (None, 'user@', 'user', None, 'proxy.host', None, None) ), + + ( "user:password@proxy.host:3128", + (None, 'user:password@', 'user', ':password', 'proxy.host', ':3128', None) ), + + ( "user@proxy.host:3128", + (None, 'user@', 'user', None, 'proxy.host', ':3128', None) ), + + ( "proxy.host/blah/blah", + (None, None, None, None, 'proxy.host', None, '/blah/blah') ), + + ( "proxy.host:3128/blah/blah", + (None, None, None, None, 'proxy.host', ':3128', '/blah/blah') ), + + ( "user:password@proxy.host/blah/blah", + (None, 'user:password@', 'user', ':password', 'proxy.host', None, '/blah/blah') ), + + ( "user@proxy.host/blah/blah", + (None, 'user@', 'user', None, 'proxy.host', None, '/blah/blah') ), + + ( "user:password@proxy.host:3128/blah/blah", + (None, 'user:password@', 'user', ':password', 'proxy.host', ':3128', "/blah/blah") ), + + ( "user@proxy.host:3128/blah/blah", + (None, 'user@', 'user', None, 'proxy.host', ':3128', "/blah/blah") ), + + + + ( "http://proxy.host", + ('http://', None, None, None, 'proxy.host', None, None) ), + + ( "http://proxy.host:3128", + ('http://', None, None, None, 'proxy.host', ':3128', None) ), + + ( "http://user:password@proxy.host", + ('http://', 'user:password@', 'user', ':password', 'proxy.host', None, None) ), + + ( "http://user@proxy.host", + ('http://', 'user@', 'user', None, 'proxy.host', None, None) ), + + ( "http://user:password@proxy.host:3128", + ('http://', 'user:password@', 'user', ':password', 'proxy.host', ':3128', None) ), + + ( "http://user@proxy.host:3128", + ('http://', 'user@', 'user', None, 'proxy.host', ':3128', None) ), + + ( "http://proxy.host/blah/blah", + ('http://', None, None, None, 'proxy.host', None, '/blah/blah') ), + + ( "http://proxy.host:3128/blah/blah", + ('http://', None, None, None, 'proxy.host', ':3128', '/blah/blah') ), + + ( "http://user:password@proxy.host/blah/blah", + ("http://", 'user:password@', 'user', ':password', 'proxy.host', None, '/blah/blah') ), + + ( "http://user@proxy.host/blah/blah", + ("http://", 'user@', 'user', None, 'proxy.host', None, '/blah/blah') ), + + ( "http://user:password@proxy.host:3128/blah/blah", + ("http://", 'user:password@', 'user', ':password', 'proxy.host', ':3128', '/blah/blah') ), + + ( "http://user@proxy.host:3128/blah/blah", + ("http://", 'user@', 'user', None, 'proxy.host', ':3128', '/blah/blah') ), + + ] + + + # This is from yumupdate.py and needs to be updated when it changes + pattern = re.compile("([A-Za-z]+://)?(([A-Za-z0-9]+)(:[^:@]+)?@)?([^:/]+)(:[0-9]+)?(/.*)?") + + got_error = False + for proxy, result in tests: + try: + self.assertEqual(pattern.match(proxy).groups(), result) + except AssertionError as error: + got_error = True + print error + + if got_error: + self.fail() + +def suite(): + return unittest.TestLoader().loadTestsFromTestCase(ProxyRegexTestCase) + + +if __name__ == "__main__": + unittest.main() + |