1 |
joey |
2108 |
# Copyright (c) 2004 by Intevation GmbH |
2 |
|
|
# Authors: |
3 |
|
|
# Martin Schulze <[email protected]> |
4 |
|
|
# |
5 |
|
|
# This program is free software under the GPL (>=v2) |
6 |
|
|
# Read the file COPYING coming with Thuban for details. |
7 |
|
|
|
8 |
|
|
""" |
9 |
|
|
Test for the PyOGCLib from Sean C. Gillies |
10 |
|
|
|
11 |
|
|
http://www.sourceforge.net/projects/pyogclib |
12 |
|
|
|
13 |
|
|
Requires the ogclib installed regularily on the system or checked out |
14 |
|
|
next to the thuban checkout |
15 |
|
|
""" |
16 |
|
|
|
17 |
|
|
__version__ = "$Revision$" |
18 |
|
|
# $Source$ |
19 |
|
|
# $Id$ |
20 |
|
|
|
21 |
|
|
import os |
22 |
|
|
import unittest |
23 |
|
|
|
24 |
|
|
from string import split |
25 |
|
|
|
26 |
|
|
# ---------------------------------------------------------------------- |
27 |
|
|
# FIXME: Temporary code until PyOGCLib is a standard requirement |
28 |
|
|
|
29 |
|
|
from sys import path |
30 |
|
|
|
31 |
|
|
# Assume the PyOGCLib to be checked out next to the thuban main directory |
32 |
|
|
pyogclib = "../../../../PyOGCLib" |
33 |
|
|
if os.path.isdir (pyogclib) and os.path.isdir (pyogclib + "/ogclib"): |
34 |
|
|
path.insert (0, pyogclib) |
35 |
|
|
# ---------------------------------------------------------------------- |
36 |
|
|
|
37 |
|
|
try: |
38 |
|
|
from ogclib.WMSClient import WMSClient |
39 |
|
|
except: |
40 |
|
|
print "No PyOGCLib found, hence no tests available." |
41 |
|
|
os._exit(-1) |
42 |
|
|
|
43 |
|
|
|
44 |
|
|
class TestOGCLib (unittest.TestCase, WMSClient): |
45 |
|
|
""" |
46 |
|
|
Defines a test environment for the PyOGCLib, i.e. check whether URL |
47 |
|
|
strings are built properly. |
48 |
|
|
""" |
49 |
|
|
|
50 |
|
|
def compare_URLs (self, foo, bar): |
51 |
|
|
""" |
52 |
|
|
Check if two URLs are equal, i.e.: |
53 |
|
|
- check for same base URL |
54 |
|
|
- check same number of HTTP GET arguments |
55 |
|
|
- check whether all arguments from one URL also exist in the second |
56 |
|
|
""" |
57 |
|
|
|
58 |
|
|
foo_tuple = split (foo, "?") |
59 |
|
|
bar_tuple = split (bar, "?") |
60 |
|
|
|
61 |
|
|
# Check for same base URL |
62 |
|
|
if foo_tuple[0] != bar_tuple[0]: |
63 |
|
|
self.fail ("%s != %s" % (foo_tuple[0], bar_tuple[0])) |
64 |
|
|
|
65 |
|
|
# Check for same number of HTTP GET arguments |
66 |
|
|
if len(foo_tuple) != len(bar_tuple): |
67 |
|
|
self.fail ("One URL has no arguments"); |
68 |
|
|
|
69 |
|
|
# Loop through all HTTP GET arguments for existance |
70 |
|
|
if len(foo_tuple) > 1 and len(bar_tuple) > 1: |
71 |
|
|
foo_opts = split (foo_tuple[1], "&") |
72 |
|
|
bar_opts = split (bar_tuple[1], "&") |
73 |
|
|
|
74 |
|
|
if len(foo_opts) != len(bar_opts): |
75 |
|
|
self.fail ("different number of arguments"); |
76 |
|
|
|
77 |
|
|
for part in foo_opts: |
78 |
|
|
if part not in bar_opts: |
79 |
|
|
self.fail ("%s not in second argument list" % part); |
80 |
|
|
|
81 |
|
|
|
82 |
|
|
def test_compareURLs (self): |
83 |
|
|
"""Perform some tests for own compare routine""" |
84 |
|
|
|
85 |
|
|
result = "http://frida.intevation.org/cgi-bin" |
86 |
|
|
self.compare_URLs ("http://frida.intevation.org/cgi-bin", result) |
87 |
|
|
|
88 |
|
|
result = "http://frida.intevation.org/cgi-bin?foo=eins" |
89 |
|
|
self.compare_URLs ("http://frida.intevation.org/cgi-bin?foo=eins", result) |
90 |
|
|
|
91 |
|
|
result = "http://frida.intevation.org/cgi-bin?foo=eins&bar=zwei" |
92 |
|
|
self.compare_URLs ("http://frida.intevation.org/cgi-bin?foo=eins&bar=zwei", result) |
93 |
|
|
|
94 |
|
|
result = "http://frida.intevation.org/cgi-bin?foo=eins&bar=zwei" |
95 |
|
|
self.compare_URLs ("http://frida.intevation.org/cgi-bin?bar=zwei&foo=eins", result) |
96 |
|
|
|
97 |
|
|
result = "http://frida.intevation.org/cgi-bin?foo=eins&bar=zwei&baz=jan&quux=tux" |
98 |
|
|
self.compare_URLs ("http://frida.intevation.org/cgi-bin?baz=jan&bar=zwei&quux=tux&foo=eins", result) |
99 |
|
|
|
100 |
|
|
|
101 |
|
|
def test_CapabilityURL (self): |
102 |
|
|
"""Test the getCapabilitiesURL() method""" |
103 |
|
|
|
104 |
|
|
frida = "http://frida.intevation.org/cgi-bin/frida_wms?" |
105 |
|
|
|
106 |
|
|
url = self.getCapabilitiesURL(frida, "1.0") |
107 |
|
|
result = frida + "WMTVER=1.0&REQUEST=capabilities" |
108 |
|
|
self.compare_URLs (url, result) |
109 |
|
|
|
110 |
|
|
url = self.getCapabilitiesURL(frida, "1.1") |
111 |
|
|
result = frida + "VERSION=1.1&SERVICE=WMS&REQUEST=GetCapabilities" |
112 |
|
|
self.compare_URLs (url, result) |
113 |
|
|
|
114 |
|
|
|
115 |
|
|
if __name__ == "__main__": |
116 |
|
|
unittest.main() |