-
Notifications
You must be signed in to change notification settings - Fork 36
refactor tests suite in order to run it locally outside docker #102
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
Changes from 2 commits
3767b1e
0012a49
a51994c
775b970
410421f
292c279
e8aa9a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,38 +5,18 @@ on: | |
pull_request: | ||
branches: [main] | ||
|
||
env: | ||
LATEST_PY_VERSION: '3.11' | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.8", "3.9", "3.10", "3.11"] | ||
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | ||
timeout-minutes: 20 | ||
|
||
services: | ||
db_service: | ||
image: ghcr.io/stac-utils/pgstac:v0.7.10 | ||
env: | ||
POSTGRES_USER: username | ||
POSTGRES_PASSWORD: password | ||
POSTGRES_DB: postgis | ||
POSTGRES_HOST: localhost | ||
POSTGRES_PORT: 5432 | ||
PGUSER: username | ||
PGPASSWORD: password | ||
PGDATABASE: postgis | ||
ALLOW_IP_RANGE: 0.0.0.0/0 | ||
# Set health checks to wait until postgres has started | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 10s | ||
--health-retries 10 | ||
--log-driver none | ||
ports: | ||
# Maps tcp port 5432 on service container to the host | ||
- 5432:5432 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't need this external service when using postgres pytest fixture |
||
|
||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v4 | ||
|
@@ -50,25 +30,26 @@ jobs: | |
cache-dependency-path: setup.py | ||
|
||
- name: Lint code | ||
if: ${{ matrix.python-version == 3.8 }} | ||
if: ${{ matrix.python-version == env.LATEST_PY_VERSION }} | ||
run: | | ||
python -m pip install pre-commit | ||
pre-commit run --all-files | ||
|
||
- name: Install | ||
- name: install lib postgres | ||
run: | | ||
sudo apt update | ||
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O- | sudo apt-key add - | ||
echo "deb [arch=amd64] http://apt.postgresql.org/pub/repos/apt/ focal-pgdg main" | sudo tee /etc/apt/sources.list.d/postgresql.list | ||
sudo apt update | ||
sudo apt-get install --yes libpq-dev postgis postgresql-14-postgis-3 | ||
|
||
- name: Install dependencies | ||
run: | | ||
pip install .[dev,server] | ||
python -m pip install --upgrade pip | ||
python -m pip install .[dev,server] | ||
|
||
- name: Run test suite | ||
run: make test | ||
env: | ||
ENVIRONMENT: testing | ||
POSTGRES_USER: username | ||
POSTGRES_PASS: password | ||
POSTGRES_DBNAME: postgis | ||
POSTGRES_HOST_READER: localhost | ||
POSTGRES_HOST_WRITER: localhost | ||
POSTGRES_PORT: 5432 | ||
run: python -m pytest --cov stac_fastapi.pgstac --cov-report xml --cov-report term-missing | ||
|
||
validate: | ||
runs-on: ubuntu-latest | ||
|
@@ -90,17 +71,23 @@ jobs: | |
--log-driver none | ||
ports: | ||
- 5432:5432 | ||
|
||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
python-version: ${{ env.LATEST_PY_VERSION }} | ||
cache: pip | ||
cache-dependency-path: setup.py | ||
|
||
- name: Install stac-fastapi and stac-api-validator | ||
run: pip install .[server] stac-api-validator==0.4.1 | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install .[server] stac-api-validator==0.4.1 | ||
|
||
- name: Load data and validate | ||
run: python -m stac_fastapi.pgstac.app & ./scripts/wait-for-it.sh localhost:8080 && python ./scripts/ingest_joplin.py http://localhost:8080 && ./scripts/validate http://localhost:8080 | ||
env: | ||
|
@@ -120,15 +107,21 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
python-version: ${{ env.LATEST_PY_VERSION }} | ||
cache: pip | ||
cache-dependency-path: setup.py | ||
|
||
- name: Install with documentation dependencies | ||
run: pip install .[docs,dev,server] | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install .[docs,dev,server] | ||
|
||
- name: Generate API docs | ||
run: make docs | ||
|
||
- name: Build documentation | ||
run: mkdocs build --strict |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,18 @@ repos: | |
rev: 5.12.0 | ||
hooks: | ||
- id: isort | ||
language_version: python3.8 | ||
language_version: python | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this change enables to run pre-commit on other python version |
||
- repo: https://github.com/psf/black | ||
rev: 22.12.0 | ||
hooks: | ||
- id: black | ||
args: ["--safe"] | ||
language_version: python3.8 | ||
language_version: python | ||
- repo: https://github.com/pycqa/flake8 | ||
rev: 6.0.0 | ||
hooks: | ||
- id: flake8 | ||
language_version: python3.8 | ||
language_version: python | ||
args: [ | ||
# E501 let black handle all line length decisions | ||
# W503 black conflicts with "line break before operator" rule | ||
|
@@ -26,7 +26,7 @@ repos: | |
rev: v2.1.1 | ||
hooks: | ||
- id: pydocstyle | ||
language_version: python3.8 | ||
language_version: python | ||
exclude: ".*(test|scripts).*" | ||
args: | ||
[ | ||
|
@@ -46,7 +46,7 @@ repos: | |
rev: 6.3.0 | ||
hooks: | ||
- id: pydocstyle | ||
language_version: python3.8 | ||
language_version: python | ||
exclude: ".*(test|scripts).*" | ||
#args: [ | ||
# Don't require docstrings for tests | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
FROM python:3.8-slim as base | ||
ARG PYTHON_VERSION=3.11 | ||
|
||
FROM python:${PYTHON_VERSION}-slim as base | ||
|
||
# Any python libraries that require system libraries to be installed will likely | ||
# need the following packages in order to build | ||
|
@@ -16,6 +18,6 @@ WORKDIR /app | |
|
||
COPY . /app | ||
|
||
RUN pip install -e .[dev,server] | ||
RUN python -m pip install -e .[server] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This image is now used only for the |
||
|
||
CMD ["uvicorn", "stac_fastapi.pgstac.app:app", "--host", "0.0.0.0", "--port", "8080"] | ||
CMD ["uvicorn", "stac_fastapi.pgstac.app:app", "--host", "0.0.0.0", "--port", "8080"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
ARG PYTHON_VERSION=3.11 | ||
|
||
FROM python:${PYTHON_VERSION}-slim as base | ||
|
||
# Any python libraries that require system libraries to be installed will likely | ||
# need the following packages in order to build | ||
RUN apt-get update && \ | ||
apt-get -y upgrade && \ | ||
apt-get install -y build-essential git libpq-dev postgresql-15-postgis-3 && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
RUN useradd -ms /bin/bash newuser | ||
USER newuser | ||
|
||
WORKDIR /app | ||
COPY . /app | ||
|
||
RUN python -m pip install -e .[dev,server] --user |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -636,7 +636,7 @@ async def search(query: Dict[str, Any]) -> List[Item]: | |
|
||
|
||
@pytest.mark.asyncio | ||
async def test_wrapped_function(load_test_data) -> None: | ||
async def test_wrapped_function(load_test_data, database) -> None: | ||
# Ensure wrappers, e.g. Planetary Computer's rate limiting, work. | ||
# https://github.com/gadomski/planetary-computer-apis/blob/2719ccf6ead3e06de0784c39a2918d4d1811368b/pccommon/pccommon/redis.py#L205-L238 | ||
|
||
|
@@ -672,7 +672,16 @@ async def get_collection( | |
collection_id, request=request, **kwargs | ||
) | ||
|
||
settings = Settings(testing=True) | ||
settings = Settings( | ||
postgres_user=database.user, | ||
postgres_pass=database.password, | ||
postgres_host_reader=database.host, | ||
postgres_host_writer=database.host, | ||
postgres_port=database.port, | ||
postgres_dbname=database.dbname, | ||
testing=True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) | ||
|
||
extensions = [ | ||
TransactionExtension(client=TransactionsClient(), settings=settings), | ||
FieldsExtension(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add python 3.12