Skip to content

Commit

Permalink
Adds ability to test against GeoDjango projects that require a spatial
Browse files Browse the repository at this point in the history
database.
  • Loading branch information
ipmb committed Nov 23, 2009
1 parent f3b00a1 commit 504b723
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.rst
Expand Up @@ -30,6 +30,11 @@ your ``INSTALLED_APPS`` in ``settings.py``: ::
Then set ``TEST_RUNNER`` in ``settings.py``: ::

TEST_RUNNER = 'django_nose.run_tests'
If you are using ``django.contrib.gis`` (GeoDjango) and need a spatial database
to run your tests, use the GIS test runner instead: ::

TEST_RUNNER = 'django_nose.run_gis_tests'

Usage
-----
Expand Down
14 changes: 12 additions & 2 deletions django_nose/runner.py
Expand Up @@ -19,13 +19,20 @@

from django_nose.plugin import ResultPlugin

def run_gis_tests(test_labels, verbosity=1, interactive=True):
"""Test runner that invokes nose with a spatial database for GeoDjango."""
run_tests(test_labels, verbosity=1, interactive=True, use_spatial_db=True)

def run_tests(test_labels, verbosity=1, interactive=True):
def run_tests(test_labels, verbosity=1, interactive=True, use_spatial_db=False):
"""Test runner that invokes nose."""
# Prepare django for testing.
utils.setup_test_environment()
old_db_name = settings.DATABASE_NAME
connection.creation.create_test_db(verbosity, autoclobber=not interactive)
if use_spatial_db:
from django.contrib.gis.db.backend import create_test_spatial_db
create_test_spatial_db(verbosity, autoclobber=not interactive)
else:
connection.creation.create_test_db(verbosity, autoclobber=not interactive)

# Pretend it's a production environment.
settings.DEBUG = False
Expand Down Expand Up @@ -73,3 +80,6 @@ def _get_options():

run_tests.options = _get_options()
run_tests.__test__ = False

run_gis_tests.options = _get_options()
run_gis_tests.__test__ = False

0 comments on commit 504b723

Please sign in to comment.