Automated WMS Testing with Python


This post and associated script details how to automate testing WMS (Web Mapping Service) layers. When you’ve set up several MapServer or GeoServer instances with 100s of layers, its nice to be able to make sure everything continues to run smoothly.

The automation makes maintenance proactive, rather than reacting to client’s emails wondering where their data has gone, and it beats pasting long obfuscated URLS into a browser and repeatedly pressing F5..

This script combines three of my current favourite Python libraries.

  • OWSLib a Python OGC Web Service utility library
  • PIL – The Python Imaging Library (PIL) used for image processing
  • Requests – a Python library to make web requests – “HTTP for Humans”

The PIL site handily contains Windows installers for nearly every version of Python. OWSLib and Requests can be added to your Python installation with easy_install, or PIP. I’m currently sticking with Python 2.6 as many scripts and packages I’m writing need to work with ArcGIS, which requires this version, and also on Windows, which puts me very much in the minority in the Python world outside of ESRI users.

In summary the script does the following:

  1. Connects to the WMS Server to retrieve a list of all the WMS layers.
  2. For each layer it finds the maximum extent of the layer and its projection code.
  3. A GetMap request is made to the WMS server for the layer at the maximum extent.
  4. Any errors getting the image can be reported. If an image is returned it is analysed to check if it is empty or blank.

I then adapted the sample script to work with Python’s unittest module so I could get a nice list of passes and fails for each map layer, and for a variety of issues such as HTTP failures or removed layers. It is then a simple step to set up a Windows Task Schedule to do a daily check that all WMS servers are up and running and returning data.



3 views shared on this article. Join in...

  1. drnextgis says:

    Thanks for post! But I didn’t find OWSLib import in your source code.

    • geographika says:

      Thanks for spotting that! It was imported already into my Python session when I was testing. I have updated the code to include from owslib.wms import WebMapService at the top of the script.

  2. Thanks for this. Any hope of having a WFS tester integrated as well?

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment

You may use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>