Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Docker tests #104

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Dockerfile-3.9
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
FROM python:3.9-buster
FROM python:3.9-slim-bullseye

LABEL description="Test executor"

ENV DEBIAN_FRONTEND noninteractive
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update --fix-missing \
&& apt-get install -y --no-install-recommends \
binutils \
libproj-dev \
gdal-bin \
libgdal-dev \
libsqlite3-mod-spatialite \
spatialite-bin \
build-essential \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir /app
Expand All @@ -19,13 +21,11 @@ COPY requirements-test.txt .
COPY requirements-dev.txt .
RUN pip install -r requirements-test.txt
RUN pip install -r requirements-dev.txt
RUN gdal_version=$(gdal-config --version) && \
pip install pygdal=="$gdal_version.*"

COPY pygeofilter pygeofilter
COPY tests tests
COPY README.md .
COPY setup.py .
RUN pip install -e .

RUN chmod +x tests/execute-tests.sh

CMD ["tests/execute-tests.sh"]
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ pip install -r requirements-dev.txt
pip install -r requirements-test.txt
```

GDAL must also be available in the local environment.

The functionality can be tested using `pytest`.

```bash
Expand All @@ -188,11 +190,10 @@ python -m pytest

### Docker

To execute tests in Docker:
To execute tests with Docker Compose:

```
docker build -t pygeofilter/test -f Dockerfile-3.9 .
docker run --rm pygeofilter/test
./execute-tests.sh
```

## Backends
Expand Down
24 changes: 24 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
services:
elasticsearch:
image: elasticsearch:8.2.2
ports:
- 9200:9200
- 9300:9300
environment:
discovery.type: single-node
xpack.security.enabled: false
xpack.security.http.ssl.enabled: false
ES_JAVA_OPTS: -Xms1g -Xmx1g
healthcheck:
test: ["CMD-SHELL", "curl -s http://localhost:9200/_cluster/health | grep -q '\"status\":\"green\"'"]
interval: 30s
timeout: 10s
retries: 3
tester:
build:
dockerfile: ./Dockerfile-3.9
environment:
PYGEOFILTER_ELASTIC_HOST: elasticsearch
depends_on:
elasticsearch:
condition: service_healthy
10 changes: 10 additions & 0 deletions execute-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

pushd $(dirname $0)

dco="docker compose -f docker-compose.test.yml"
$dco build
$dco run --rm tester pytest
exit_code=$?
$dco down
exit $exit_code
7 changes: 5 additions & 2 deletions tests/backends/elasticsearch/test_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from pygeofilter.backends.elasticsearch import to_filter
from pygeofilter.parsers.ecql import parse
from pygeofilter.util import parse_datetime

from os import environ

class Wildcard(Field):
name = "wildcard"
Expand Down Expand Up @@ -54,7 +54,10 @@ class Index:
@pytest.fixture(autouse=True, scope="session")
def connection():
connections.create_connection(
hosts=["http://localhost:9200"],
hosts=["http://{}:{}".format(
environ.get("PYGEOFILTER_ELASTIC_HOST", "localhost"),
environ.get("PYGEOFILTER_ELASTIC_PORT", "9200"),
)],
)


Expand Down
Loading