attribute: Phillie Casablanca

Geodjango testing on windows with postgres/postgis



While trying to get django's builtin testing system working (http://docs.djangoproject.com/en/dev/topics/testing/) with postgres/postgis and geodjango I hit a roadblock.

Basically, I was hoping it would just work, but my first attempt brought up an exception:


$ python manage.py test myapp
Creating new spatial database...
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python26\Lib\site-packages\django\core\management\__init__.py", line 340, in execute_manager
utility.execute()
File "C:\Python26\Lib\site-packages\django\core\management\__init__.py", line 295, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python26\Lib\site-packages\django\core\management\base.py", line 192, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python26\Lib\site-packages\django\core\management\base.py", line 219, in execute
output = self.handle(*args, **options)
File "C:\Python26\Lib\site-packages\django\core\management\commands\test.py", line 33, in handle
failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive)
File "C:\Python26\Lib\site-packages\django\contrib\gis\tests\__init__.py", line 196, in run_tests
create_spatial_db(test=True, verbosity=verbosity)
File "C:\Python26\Lib\site-packages\django\contrib\gis\db\backend\postgis\creation.py", line 118, in create_spatial_d

load_postgis_sql(db_name, verbosity=verbosity)
File "C:\Python26\Lib\site-packages\django\contrib\gis\db\backend\postgis\creation.py", line 189, in load_postgis_sql
raise Exception('Could not find PostGIS function definitions in %s' % lwpostgis_file)
Exception: Could not find PostGIS function definitions in C:/PROGRA~1/POSTGR~1/8.3/share\lwpostgis.sql

ugh! Ok, so searching around I found this nice series of posts describing the issue:

http://www.pointy-stick.com/blog/2009/03/03/testing-geodjango/
http://www.pointy-stick.com/blog/2009/03/06/testing-geodjango-part-2/

I'm running postgres/postgis on windows and so I added the following to my settings file (I'm using Django 1.0.2):

POSTGIS_SQL_PATH = 'C:\\Program Files\\PostgreSQL\\8.3\\share\\contrib'
TEST_RUNNER='django.contrib.gis.tests.run_tests'

Runnning tests for myapp again, asked for the postgres db password when trying to run some sql found in the contrib directory, but it now appears to run successfully!


monkut // May 7, 2009 // 8:04 a.m.