5
.. versionchanged:: 1.2
7
In Django 1.2, the addition of :ref:`spatial-backends`
8
simplified the process of testing GeoDjango applications. Specifically, testing
9
GeoDjango applications is now the same as :ref:`topics-testing`.
11
Included in this documentation are some additional notes and settings
12
for :ref:`testing-postgis` and :ref:`testing-spatialite` users.
16
Django 1.1 users are still required to use a custom :setting:`TEST_RUNNER`.
17
See the :ref:`testing-1.1` section for more details.
29
The settings below have sensible defaults, and shouldn't require manual setting.
31
.. setting:: POSTGIS_TEMPLATE
38
.. versionchanged:: 1.2
40
This setting may be used to customize the name of the PostGIS template
41
database to use. In Django versions 1.2 and above, it automatically
42
defaults to ``'template_postgis'`` (the same name used in the
43
:ref:`installation documentation <spatialdb_template>`).
47
Django 1.1 users will still have to define the :setting:`POSTGIS_TEMPLATE`
48
with a value, for example::
50
POSTGIS_TEMPLATE='template_postgis'
52
.. setting:: POSTGIS_VERSION
58
When GeoDjango's spatial backend initializes on PostGIS, it has to perform
59
a SQL query to determine the version. Setting the version manually
60
prevents this query to the database::
62
POSTGIS_VERSION=('1.3.6', 1, 3, 6)
64
Obtaining Sufficient Privileges
65
-------------------------------
67
Depending on your configuration, this section describes several methods to
68
configure a database user with sufficient privileges to run tests for
69
GeoDjango applications on PostgreSQL. If your
70
:ref:`spatial database template <spatialdb_template>`
71
was created like in the instructions, then your testing database user
72
only needs to have the ability to create databases. In other configurations,
73
you may be required to use a database superuser.
77
To make database user with the ability to create databases, use the
80
$ createuser --createdb -R -S <user_name>
82
The ``-R -S`` flags indicate that we do not want the user to have the ability
83
to create additional users (roles) or to be a superuser, respectively.
85
Alternatively, you may alter an existing user's role from the SQL shell
86
(assuming this is done from an existing superuser account)::
88
postgres# ALTER ROLE <user_name> CREATEDB NOSUPERUSER NOCREATEROLE;
90
Create Database Superuser
91
^^^^^^^^^^^^^^^^^^^^^^^^^
92
This may be done at the time the user is created, for example::
94
$ createuser --superuser <user_name>
96
Or you may alter the user's role from the SQL shell (assuming this
97
is done from an existing superuser account)::
99
postgres# ALTER ROLE <user_name> SUPERUSER;
102
Create Local PostgreSQL Database
103
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105
1. Initialize database: ``initdb -D /path/to/user/db``
107
2. If there's already a Postgres instance on the machine, it will need
108
to use a different TCP port than 5432. Edit ``postgresql.conf`` (in
109
``/path/to/user/db``) to change the database port (e.g. ``port = 5433``).
111
3. Start this database ``pg_ctl -D /path/to/user/db start``
115
On Windows platforms the pgAdmin III utility may also be used as
116
a simple way to add superuser privileges to your database user.
118
By default, the PostGIS installer on Windows includes a template
119
spatial database entitled ``template_postgis``.
121
.. _testing-spatialite:
126
.. versionadded:: 1.1
128
You will need to download the `initialization SQL`__ script for SpatiaLite::
130
$ wget http://www.gaia-gis.it/spatialite/init_spatialite-2.3.zip
131
$ unzip init_spatialite-2.3.zip
133
If ``init_spatialite-2.3.sql`` is in the same path as your project's ``manage.py``,
134
then all you have to do is::
136
$ python manage.py test
141
.. setting:: SPATIALITE_SQL
145
.. versionadded:: 1.1
147
By default, the GeoDjango test runner looks for the SpatiaLite SQL in the
148
same directory where it was invoked (by default the same directory where
149
``manage.py`` is located). If you want to use a different location, then
150
you may add the following to your settings::
152
SPATIALITE_SQL='/path/to/init_spatialite-2.3.sql'
154
__ http://www.gaia-gis.it/spatialite/init_spatialite-2.3.zip
158
Testing GeoDjango Applications in 1.1
159
=====================================
161
In Django 1.1, to accommodate the extra steps required to scaffalod a
162
spatial database automatically, a test runner customized for GeoDjango
163
must be used. To use this runner, configure :setting:`TEST_RUNNER` as follows::
165
TEST_RUNNER='django.contrib.gis.tests.run_tests'
169
In order to create a spatial database, the :setting:`DATABASE_USER` setting
170
(or :setting:`TEST_DATABASE_USER`, if optionally defined on Oracle) requires
171
elevated privileges. When using PostGIS or MySQL, the database user
172
must have at least the ability to create databases. When testing on Oracle,
173
the user should be a superuser.
178
To run GeoDjango's own internal test suite, configure the
179
:setting:`TEST_RUNNER` setting as follows::
181
TEST_RUNNER='django.contrib.gis.tests.run_gis_tests'