Skip to content

Commit

Permalink
Integration tests (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
why-not-try-calmer authored Jul 26, 2023
1 parent b09e047 commit c9e8135
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 5 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- main

jobs:
test-quickstart:
tests:
runs-on: ubuntu-latest
env:
DOCKER_BUILDKIT: 1
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
cache-to: type=registry,ref=opengisch/signalo-django:latest,mode=max
tags: opengisch/signalo-django:latest

- name: Setup Compose & run all tests
- name: Setup Compose
run: |
# copy default conf
cp .env.example .env
Expand All @@ -52,13 +52,20 @@ jobs:
# deploy static files and migrate database
docker compose exec django python manage.py collectstatic --no-input
docker compose exec django python manage.py migrate --no-input
docker-compose exec -T django python manage.py populate_users
docker-compose exec -T django python manage.py populate_vl
docker-compose exec -T django python manage.py populate_signs_poles
# run tests
- name: Run unit tests
run: |
docker compose exec django python manage.py test signalo.value_lists
docker compose exec django python manage.py test signalo.core
docker compose exec django python manage.py test signalo.edge_cases
docker compose exec django python manage.py test signalo.roads
- name: Run integration tests
run: docker compose run integration_tests

- name: Failure logs
if: failure()
run: docker-compose logs
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:

# Remove unused imports/variables
- repo: https://github.com/myint/autoflake
rev: v2.0.2
rev: v2.2.0
hooks:
- id: autoflake
args:
Expand All @@ -28,7 +28,7 @@ repos:

# Black formatting
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
exclude: migrations/
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ services:
- ./docker/conformance-tests/test-run-props.xml:/build/run/test-run-props.xml
profiles:
- testing

integration_tests:
image: opengisch/qgis:latest
command: sh -c 'xvfb-run python3 -m unittest discover'
tty: true
volumes:
- ./docker/integration-tests:/integration-tests
working_dir: /integration-tests
profiles:
- testing
67 changes: 67 additions & 0 deletions docker/integration-tests/test_stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import requests
from qgis.core import QgsDataSourceUri, QgsFeature, QgsProject, QgsVectorLayer
from qgis.testing import start_app, unittest

start_app()

ROOT_URL = "http://django:8000/oapif/"
COLLECTIONS_URL = "http://django:8000/oapif/collections"
POLES_URL = "http://django:8000/oapif/collections/signalo_core.pole"


class TestStack(unittest.TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.project = QgsProject.instance()
cls.user = "admin"
cls.password = "123"

def test_endpoint_ok(self):
root_response = requests.get(ROOT_URL)
collections_response = requests.get(COLLECTIONS_URL)
poles_response = requests.get(POLES_URL)

self.assertTrue(root_response.status_code == 200)
self.assertTrue(collections_response.status_code == 200)
self.assertTrue(poles_response.status_code == 200)

def test_collection_exists(self):
res = requests.get(COLLECTIONS_URL).json()
self.assertTrue(
"signalo_core.pole"
in [collection["id"] for collection in res["collections"]]
)

def test_many_poles(self):
poles = requests.get(POLES_URL).json()
self.assertTrue(len(poles) > 1)

def test_load_layer(self):
uri = QgsDataSourceUri()
uri.setParam("service", "wfs")
uri.setParam("typename", "signalo_core.pole")
uri.setParam("url", ROOT_URL)
layer = QgsVectorLayer(uri.uri(), "pole", "OAPIF")
self.assertTrue(layer.isValid())

self.project.addMapLayer(layer)
self.assertTrue(len(self.project.mapLayers().values()) > 0)

def test_load_with_basic_auth(self):
uri = QgsDataSourceUri()
uri.setParam("service", "wfs")
uri.setParam("typename", "signalo_core.pole")
uri.setParam("url", ROOT_URL)
uri.setPassword(self.password)
uri.setUsername(self.user)

layer = QgsVectorLayer(uri.uri(), "pole", "OAPIF")
self.assertTrue(layer.isValid())
layer = self.project.addMapLayer(layer)
self.assertIsNotNone(layer)

f = None
for f in layer.getFeatures("name='1-1'"):
pass
self.assertIsInstance(f, QgsFeature)

0 comments on commit c9e8135

Please sign in to comment.