[Inteproxy-commits] r37 - in trunk: . test

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Apr 5 20:10:28 CEST 2007


Author: bh
Date: 2007-04-05 20:10:28 +0200 (Thu, 05 Apr 2007)
New Revision: 37

Added:
   trunk/test/support.py
   trunk/test/test_transcoder_map.py
Modified:
   trunk/ChangeLog
Log:
* test/test_transcoder_map.py: New.  Test cases for the TranscoderMap

* test/support.py: New.  Support code for test cases


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-04-05 18:08:39 UTC (rev 36)
+++ trunk/ChangeLog	2007-04-05 18:10:28 UTC (rev 37)
@@ -1,5 +1,11 @@
 2007-04-05  Bernhard Herzog  <bh at intevation.de>
 
+	* test/test_transcoder_map.py: New.  Test cases for the TranscoderMap
+
+	* test/support.py: New.  Support code for test cases
+					 
+2007-04-05  Bernhard Herzog  <bh at intevation.de>
+
 	* transcoder.py (create_transcoder_map): New.  Creates the default
 	transcoder map
 

Added: trunk/test/support.py
===================================================================
--- trunk/test/support.py	2007-04-05 18:08:39 UTC (rev 36)
+++ trunk/test/support.py	2007-04-05 18:10:28 UTC (rev 37)
@@ -0,0 +1,48 @@
+# 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.
+
+"""Support code for the test cases"""
+
+import os
+
+def create_temp_dir():
+    """Create a temporary directory for the test-suite and return its name.
+
+    The temporary directory is always called temp and is created in the
+    directory where the support module is located.
+
+    If the temp directory already exists, just return the name.
+    """
+    name = os.path.abspath(os.path.join(os.path.dirname(__file__), "temp"))
+
+    # if the directory already exists, we're done
+    if os.path.isdir(name):
+        return name
+
+    # create the directory
+    os.mkdir(name)
+    return name
+
+
+class FileTestMixin:
+
+    """Mixin class for tests that use files in the temporary directory
+    """
+
+    def temp_file_name(self, basename):
+        """Return the full name of the file named basename in the temp. dir"""
+        return os.path.join(create_temp_dir(), basename)
+
+    def create_temp_file(self, basename, contents, mode = None):
+        """Create a file in the temp directory"""
+        filename = self.temp_file_name(basename)
+        file = open(filename, "w")
+        file.write(contents)
+        file.close()
+        if mode is not None:
+            os.chmod(filename, mode)
+        return filename


Property changes on: trunk/test/support.py
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Added: trunk/test/test_transcoder_map.py
===================================================================
--- trunk/test/test_transcoder_map.py	2007-04-05 18:08:39 UTC (rev 36)
+++ trunk/test/test_transcoder_map.py	2007-04-05 18:10:28 UTC (rev 37)
@@ -0,0 +1,65 @@
+# 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 TranscoderMap"""
+
+import unittest
+
+import support
+
+from transcoder import create_transcoder_map, \
+     OWSProxyGETTranscoder, OWSProxyPOSTTranscoder, IdentityTranscoder
+
+
+class TestTranscoderMap(unittest.TestCase, support.FileTestMixin):
+
+    config_contents = """\
+[inteproxy-demo.intevation.org]
+host=inteproxy-demo.intevation.org
+path=/cgi-bin/frida-wms
+class=owsproxy
+
+[example.com]
+host=example.com
+path=/foo
+class=owsproxy
+"""
+    #
+
+    def setUp(self):
+        self.config_filename = self.create_temp_file(self.id(),
+                                                     self.config_contents)
+
+    def test(self):
+        transcoder_map = create_transcoder_map()
+        transcoder_map.read_config(self.config_filename)
+
+        test_cases = [
+            ("GET", "inteproxy-demo.intevation.org", "/cgi-bin/frida-wms",
+             OWSProxyGETTranscoder),
+            ("POST", "inteproxy-demo.intevation.org", "/cgi-bin/frida-wms",
+             OWSProxyPOSTTranscoder),
+            ("GET", "inteproxy-demo.intevation.org", "/cgi-bin/frida",
+             IdentityTranscoder),
+            ("POST", "inteproxy-demo.intevation.org", "/cgi-bin/frida",
+             IdentityTranscoder),
+
+            ("GET", "example.com", "/foo",
+             OWSProxyGETTranscoder),
+            ("POST", "example.com", "/foo",
+             OWSProxyPOSTTranscoder),
+
+            # Example for a non-WMS request sent by deejump
+            ("GET", "schemas.opengeospatial.net",
+             "/wms/1.1.1/WMS_MS_Capabilities.dtd", IdentityTranscoder),
+            ]
+
+        for method, host, path, expectedcls in test_cases:
+            cls = transcoder_map.lookup(method, host, path)
+            msg=("Wrong class for %(method)s %(host)s%(path)s:"
+                 " got %(cls)s expected %(expectedcls)s" % locals())
+            self.assertEquals(cls, expectedcls, msg)


Property changes on: trunk/test/test_transcoder_map.py
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native



More information about the Inteproxy-commits mailing list