From 125fd6ed36f534aa6072c35496028484c51fa0e0 Mon Sep 17 00:00:00 2001 From: Amandine Date: Tue, 10 Oct 2023 09:40:07 +0200 Subject: [PATCH] Add pytests githubaction (#254) * Add tests workflow * Add fake test --- .github/workflows/pytest.yml | 120 ++++++++++++++++++ .gitmodules | 4 + .../gn_module_monitoring/tests/test_true.py | 6 + dependencies/GeoNature | 1 + 4 files changed, 131 insertions(+) create mode 100644 .github/workflows/pytest.yml create mode 100644 .gitmodules create mode 100644 backend/gn_module_monitoring/tests/test_true.py create mode 160000 dependencies/GeoNature diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 000000000..fb0c6beca --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,120 @@ +name: pytest + +on: + push: + branches: + - master + - hotfixes + - develop + - workshop + pull_request: + branches: + - master + - hotfixes + - develop + - workshop + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + include: + - name: "Debian 10" + python-version: "3.7" + postgres-version: 11 + postgis-version: 2.5 + - name: "Debian 11" + python-version: "3.9" + postgres-version: 13 + postgis-version: 3.2 + + name: ${{ matrix.name }} + + services: + postgres: + image: postgis/postgis:${{ matrix.postgres-version }}-${{ matrix.postgis-version }} + env: + POSTGRES_DB: geonature2db + POSTGRES_PASSWORD: geonatpasswd + POSTGRES_USER: geonatadmin + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + redis: + image: redis + ports: + - 6379:6379 + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Add postgis_raster database extension + if: ${{ matrix.postgis-version >= 3 }} + run: | + psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "postgis_raster";' + env: + PGPASSWORD: geonatpasswd + - name: Add database extensions + run: | + psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "hstore";' + psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "uuid-ossp";' + psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "pg_trgm";' + psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "unaccent";' + env: + PGPASSWORD: geonatpasswd + - uses: actions/checkout@v2 + with: + submodules: recursive + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install GDAL + run: | + sudo apt update + sudo apt install -y libgdal-dev + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install \ + -e ..[tests] \ + -r requirements-dev.txt + working-directory: ./dependencies/GeoNature/backend + - name: Install database + run: | + geonature db upgrade geonature@head -x local-srid=2154 + geonature db autoupgrade -x local-srid=2154 + geonature taxref import-v15 --skip-bdc-statuts + geonature db upgrade geonature-samples@head + geonature db upgrade nomenclatures_taxonomie_data@head + geonature db upgrade ref_geo_fr_departments@head + geonature db upgrade ref_geo_fr_municipalities@head + geonature db upgrade ref_geo_inpn_grids_10@head + env: + GEONATURE_CONFIG_FILE: dependencies/GeoNature/config/test_config.toml + - name: Install import module database + run: | + geonature upgrade-modules-db MONITORINGS + env: + GEONATURE_CONFIG_FILE: dependencies/GeoNature/config/test_config.toml + - name: Test with pytest + run: | + pytest -v --cov --cov-report xml + env: + GEONATURE_CONFIG_FILE: dependencies/GeoNature/config/test_config.toml + - name: Upload coverage to Codecov + if: ${{ matrix.name == 'Debian 11' }} + uses: codecov/codecov-action@v2 + with: + flags: pytest diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..39957d44f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "dependencies/GeoNature"] + path = dependencies/GeoNature + url = git@github.com:PnX-SI/GeoNature.git + branch = develop diff --git a/backend/gn_module_monitoring/tests/test_true.py b/backend/gn_module_monitoring/tests/test_true.py new file mode 100644 index 000000000..082867288 --- /dev/null +++ b/backend/gn_module_monitoring/tests/test_true.py @@ -0,0 +1,6 @@ +import pytest + + +class Tests: + def test_true_is_true(self): + assert True == True diff --git a/dependencies/GeoNature b/dependencies/GeoNature new file mode 160000 index 000000000..7ee68c555 --- /dev/null +++ b/dependencies/GeoNature @@ -0,0 +1 @@ +Subproject commit 7ee68c5555ecd4e3d1b252dd78254a492cd2d7eb