-
Notifications
You must be signed in to change notification settings - Fork 3
189 lines (161 loc) · 6.02 KB
/
tests.yml
File metadata and controls
189 lines (161 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Test Suite
on:
pull_request:
branches: ['production', 'staging', 'transfer']
permissions:
contents: read
jobs:
unit-tests:
runs-on: ubuntu-latest
env:
MODE: development
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
PYGEOAPI_POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
PYGEOAPI_POSTGRES_PASSWORD: postgres
POSTGRES_DB: ocotilloapi_test
PYGEOAPI_POSTGRES_HOST: localhost
PYGEOAPI_POSTGRES_PORT: 5432
PYGEOAPI_POSTGRES_DB: ocotilloapi_test
DB_DRIVER: postgres
BASE_URL: http://localhost:8000
SESSION_SECRET_KEY: supersecretkeyforunittests
AUTHENTIK_DISABLE_AUTHENTICATION: 1
services:
postgis:
image: postgis/postgis:17-3.5
# don't test against latest. be explicit in version being tested to avoid breaking changes
# image: postgis/postgis:latest
env:
POSTGRES_PASSWORD: postgres
POSTGRES_PORT: 5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Check out source repository
uses: actions/checkout@v6.0.2
- name: Wait for database readiness
run: |
for i in {1..60}; do
if PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d postgres -c "SELECT 1" >/dev/null 2>&1; then
exit 0
fi
sleep 2
done
echo "Database did not become ready in time"
exit 1
- name: Install uv
uses: astral-sh/setup-uv@v8.0.0
with:
enable-cache: true
cache-dependency-glob: uv.lock
- name: Set up Python
id: setup-python
uses: actions/setup-python@v6.2.0
with:
python-version-file: "pyproject.toml"
- name: Cache project virtualenv
id: cache-venv
uses: actions/cache@v5
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('uv.lock') }}
- name: Install the project
run: uv sync --locked --all-extras --dev
- name: Show Alembic heads
run: uv run alembic heads
- name: Create test database and extensions
run: |
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -tc "SELECT 1 FROM pg_database WHERE datname = 'ocotilloapi_test'" | grep -q 1 || \
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -c "CREATE DATABASE ocotilloapi_test"
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d ocotilloapi_test -c "CREATE EXTENSION IF NOT EXISTS postgis"
- name: Run tests
run: uv run pytest -vv --durations=20 --cov --cov-report=xml --junitxml=junit.xml --ignore=tests/transfers
- name: Upload results to Codecov
uses: codecov/codecov-action@v6
with:
report_type: test_results
token: ${{ secrets.CODECOV_TOKEN }}
bdd-tests:
runs-on: ubuntu-latest
env:
MODE: development
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
PYGEOAPI_POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
PYGEOAPI_POSTGRES_PASSWORD: postgres
POSTGRES_DB: ocotilloapi_test
PYGEOAPI_POSTGRES_HOST: localhost
PYGEOAPI_POSTGRES_PORT: 5432
PYGEOAPI_POSTGRES_DB: ocotilloapi_test
DB_DRIVER: postgres
BASE_URL: http://localhost:8000
SESSION_SECRET_KEY: supersecretkeyforunittests
AUTHENTIK_DISABLE_AUTHENTICATION: 1
DROP_AND_REBUILD_DB: 1
services:
postgis:
image: postgis/postgis:17-3.5
# don't test against latest. be explicit in version being tested to avoid breaking changes
# image: postgis/postgis:latest
env:
POSTGRES_PASSWORD: postgres
POSTGRES_PORT: 5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Check out source repository
uses: actions/checkout@v6.0.2
- name: Wait for database readiness
run: |
for i in {1..60}; do
if PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d postgres -c "SELECT 1" >/dev/null 2>&1; then
exit 0
fi
sleep 2
done
echo "Database did not become ready in time"
exit 1
- name: Install uv
uses: astral-sh/setup-uv@v8.0.0
with:
enable-cache: true
cache-dependency-glob: uv.lock
- name: Set up Python
id: setup-python
uses: actions/setup-python@v6.2.0
with:
python-version-file: "pyproject.toml"
- name: Cache project virtualenv
id: cache-venv
uses: actions/cache@v5
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('uv.lock') }}
- name: Install the project
run: uv sync --locked --all-extras --dev
- name: Show Alembic heads
run: uv run alembic heads
- name: Create test database and extensions
run: |
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -tc "SELECT 1 FROM pg_database WHERE datname = 'ocotilloapi_test'" | grep -q 1 || \
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -c "CREATE DATABASE ocotilloapi_test"
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d ocotilloapi_test -c "CREATE EXTENSION IF NOT EXISTS postgis"
- name: Run BDD tests
run: uv run behave tests/features --tags="@backend and @production and not @skip" --no-capture