Skip to content

Commit

Permalink
Enable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Dec 13, 2023
1 parent f73bad9 commit 8a9d264
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,42 @@ on: [push]

jobs:

test:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@master

- name: Checkout qwc-docker
uses: actions/checkout@master
with:
repository: qwc-services/qwc-docker
path: qwc-docker

- name: Start demo database
run: |
cd qwc-docker
cp pg_service.conf ~/.pg_service.conf
sed -i 's|host=qwc-postgis|host=localhost|g' ~/.pg_service.conf
sed -i 's|port=5432|port=5439|g' ~/.pg_service.conf
sed -Ei "s|^(\s*POSTGRES_PASSWORD:).*$|\1 'waej7WuoOoth0wor'|" docker-compose-example.yml
sed -i 's|qwc-ogc-service:9090|localhost:8001|' volumes/config/default/printConfig.json
sed -i -e 's|# ports:|ports:|g' -e 's|# - "127.0.0.1| - "127.0.0.1|g' docker-compose-example.yml
docker-compose -f docker-compose-example.yml up -d qwc-postgis qwc-config-db-migrate qwc-qgis-server
- name: Setting up Python
uses: actions/setup-python@v2
with:
python-version: '3.12'

- name: Run unittests
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
PYTHONPATH=$PWD/src CONFIG_PATH=$PWD/qwc-docker/volumes/config/ python3 test.py
build:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
steps:
Expand Down
34 changes: 10 additions & 24 deletions tests/api_tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import unittest
from urllib.parse import urlparse, parse_qs, unquote

from flask import Response, json
from flask import Response
from flask.testing import FlaskClient
from flask_jwt_extended import JWTManager, create_access_token
from flask_jwt_extended import JWTManager

import server
JWTManager(server.app)


class ApiTestCase(unittest.TestCase):
Expand All @@ -15,30 +15,24 @@ class ApiTestCase(unittest.TestCase):
def setUp(self):
server.app.testing = True
self.app = FlaskClient(server.app, Response)
JWTManager(server.app)

def tearDown(self):
pass

def jwtHeader(self):
with server.app.test_request_context():
access_token = create_access_token('test')
return {'Authorization': 'Bearer {}'.format(access_token)}

# submit query
def test_print(self):
params = {
'DPI': 300,
'SRS': 'EPSG:2056',
'TEMPLATE': 'A4_portrait',
'TEMPLATE': 'A4 Landscape',
'FORMAT': 'PDF',
'TRANSPARENT': 1,
'LAYERS': 'test_point,test_poly,wms:http://wms.geo.admim.ch#test',
'TRANSPARENT': 'true',
'LAYERS': 'countries,states_provinces,country_names,geographic_lines',
'OPACITIES': '255,127,192',
'COLORS': ',,',
'MAP0:LAYERS': 'test_point,test_poly,wms:http://wms.geo.admim.ch#test',
'MAP0:SCALE': 250000,
'MAP0:EXTENT': '2600087,1219011,2618587,1243911',
'MAP0:LAYERS': 'countries,states_provinces,country_names,geographic_lines',
'MAP0:SCALE': 12500000,
'MAP0:EXTENT': '-375000,4812500,2375000,7187500',
'MAP0:ROTATION': 0,
'MAP0:GRID_INTERVAL_X': 500,
'MAP0:GRID_INTERVAL_Y': 500,
Expand All @@ -50,13 +44,5 @@ def test_print(self):
'MAP0:HIGHLIGHT_LABELBUFFERSIZE': '',
'MAP0:HIGHLIGHT_LABELSIZE': ''
}
response = self.app.post('/somap', data=params, headers=self.jwtHeader())
response = self.app.post('/ows/qwc_demo', data=params)
self.assertEqual(200, response.status_code, "Status code is not OK")
data = json.loads(response.data)
self.assertEqual('somap_print', data['path'], 'Print project name mismatch')
self.assertEqual('POST', data['method'], 'Method mismatch')
print_params = dict([list(map(unquote, param.split("=", 1))) for param in data['data'].split("&")])
for param in params.keys():
self.assertTrue(param in print_params, "Parameter %s missing in response" % param)
self.assertEqual(print_params[param], str(params[param]), "Parameter %s mismatch" % param)
self.assertTrue("SLD_BODY" in print_params)
Binary file removed tests/testenv.zip
Binary file not shown.

0 comments on commit 8a9d264

Please sign in to comment.