[Qgis-developer] Unit testing QGIS Server, assistance requested

Larry Shaffer larrys at dakotacarto.com
Wed Aug 21 11:46:10 PDT 2013


Hi,

Today I committed a simple Python interface to running queries to a local
QGIS Server [0] (qgis_local_server.py). This was to aid in creating unit
tests for labeling, but could be used for other tests/purposes. It requires
an existing, running Server available via TCP/IP. It can be run directly
from command line, to aid in testing configuration, just make sure
<qgis-build-dir>/output/python is on sys.path.

Until build/test servers are updated with access to a local test Server,
all associated Server unit tests will be skipped. I am requesting that,
where possible, any of those servers be configured with a local test QGIS
Server.

Before I continue explaining how to setup the local server configuration
for tests, I have to ask: is there a better way to control qgis_map_serv
via Python? Seems like in addition to FCGI, offering some type of WSGI
interface would be very nice. I have an idea for a standalone, spawned
local test server, noted below.

Configuring local test QGIS Server for tests:

1) After attempting to run first invocation of any labeling unit tests
(labeling is only place it is used so far), a configuration file should be
created at: <current user>/.qgis2/qgis_local_server.cfg. You can set server
access url parameters in that file...

[LocalServer]  (my setup on Mac)
protocol = http
host = qgis-server-test.localhost
port = 8888
fcgipath = /fcgi-bin/qgis_mapserv.fcgi
sourceurl = %(protocol)s://%(host)s:%(port)s%(fcgipath)s
projdir = /test-projects/tests

2) The config setting of 'projdir' needs to be writeable by the test/script
runner and readable by the local QGIS Server. This allows a unit test to
copy to that directory a project.qgs with associated .qml files and and
data sources. The running Server can access that project via the MAP url
parameter. See example under __main__ in qgis_local_server.py.

3) A unit test calls the QgisLocalServerConfig.getMap(url_params) and
receives a tuple of the result success and path to output as a PNG file
(for render comparison checks).

4) Since qgis_map_serv is FCGI, any running instance will need to be
re-spawned before unit tests are run against it, so new changes pulled from
git repo will be reflected. I have my qgis_map_serv.fcgi set up as a
symlink from <qgis-build-dir>/output/bin/qgis_mapserv.fcgi. This is one
example of where having a locally spawned instance of qgis_map_serv will
help.


Running qgis_map_serv as a locally spawned process for unit testing (my
proposal):

* Add spawn-fcgi source code [1] from lighttpd to <qgis-src>/tests/. It has
an optional cmake build setup, which can be integrated into QGIS's. It has
(I believe) a compatible license [2].

* When building QGIS with ENABLE_TESTS, spawn-fcgi is built and used to
launch qgis_map_serv in a fixture at the beginning of unit tests. I have
used a similar setup to run QGIS Server successfully under Nginx.

* Add a lightweight, pure python module that creates a standalone HTTP
server that connects as a FCGI client to the spawned qgis_map_serv. There
are several choices for this, most under permissive/compatible licenses,
e.g. Flup [2]. Then, QgisLocalServerConfig's qgis_local_server.cfg can be
hard-coded to this standalone server.

Any ideas on a different setup, or comments on this one? I think it would
be good to have a standalone test server for unit tests.

[0] https://github.com/qgis/Quantum-GIS/commit/dd26e611
[1] http://redmine.lighttpd.net/projects/spawn-fcgi ,
http://redmine.lighttpd.net/projects/spawn-fcgi/repository/show/trunk
[2]
http://redmine.lighttpd.net/projects/spawn-fcgi/repository/entry/trunk/COPYING
[3] http://hg.saddi.com/flup-server/file/tip/flup/client/fcgi_app.py

Best regards,

Larry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20130821/377acdfd/attachment-0001.html>


More information about the Qgis-developer mailing list