#!/usr/bin/env python # coding=utf-8 # # import unittest import logging import os,sys from ConfigParser import ConfigParser import urllib import urlparse OWSVIEWER_DIR=os.path.abspath(os.path.join(os.path.dirname(__file__),"..")) sys.path.append(OWSVIEWER_DIR) from OWS import * class TestOWS(unittest.TestCase): """Base class for OWS services (WFS, WCS) """ owsUrl = None config = None service = None def setUp(self): # set logging logging.basicConfig(level=logging.DEBUG) # mapfile for original services mapfile = os.path.join(OWSVIEWER_DIR,"tests","mapfiles","ows.map") self.config = ConfigParser.ConfigParser() self.config.read(os.path.join(OWSVIEWER_DIR,"tests","test.cfg")) self.owsUrl = self._getURLWithMap(mapfile) os.environ.update({"QUERY_STRING": "owsService=%s&owsUrl=%s"%(self.service,urllib.quote(self.owsUrl))}) self.service = getService() def _getURLWithMap(self,mapfile): # create URL which will produce WCS and WFS services for testing # purposes owsUrl = urlparse.urlparse(self.config.get("OWSServer","owsserver")) owsParams = urlparse.parse_qs(owsUrl[4]) owsParams["map"] = mapfile return urlparse.urlunparse((owsUrl[0],owsUrl[1],owsUrl[2], owsUrl[3], urllib.unquote(urllib.urlencode(owsParams,True)),owsUrl[5])) def _getWMSCapabilities(self): # download the WMS Capabilities url = self._getURLWithMap(self.service.mapfilename) url = urlparse.urlparse(url) params = urlparse.parse_qs(url[4]) params["REQUEST"] = "GetCapabilities" params["SERVICE"] = "WMS" params = urllib.unquote(urllib.urlencode(params,True)) attrs = (url[0],url[1],url[2],url[3],params,url[5]) logging.debug("GetCapabilities URL: " + urlparse.urlunparse(attrs)) resp = objectify.parse(urllib.urlopen(urlparse.urlunparse(attrs))) return resp.getroot()