Navigation Menu

Skip to content

Commit

Permalink
Fixed #14439 -- Improved documentation for running the GeoDjango test…
Browse files Browse the repository at this point in the history
… suite.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15015 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jbronn committed Dec 22, 2010
1 parent d66ab47 commit b6ab88c
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 36 deletions.
4 changes: 4 additions & 0 deletions docs/internals/contributing.txt
Expand Up @@ -853,6 +853,8 @@ discovered, please follow these guidelines:
* The release branch maintainer may back out commits to the release * The release branch maintainer may back out commits to the release
branch without permission if the commit breaks the release branch. branch without permission if the commit breaks the release branch.


.. _unit-tests:

Unit tests Unit tests
========== ==========


Expand All @@ -871,6 +873,8 @@ The Django tests all use the testing infrastructure that ships with Django for
testing applications. See :doc:`Testing Django applications </topics/testing>` testing applications. See :doc:`Testing Django applications </topics/testing>`
for an explanation of how to write new tests. for an explanation of how to write new tests.


.. _running-unit-tests:

Running the unit tests Running the unit tests
---------------------- ----------------------


Expand Down
122 changes: 86 additions & 36 deletions docs/ref/contrib/gis/testing.txt
Expand Up @@ -4,18 +4,13 @@ Testing GeoDjango Apps


.. versionchanged:: 1.2 .. versionchanged:: 1.2


In Django 1.2, the addition of :ref:`spatial-backends` In Django 1.2, the addition of :ref:`spatial-backends` simplified the
simplified the process of testing GeoDjango applications. Specifically, testing process of testing GeoDjango applications -- the process is now the
GeoDjango applications is now the same as :doc:`/topics/testing`. same as :doc:`/topics/testing`.


Included in this documentation are some additional notes and settings Included in this documentation are some additional notes and settings
for :ref:`testing-postgis` and :ref:`testing-spatialite` users. for :ref:`testing-postgis` and :ref:`testing-spatialite` users.


.. note::

Django 1.1 users are still required to use a custom :setting:`TEST_RUNNER`.
See the :ref:`testing-1.1` section for more details.

.. _testing-postgis: .. _testing-postgis:


PostGIS PostGIS
Expand All @@ -42,24 +37,21 @@ database to use. In Django versions 1.2 and above, it automatically
defaults to ``'template_postgis'`` (the same name used in the defaults to ``'template_postgis'`` (the same name used in the
:ref:`installation documentation <spatialdb_template>`). :ref:`installation documentation <spatialdb_template>`).


.. note::

Django 1.1 users will still have to define the :setting:`POSTGIS_TEMPLATE`
with a value, for example::

POSTGIS_TEMPLATE='template_postgis'

.. setting:: POSTGIS_VERSION .. setting:: POSTGIS_VERSION


``POSTGIS_VERSION`` ``POSTGIS_VERSION``
^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^

.. versionadded:: 1.1 .. versionadded:: 1.1


When GeoDjango's spatial backend initializes on PostGIS, it has to perform When GeoDjango's spatial backend initializes on PostGIS, it has to perform
a SQL query to determine the version. Setting the version manually a SQL query to determine the version in order to figure out what
prevents this query to the database:: features are available. Advanced users wishing to prevent this additional
query may set the version manually using a 3-tuple of integers specifying
the major, minor, and subminor version numbers for PostGIS. For example,
to configure for PostGIS 1.5.2 you would use::


POSTGIS_VERSION=('1.3.6', 1, 3, 6) POSTGIS_VERSION = (1, 5, 2)


Obtaining Sufficient Privileges Obtaining Sufficient Privileges
------------------------------- -------------------------------
Expand All @@ -74,6 +66,7 @@ you may be required to use a database superuser.


Create Database User Create Database User
^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^

To make database user with the ability to create databases, use the To make database user with the ability to create databases, use the
following command:: following command::


Expand All @@ -89,6 +82,7 @@ Alternatively, you may alter an existing user's role from the SQL shell


Create Database Superuser Create Database Superuser
^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^

This may be done at the time the user is created, for example:: This may be done at the time the user is created, for example::


$ createuser --superuser <user_name> $ createuser --superuser <user_name>
Expand All @@ -112,6 +106,7 @@ Create Local PostgreSQL Database


Windows Windows
------- -------

On Windows platforms the pgAdmin III utility may also be used as On Windows platforms the pgAdmin III utility may also be used as
a simple way to add superuser privileges to your database user. a simple way to add superuser privileges to your database user.


Expand Down Expand Up @@ -142,6 +137,7 @@ Settings


``SPATIALITE_SQL`` ``SPATIALITE_SQL``
^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^

.. versionadded:: 1.1 .. versionadded:: 1.1


By default, the GeoDjango test runner looks for the SpatiaLite SQL in the By default, the GeoDjango test runner looks for the SpatiaLite SQL in the
Expand All @@ -153,29 +149,83 @@ you may add the following to your settings::


__ http://www.gaia-gis.it/spatialite/init_spatialite-2.3.zip __ http://www.gaia-gis.it/spatialite/init_spatialite-2.3.zip


.. _testing-1.1:


Testing GeoDjango Applications in 1.1 .. _geodjango-tests:
=====================================


In Django 1.1, to accommodate the extra steps required to scaffalod a GeoDjango Tests
spatial database automatically, a test runner customized for GeoDjango ===============
must be used. To use this runner, configure :setting:`TEST_RUNNER` as follows::


TEST_RUNNER='django.contrib.gis.tests.run_tests' .. versionchanged:: 1.3


.. note:: GeoDjango's test suite may be run in one of two ways, either by itself or
with the rest of :ref:`Django's unit tests <unit-tests>`.

Run only GeoDjango tests
------------------------

To run *only* the tests for GeoDjango, the :setting:`TEST_RUNNER`
setting must be changed to use the
:class:`~django.contrib.gis.tests.GeoDjangoTestSuiteRunner`::

TEST_RUNNER = 'django.contrib.gis.tests.GeoDjangoTestSuiteRunner'

Example
^^^^^^^

First, you'll need a bare-bones settings file, like below, that is
customized with your spatial database name and user::

TEST_RUNNER = 'django.contrib.gis.tests.GeoDjangoTestSuiteRunner'

DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'a_spatial_database',
'USER': 'db_user'
}
}

Assuming the above is in a file called ``postgis.py`` that is in the
the same directory as ``manage.py`` of your Django project, then
you may run the tests with the following command::

$ python manage.py test --settings=postgis

Run with ``runtests.py``
------------------------

To have the GeoDjango tests executed when
:ref:`running the Django test suite <running-unit-tests>` with ``runtests.py``
all of the databases in the settings file must be using one of the
:ref:`spatial database backends <spatial-backends>`.

.. warning::

Do not change the :setting:`TEST_RUNNER` setting
when running the GeoDjango tests with ``runtests.py``.

Example
^^^^^^^


In order to create a spatial database, the :setting:`USER` setting The following is an example bare-bones settings file with spatial backends
(or :setting:`TEST_USER`, if optionally defined on Oracle) requires that can be used to run the entire Django test suite, including those
elevated privileges. When using PostGIS or MySQL, the database user in :mod:`django.contrib.gis`::
must have at least the ability to create databases. When testing on Oracle,
the user should be a superuser.


GeoDjango Test Suite DATABASES = {
==================== 'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'geodjango',
'USER': 'geodjango',
},
'other': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'other',
'USER': 'geodjango',
}
}


To run GeoDjango's own internal test suite, configure the Assuming the settings above were in a ``postgis.py`` file in the same
:setting:`TEST_RUNNER` setting as follows:: directory as ``runtests.py``, then all Django and GeoDjango tests would
be performed when executing the command::


TEST_RUNNER='django.contrib.gis.tests.run_gis_tests' $ ./runtests.py --settings=postgis
15 changes: 15 additions & 0 deletions docs/releases/1.3.txt
Expand Up @@ -185,6 +185,13 @@ If you provide a custom auth backend with ``supports_inactive_user`` set to
This is useful for further centralizing the permission handling. See the This is useful for further centralizing the permission handling. See the
:ref:`authentication docs <topics-auth>` for more details. :ref:`authentication docs <topics-auth>` for more details.


GeoDjango
~~~~~~~~~

The GeoDjango test suite is now included when
:ref:`running the Django test suite <running-unit-tests>` with ``runtests.py``
when using :ref:`spatial database backends <spatial-backends>`.

Everything else Everything else
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~


Expand Down Expand Up @@ -513,3 +520,11 @@ attribute.
Those commands have been deprecated. The ``flush`` and ``sqlflush`` commands Those commands have been deprecated. The ``flush`` and ``sqlflush`` commands
can be used to delete everything. You can also use ALTER TABLE or DROP TABLE can be used to delete everything. You can also use ALTER TABLE or DROP TABLE
statements manually. statements manually.


GeoDjango
~~~~~~~~~

The :setting:`TEST_RUNNER` previously used to execute the GeoDjango test suite,
:func:`django.contrib.gis.tests.run_gis_tests`, is deprecated in favor of
the :class:`django.contrib.gis.tests.GeoDjangoTestSuiteRunner` class.

0 comments on commit b6ab88c

Please sign in to comment.