Skip to content

Commit c0578e4

Browse files
committed
Add Docker Postgis Test Bypass and Test Docs
Set CUBEDASH_BYPASS_DOCKER=True as an environment variable along with DB access environment variables to allow running the integration tests outside of docker, and without spawning PostGIS containers. Also document this in the README
1 parent 6295703 commit c0578e4

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ refer to [deployment instructions](https://datacube-explorer.readthedocs.io/en/l
151151

152152
### How do I modify the CSS/Javascript?
153153

154-
The CSS is compiled from [Sass](https://sass-lang.com/), and the Javascript is compiled from
154+
The CSS is compiled from [Sass](https://sass-lang.com/), and the JavaScript is compiled from
155155
[Typescript](https://www.typescriptlang.org/).
156156

157157
Install [npm](https://www.npmjs.com/get-npm), and then install them both:
@@ -179,6 +179,35 @@ Install the test dependencies: `pip install -e .[test]`
179179

180180
The run the tests with: `pytest integration_tests`
181181

182+
**Docker Compose alternative:**
183+
See below for running the tests using `docker compose`.
184+
185+
**Without Docker alternative:**
186+
187+
Assuming you have a PostgreSQL server running locally, that you're setup to log into.
188+
189+
```
190+
# Create a test database to use
191+
$ createdb odc-explorer-testing
192+
193+
# Add the PostGIS extensions to it
194+
$ psql odc-explorer-testing
195+
odc-explorer-testing=# create extension if not exists postgis;
196+
CREATE EXTENSION
197+
198+
# Export environment variables so that the tests know which Database to use
199+
$ export ODC_DEFAULT_INDEX_DRIVER=postgres
200+
$ export ODC_POSTGIS_INDEX_DRIVER=postgis
201+
$ export ODC_DEFAULT_DB_URL=postgresql://localhost/odc-explorer-testing
202+
$ export ODC_POSTGIS_DB_URL=postgresql://localhost/odc-explorer-testing
203+
$ export CUBEDASH_BYPASS_DOCKER=True
204+
205+
# Finally, run the tests
206+
$ uv run pytest integration_tests/
207+
208+
```
209+
210+
182211
### How do I add test data for the automated tests?
183212

184213
Most of the automated tests for Datacube Explorer require sample data to run. This comprises

cubedash/testutils/database.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ def postgresql_server():
3838
# If we're running inside docker already, don't attempt to start a container!
3939
# Hopefully we're using the `with-test-db` script and can use *that* database.
4040
# I think this may be copypasta from odc-tools
41-
if Path("/.dockerenv").exists() and (
42-
"ODC_DEFAULT_DB_URL" in os.environ or "ODC_POSTGIS_DB_URL" in os.environ
41+
if (
42+
"CUBEDASH_BYPASS_DOCKER" in os.environ
43+
or Path("/.dockerenv").exists()
44+
and ("ODC_DEFAULT_DB_URL" in os.environ or "ODC_POSTGIS_DB_URL" in os.environ)
4345
):
4446
yield GET_DB_FROM_ENV
4547
else:
@@ -136,7 +138,6 @@ def odc_test_db(cfg_env):
136138
the default ODC DB by setting environment variables.
137139
:return: Datacube instance
138140
"""
139-
140141
index = index_connect(cfg_env, validate_connection=False)
141142
index.init_db()
142143

0 commit comments

Comments
 (0)