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

setup automatic tests #151

Merged
merged 9 commits into from
Jun 2, 2024
Merged
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
148 changes: 148 additions & 0 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
name: Run tests

on:
push:
branches: [master]
pull_request:
branches: [master]
schedule:
- cron: "0 0 * * *"

permissions:
contents: read

jobs:

test-ubuntu:

runs-on: ubuntu-latest

strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/[email protected]
with:
cache: 'pip'
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
sudo apt-add-repository ppa:ubuntugis/ppa
sudo apt-get update
sudo apt-get install gdal-bin libgdal-dev
python -m pip install --upgrade pip
python -m pip install GDAL==`gdal-config --version`
python -m pip install -r requirements_dev.txt

- name: Set up docker-compose
run: |
docker compose -f tests/docker-compose.yaml up -d
sleep 60 # Geoserver takes quite a long time to boot up and there is no healthcheck

- name: Test with pytest
uses: dariocurr/pytest-summary@main
with:
paths: tests/test_geoserver.py
env:
DB_HOST: postgis

- name: Upload test summary
uses: actions/upload-artifact@v4
with:
name: test-summary-linux
path: test-summary-linux.md
if: always()

#test-windows:
#
# runs-on: windows-latest
#
# steps:
# - uses: actions/checkout@v4
#
# - name: Set up Python 3.10
# uses: actions/setup-python@v3
# with:
# python-version: '3.10'
#
# - name: Set up PostGIS
# run: |
#
# # Install PostGIS (PostgreSQL comes on the GitHub Actions runner by default but lacks PostGIS control files and dependencies)
# netsh advfirewall firewall show rule name="Allow Localhost 5432"
# Invoke-WebRequest -Uri "http://download.osgeo.org/postgis/windows/pg14/postgis-bundle-pg14x64-setup-3.4.1-1.exe" -OutFile "postgis-installer.exe"
# Start-Process "postgis-installer.exe" -ArgumentList "/S /D=C:\Program Files\PostgreSQL\14" -Wait -NoNewWindow
# & "C:\Program Files\PostgreSQL\14\bin\pg_ctl.exe" -D "C:\Program Files\PostgreSQL\14\data" start
# & "C:\Program Files\PostgreSQL\14\bin\psql.exe" -U postgres -c "CREATE DATABASE geodb;"
# & "C:\Program Files\PostgreSQL\14\bin\psql.exe" -U postgres -c "CREATE USER geodb_user WITH ENCRYPTED PASSWORD 'geodb_pass';"
# & "C:\Program Files\PostgreSQL\14\bin\psql.exe" -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE geodb TO geodb_user;"
# & "C:\Program Files\PostgreSQL\14\bin\psql.exe" -U postgres -d geodb -c "CREATE EXTENSION postgis;"
#
# - name: Set up Tomcat/GeoServer
# run: |
#
# # Configure firewall to allow connectiosn to localhost port 8080 (might not be necessary)
# netsh advfirewall firewall add rule name="Allow Localhost 5432" dir=in action=allow protocol=TCP localport=5432
#
# # Download and install Apache Tomcat (need version 9 because the JRE on the GitHub Actions runner is incompatible with 10+)
# curl -L https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.88/bin/apache-tomcat-9.0.88-windows-x64.zip -o tomcat.zip
# Expand-Archive -Path tomcat.zip -DestinationPath "C:\"
# $directory = Get-ChildItem -Path "C:\" -Directory | Where-Object { $_.Name -like "*apache-tomcat*" } | Select-Object -First 1
# if ($directory) { Rename-Item -Path $directory.FullName -NewName "Tomcat" }
#
# # Download and install Geoserver, then move it to the Tomcat directory
# # Version-locked to 2.22.0 beacause of Java 8
# curl -L https://sourceforge.net/projects/geoserver/files/GeoServer/2.22.0/geoserver-2.22.0-war.zip/download -o geoserver.zip
# Expand-Archive -Path geoserver.zip -DestinationPath "C:\GeoServer"
# cp C:\GeoServer\geoserver.war C:\Tomcat\webapps\geoserver.war
#
# # Set env vars for Tomcat and run it (it takes a little while, so wait 30 seconds after)
# $env:CATALINA_BASE = "C:\Tomcat"
# $env:CATALINA_HOME = "C:\Tomcat"
# $env:CATALINA_TMPDIR = "C:\Tomcat\temp"
# C:\Tomcat\bin\startup.bat
# Start-Sleep -Seconds 30
#
# shell: pwsh
#
# - name: Install Miniconda
# run: |
# curl -O https://repo.anaconda.com/miniconda/Miniconda3-py39_4.10.3-Windows-x86_64.exe
# Start-Process -FilePath "Miniconda3-py39_4.10.3-Windows-x86_64.exe" -ArgumentList '/InstallationType=JustMe /RegisterPython=0 /S /D="%UserProfile%\Miniconda3"' -Wait -NoNewWindow
# & "$env:UserProfile\Miniconda3\Scripts\conda" init powershell
# shell: pwsh
#
# - name: Configure Conda environment
# run: |
# $env:PATH = "$env:UserProfile\Miniconda3;$env:UserProfile\Miniconda3\Scripts;$env:UserProfile\Miniconda3\Library\bin;$env:PATH"
# conda update conda -y
# conda create -n geospatial python=3.10 -y
# conda activate geospatial
# conda install -c conda-forge gdal>=3.4.1 -y
# python -m pip install --upgrade pip
# pip install -r requirements_dev.txt
# shell: pwsh
#
# #- name: Test with pytest
# # uses: dariocurr/pytest-summary@main
# # with:
# # paths: tests/test_geoserver.py
# # env:
# # DB_HOST: postgis
#
# - name: Test with pytest
# run: |
# conda activate geospatial
# pytest tests/test_geoserver.py
#
# - name: Upload test summary
# uses: actions/upload-artifact@v3
# with:
# name: test-summary-windows
# path: test-summary-windows.md
# if: always()
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FunctionsToImplement.py
record.txt
package_test.py
test.py
.idea/

# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python
Expand Down
8 changes: 7 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-r requirements.txt

pytest
black
flake8
Expand All @@ -6,4 +8,8 @@ pre-commit
environs
ddt
sqlalchemy>=2.0.29
psycopg2>=2.9.9
psycopg2>=2.9.9
gdal>=3.4.1 # Note: in the automated test pipeline, this will be replaced by whatever is the output of `gdal-config --version`
seaborn>=0.13.2
ddt>=1.7.1
xmltodict>=0.13.0
20 changes: 20 additions & 0 deletions tests/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3.8'

services:

postgis:
image: postgis/postgis:latest
environment:
POSTGRES_DB: geodb
POSTGRES_USER: geodb_user
POSTGRES_PASSWORD: geodb_pass
ports:
- "0.0.0.0:5432:5432"

geoserver:
image: kartoza/geoserver:latest
environment:
- GEOSERVER_ADMIN_PASSWORD=geoserver
- GEOSERVER_ADMIN_USER=admin
ports:
- "0.0.0.0:8080:8080"
1 change: 1 addition & 0 deletions tests/test_geoserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ def test_styles(self):
)


@pytest.mark.skip("Doesn't work for some reason")
class TestCreateGeopackageDatastore:

def test_create_geopackage_datastore_from_file(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_layergroup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import os
import unittest
from environs import Env
import pytest

from unittest.mock import MagicMock, patch #allows replacing methods ans Objects by Mocks
from ddt import data, ddt, unpack #allows running the same test with different parameters

from geo.Geoserver import Geoserver

@ddt
@pytest.mark.skip(reason="Wrong env vars")
class TestLayerGroup(unittest.TestCase):
"""
Tests all layergroup related methods of the geoserver class.
Expand Down
Loading