{"title":"Testing GeoDjango apps","version":"2.1","locale":"el","docname":"ref/contrib/gis/testing","url":"/el/2.1/ref/contrib/gis/testing/","canonical":"https://djangodocs.dev/el/2.1/ref/contrib/gis/testing/","summary":"Included in this documentation are some additional notes and settings for PostGIS users. PostGIS Link to this heading # Settings Link to this heading # Σημείωση The…","html":"<h1>Testing GeoDjango apps<a class=\"heading-anchor\" href=\"#testing-geodjango-apps\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Included in this documentation are some additional notes and settings\nfor <a class=\"reference internal\" href=\"#testing-postgis\"><span class=\"std std-ref\">PostGIS</span></a> users.</p>\n<section id=\"postgis\">\n<span id=\"testing-postgis\"></span><h2>PostGIS<a class=\"heading-anchor\" href=\"#postgis\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"settings\">\n<h3>Settings<a class=\"heading-anchor\" href=\"#settings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Σημείωση</p>\n<p>The settings below have sensible defaults, and shouldn’t require manual setting.</p>\n</aside>\n<section id=\"postgis-version\">\n<span id=\"std-setting-POSTGIS_VERSION\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">POSTGIS_VERSION</span></code><a class=\"heading-anchor\" href=\"#postgis-version\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>When GeoDjango’s spatial backend initializes on PostGIS, it has to perform\nan SQL query to determine the version in order to figure out what\nfeatures are available. Advanced users wishing to prevent this additional\nquery may set the version manually using a 3-tuple of integers specifying\nthe major, minor, and micro version numbers for PostGIS. For example,\nto configure for PostGIS X.Y.Z you would use:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">POSTGIS_VERSION</span> <span class=\"o\">=</span> <span class=\"p\">(</span><span class=\"n\">X</span><span class=\"p\">,</span> <span class=\"n\">Y</span><span class=\"p\">,</span> <span class=\"n\">Z</span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"obtaining-sufficient-privileges\">\n<h3>Obtaining sufficient privileges<a class=\"heading-anchor\" href=\"#obtaining-sufficient-privileges\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Depending on your configuration, this section describes several methods to\nconfigure a database user with sufficient privileges to run tests for\nGeoDjango applications on PostgreSQL. If your\n<a class=\"reference internal\" href=\"/el/2.1/ref/contrib/gis/install/postgis/#spatialdb-template\"><span class=\"std std-ref\">spatial database template</span></a>\nwas created like in the instructions, then your testing database user\nonly needs to have the ability to create databases. In other configurations,\nyou may be required to use a database superuser.</p>\n<section id=\"create-database-user\">\n<h4>Create database user<a class=\"heading-anchor\" href=\"#create-database-user\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>To make a database user with the ability to create databases, use the\nfollowing command:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>$ createuser --createdb -R -S &lt;user_name&gt;\n</code></pre></div>\n<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">-R</span> <span class=\"pre\">-S</span></code> flags indicate that we do not want the user to have the ability\nto create additional users (roles) or to be a superuser, respectively.</p>\n<p>Alternatively, you may alter an existing user’s role from the SQL shell\n(assuming this is done from an existing superuser account):</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">postgres</span><span class=\"c1\"># ALTER ROLE &lt;user_name&gt; CREATEDB NOSUPERUSER NOCREATEROLE;</span>\n</code></pre></div>\n</section>\n<section id=\"create-database-superuser\">\n<h4>Create database superuser<a class=\"heading-anchor\" href=\"#create-database-superuser\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>This may be done at the time the user is created, for example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>$ createuser --superuser &lt;user_name&gt;\n</code></pre></div>\n<p>Or you may alter the user’s role from the SQL shell (assuming this\nis done from an existing superuser account):</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">postgres</span><span class=\"c1\"># ALTER ROLE &lt;user_name&gt; SUPERUSER;</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"windows\">\n<h3>Windows<a class=\"heading-anchor\" href=\"#windows\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>On Windows platforms the pgAdmin III utility may also be used as\na simple way to add superuser privileges to your database user.</p>\n<p>By default, the PostGIS installer on Windows includes a template\nspatial database entitled <code class=\"docutils literal notranslate\"><span class=\"pre\">template_postgis</span></code>.</p>\n</section>\n</section>\n<section id=\"geodjango-tests\">\n<span id=\"id1\"></span><h2>GeoDjango tests<a class=\"heading-anchor\" href=\"#geodjango-tests\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>To have the GeoDjango tests executed when <a class=\"reference internal\" href=\"/el/2.1/internals/contributing/writing-code/unit-tests/#running-unit-tests\"><span class=\"std std-ref\">running the Django test suite</span></a> with <code class=\"docutils literal notranslate\"><span class=\"pre\">runtests.py</span></code> all of the databases in the settings\nfile must be using one of the <a class=\"reference internal\" href=\"/el/2.1/ref/contrib/gis/db-api/#spatial-backends\"><span class=\"std std-ref\">spatial database backends</span></a>.</p>\n<section id=\"example\">\n<h3>Example<a class=\"heading-anchor\" href=\"#example\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The following is an example bare-bones settings file with spatial backends\nthat can be used to run the entire Django test suite, including those\nin <a class=\"reference internal\" href=\"/el/2.1/ref/contrib/gis/#module-django.contrib.gis\" title=\"django.contrib.gis: Geographic Information System (GIS) extensions for Django\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.gis</span></code></a>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s1\">&#39;default&#39;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s1\">&#39;ENGINE&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;django.contrib.gis.db.backends.postgis&#39;</span><span class=\"p\">,</span>\n        <span class=\"s1\">&#39;NAME&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;geodjango&#39;</span><span class=\"p\">,</span>\n        <span class=\"s1\">&#39;USER&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;geodjango&#39;</span><span class=\"p\">,</span>\n    <span class=\"p\">},</span>\n    <span class=\"s1\">&#39;other&#39;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s1\">&#39;ENGINE&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;django.contrib.gis.db.backends.postgis&#39;</span><span class=\"p\">,</span>\n        <span class=\"s1\">&#39;NAME&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;other&#39;</span><span class=\"p\">,</span>\n        <span class=\"s1\">&#39;USER&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;geodjango&#39;</span><span class=\"p\">,</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n\n<span class=\"n\">SECRET_KEY</span> <span class=\"o\">=</span> <span class=\"s1\">&#39;django_tests_secret_key&#39;</span>\n</code></pre></div>\n<p>Assuming the settings above were in a <code class=\"docutils literal notranslate\"><span class=\"pre\">postgis.py</span></code> file in the same\ndirectory as <code class=\"docutils literal notranslate\"><span class=\"pre\">runtests.py</span></code>, then all Django and GeoDjango tests would\nbe performed when executing the command:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>$ ./runtests.py --settings=postgis\n</code></pre></div>\n<p>To run only the GeoDjango test suite, specify <code class=\"docutils literal notranslate\"><span class=\"pre\">gis_tests</span></code>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>$ ./runtests.py --settings=postgis gis_tests\n</code></pre></div>\n</section>\n</section>","rootId":"testing-geodjango-apps","toc":[{"title":"PostGIS","anchor":"postgis","children":[{"title":"Settings","anchor":"settings","children":[{"title":"POSTGIS_VERSION","anchor":"postgis-version","children":[]}]},{"title":"Obtaining sufficient privileges","anchor":"obtaining-sufficient-privileges","children":[{"title":"Create database user","anchor":"create-database-user","children":[]},{"title":"Create database superuser","anchor":"create-database-superuser","children":[]}]},{"title":"Windows","anchor":"windows","children":[]}]},{"title":"GeoDjango tests","anchor":"geodjango-tests","children":[{"title":"Example","anchor":"example","children":[]}]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/el/2.1/ref/"},{"docname":"ref/contrib/index","title":"contrib packages","url":"/el/2.1/ref/contrib/"},{"docname":"ref/contrib/gis/index","title":"GeoDjango","url":"/el/2.1/ref/contrib/gis/"}],"prev":{"docname":"ref/contrib/gis/sitemaps","title":"Geographic Sitemaps","url":"/el/2.1/ref/contrib/gis/sitemaps/"},"next":{"docname":"ref/contrib/gis/deployment","title":"Deploying GeoDjango","url":"/el/2.1/ref/contrib/gis/deployment/"},"formats":{"html":"/el/2.1/ref/contrib/gis/testing/","markdown":"/el/2.1/ref/contrib/gis/testing.md","json":"/el/2.1/ref/contrib/gis/testing.json"},"source":"https://github.com/django/django/blob/stable/2.1.x/docs/ref/contrib/gis/testing.txt","official":"https://docs.djangoproject.com/el/2.1/ref/contrib/gis/testing/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}