[Inteproxy-commits] r24 - in trunk: . test
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Feb 8 13:07:08 CET 2007
Author: bh
Date: 2007-02-08 13:07:08 +0100 (Thu, 08 Feb 2007)
New Revision: 24
Added:
trunk/test/
trunk/test/runtests.py
trunk/test/test_owsproxy_get_transcoder.py
trunk/test/test_owsproxy_post_transcoder.py
Modified:
trunk/ChangeLog
Log:
* test/runtests.py, test/test_owsproxy_post_transcoder.py,
test/test_owsproxy_get_transcoder.py: New files with the
beginnings of a test suite.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-02-08 11:50:28 UTC (rev 23)
+++ trunk/ChangeLog 2007-02-08 12:07:08 UTC (rev 24)
@@ -1,5 +1,11 @@
2007-02-08 Bernhard Herzog <bh at intevation.de>
+ * test/runtests.py, test/test_owsproxy_post_transcoder.py,
+ test/test_owsproxy_get_transcoder.py: New files with the
+ beginnings of a test suite.
+
+2007-02-08 Bernhard Herzog <bh at intevation.de>
+
* transcoder.py (OWSProxyGETTranscoder.get_url): Quote username
and password properly.
Added: trunk/test/runtests.py
===================================================================
--- trunk/test/runtests.py 2007-02-08 11:50:28 UTC (rev 23)
+++ trunk/test/runtests.py 2007-02-08 12:07:08 UTC (rev 24)
@@ -0,0 +1,72 @@
+# Copyright (C) 2007 by Intevation GmbH
+# Authors:
+# Bernhard Herzog <bh at intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+"""
+Main entry point for the InteProxy test suite.
+
+Just run this file as a python script to execute all tests
+"""
+
+import os
+import sys
+import unittest
+import optparse
+
+test_dir = os.path.dirname(__file__)
+sys.path.append(os.path.join(test_dir, os.pardir))
+
+def find_test_modules(dirname, package = None):
+ """Return a list the names of the test modules in the directory dirname
+
+ The return value is a list of names that can be passed to
+ unittest.defaultTestLoader.loadTestsFromNames. Each name of the
+ list is the name of a pure python module, one for each file in
+ dirname whose name starts with 'test' and ends with '.py'.
+
+ The optional parameter package should be the name of the python
+ package whose directory is dirname. If package is given all names
+ in the returned list will be prefixed with package and a dot.
+ """
+ if package:
+ prefix = package + "."
+ else:
+ prefix = ""
+
+ suffix = ".py"
+ return [prefix + name[:-len(suffix)]
+ for name in os.listdir(dirname)
+ if name.startswith("test") and name.endswith(suffix)]
+
+
+def main():
+ """Run all the tests in the test suite"""
+
+ parser = optparse.OptionParser()
+ parser.set_defaults(verbosity=1)
+ parser.add_option("-v", "--verbose", action="store_const", const=2,
+ dest="verbosity")
+ opts, rest = parser.parse_args()
+
+ # Build the list of test names. If names were given on the command
+ # line, run exactly those. Othwerwise build a default list of
+ # names.
+ if rest:
+ names = rest
+ else:
+ # All Python files starting with 'test' in the current directory
+ # and some directories in Extensions contain test cases.
+ # FIXME: It should be possible to run runtests.py even when not in
+ # the test directory
+ names = find_test_modules(test_dir)
+ suite = unittest.defaultTestLoader.loadTestsFromNames(names)
+ runner = unittest.TextTestRunner(verbosity=opts.verbosity)
+ result = runner.run(suite)
+ sys.exit(not result.wasSuccessful())
+
+
+if __name__ == "__main__":
+ main()
Property changes on: trunk/test/runtests.py
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: trunk/test/test_owsproxy_get_transcoder.py
===================================================================
--- trunk/test/test_owsproxy_get_transcoder.py 2007-02-08 11:50:28 UTC (rev 23)
+++ trunk/test/test_owsproxy_get_transcoder.py 2007-02-08 12:07:08 UTC (rev 24)
@@ -0,0 +1,49 @@
+# Copyright (C) 2007 by Intevation GmbH
+# Authors:
+# Bernhard Herzog <bh at intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+"""Tests for OWSProxyGETTranscoder"""
+
+import urlparse
+import unittest
+
+from transcoder import OWSProxyGETTranscoder
+
+
+class TestOWSProxyGETTranscoder(unittest.TestCase):
+
+ def test_username_password_substitution(self):
+
+ class Transcoder(OWSProxyGETTranscoder):
+ """
+ An OWSProxyGETTranscoder that uses usernames/passwords
+ defined in this test case
+ """
+ def get_password(self):
+ return user, password
+
+
+ test_users = [("user", "password",
+ "https://example.com/wfs",
+ "https://example.com/wfs?user=user&password=password"),
+ ("foo", "bar",
+ # base url with trailing ?
+ "https://example.com/wfs?",
+ "https://example.com/wfs?user=foo&password=bar"),
+ ("foo", "bar",
+ # base url with existing query
+ "https://example.com/wfs?REQUEST=GetCapabilities"
+ "&VERSION=1.1.0&SERVICE=WFS",
+ "https://example.com/wfs?REQUEST=GetCapabilities"
+ "&VERSION=1.1.0&SERVICE=WFS&user=foo&password=bar"),
+ ("some \xc3\xbcser&", "<pass&>word?",
+ "https://example.com/wfs",
+ "https://example.com/wfs?"
+ "user=some+%C3%BCser%26&password=%3Cpass%26%3Eword%3F"),
+ ]
+ for user, password, baseurl, encodedurl in test_users:
+ transcoder = Transcoder("GET", urlparse.urlsplit(baseurl))
+ self.assertEquals(transcoder.get_url(), encodedurl)
Property changes on: trunk/test/test_owsproxy_get_transcoder.py
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: trunk/test/test_owsproxy_post_transcoder.py
===================================================================
--- trunk/test/test_owsproxy_post_transcoder.py 2007-02-08 11:50:28 UTC (rev 23)
+++ trunk/test/test_owsproxy_post_transcoder.py 2007-02-08 12:07:08 UTC (rev 24)
@@ -0,0 +1,70 @@
+# Copyright (C) 2007 by Intevation GmbH
+# Authors:
+# Bernhard Herzog <bh at intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+"""Tests for OWSProxyPOSTTranscoder"""
+
+import unittest
+from transcoder import OWSProxyPOSTTranscoder
+
+
+class TestOWSProxyPOSTTranscoder(unittest.TestCase):
+
+ get_feature_orig = (
+ '<?xml version="1.0" encoding="ISO-8859-1"?>'
+ '<wfs:GetFeature'
+ ' xmlns:ogc="http://www.opengis.net/ogc"'
+ ' xmlns:gml="http://www.opengis.net/gml"'
+ ' xmlns:wfs="http://www.opengis.net/wfs"'
+ ' outputFormat="text/xml; subtype=gml/3.1.1">'
+ '<wfs:Query'
+ ' xmlns:app="http://www.deegree.org/app"'
+ ' typeName="app:flurst">'
+ '<wfs:PropertyName>app:the_geom</wfs:PropertyName>'
+ '<wfs:PropertyName>app:objnr</wfs:PropertyName>'
+ '</wfs:Query>'
+ '</wfs:GetFeature>')
+
+ get_feature_modified_template = (
+ "<?xml version='1.0' encoding='ASCII'?>\n"
+ '<wfs:GetFeature'
+ ' xmlns:ogc="http://www.opengis.net/ogc"'
+ ' xmlns:gml="http://www.opengis.net/gml"'
+ ' xmlns:wfs="http://www.opengis.net/wfs"'
+ ' outputFormat="text/xml; subtype=gml/3.1.1"'
+ ' user=%(userattr)s password=%(passwordattr)s>'
+ '<wfs:Query'
+ ' xmlns:app="http://www.deegree.org/app"'
+ ' typeName="app:flurst">'
+ '<wfs:PropertyName>app:the_geom</wfs:PropertyName>'
+ '<wfs:PropertyName>app:objnr</wfs:PropertyName>'
+ '</wfs:Query>'
+ '</wfs:GetFeature>')
+
+ def test_username_password_substitution(self):
+
+ class Transcoder(OWSProxyPOSTTranscoder):
+ """
+ An OWSProxyPOSTTranscoder that uses usernames/passwords
+ defined in this test case
+ """
+ def get_password(self):
+ return user, password
+
+
+ test_users = [("user", "password", '"user"', '"password"'),
+ (u"some \xfcser&", "<pass&>word",
+ '"some üser&"', '"<pass&>word"'),
+ ]
+ for user, password, userattr, passwordattr in test_users:
+ transcoder = Transcoder("POST",
+ ("https", "example.com", "wfs", "", ""))
+ converted_body = transcoder.convert_body(None,
+ self.get_feature_orig)
+ self.assertEquals(converted_body[1],
+ self.get_feature_modified_template % locals())
+ self.assertEquals(converted_body[0],
+ "text/xml")
Property changes on: trunk/test/test_owsproxy_post_transcoder.py
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
More information about the Inteproxy-commits
mailing list