Mercurial > gemma
changeset 4120:ad0c373dff6a request_hist_bns
Merged default
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Wed, 31 Jul 2019 19:08:53 +0200 |
parents | 0cf0008070db (current diff) b785b6bef578 (diff) |
children | 8c62809ea87e |
files | |
diffstat | 6 files changed, 84 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/README.md Wed Jul 31 19:08:35 2019 +0200 +++ b/README.md Wed Jul 31 19:08:53 2019 +0200 @@ -21,6 +21,21 @@ For further details see [docs/DEVELOPMENT](docs/DEVELOPMENT.md), +## Running Tests + +- Running database tests: + + * You will need a PostgreSQL cluster with PostGIS and pgTAP. + * To run the tests use the script `./schema/run_tests.sh`. + * `./schema/run_tests.sh --help` shows you available options. + Per default the script will create (and drop if it already exists) + a database named "gemma_test" and all necessary roles in the postgres + default cluster (listening on port 5432) and run the tests + in that database. + * The script must be run as a user with PostgreSQL super user rights. + By convention this is "postgres" on most systems. + + ## Setup Database - You will need a PostgreSQL cluster with PostGIS.
--- a/schema/auth_tests.sql Wed Jul 31 19:08:35 2019 +0200 +++ b/schema/auth_tests.sql Wed Jul 31 19:08:53 2019 +0200 @@ -75,11 +75,11 @@ PREPARE bn_insert (varchar, geometry(MULTIPOLYGON, 4326)) AS INSERT INTO waterway.bottlenecks ( - gauge_location, gauge_validity, validity, + gauge_location, validity, bottleneck_id, stretch, area, rb, lb, responsible_country, revisiting_time, limiting, date_info, source_organization) SELECT - location, validity, validity, + location, validity, $1, isrsrange(('AT', 'XXX', '00001', '00000', 0)::isrs, ('AT', 'XXX', '00001', '00000', 2)::isrs),
--- a/schema/gemma_tests.sql Wed Jul 31 19:08:35 2019 +0200 +++ b/schema/gemma_tests.sql Wed Jul 31 19:08:53 2019 +0200 @@ -30,40 +30,3 @@ $$, 23505, NULL, 'No duplicate geometries can be inserted into waterway_area'); - -START TRANSACTION; -CREATE TEMP TABLE new_v (v) AS - SELECT tstzrange(current_timestamp - '2 d'::interval, - current_timestamp - '12 h'::interval); -INSERT INTO waterway.gauges ( - location, - validity, - objname, - geom, - zero_point, - date_info, - source_organization, - lastupdate, - erased) -VALUES ( - ('AT', 'XXX', '00001', 'G0001', 1)::isrs, - (SELECT v FROM new_v), - 'testgauge', - ST_geomfromtext('POINT(0 0)', 4326), - 0, - current_timestamp, - 'testorganization', - current_timestamp, - true); --- Fix validity of old entry to match exclusion constraint -UPDATE waterway.gauges SET - validity = validity - (SELECT v FROM new_v) -WHERE location = ('AT', 'XXX', '00001', 'G0001', 1)::isrs - AND validity && (SELECT v FROM new_v) - AND NOT erased; -COMMIT; -SELECT results_eq($$ - SELECT count(*) FROM waterway.bottlenecks GROUP BY bottleneck_id; - $$, - CAST(ARRAY[2,2] AS bigint[]), - 'Bottlenecks have been split to two new matching gauge versions');
--- a/schema/run_tests.sh Wed Jul 31 19:08:35 2019 +0200 +++ b/schema/run_tests.sh Wed Jul 31 19:08:53 2019 +0200 @@ -5,35 +5,87 @@ # SPDX-License-Identifier: AGPL-3.0-or-later # License-Filename: LICENSES/AGPL-3.0.txt # -# Copyright (C) 2018 by via donau +# Copyright (C) 2018, 2019 by via donau # – Österreichische Wasserstraßen-Gesellschaft mbH # Software engineering by Intevation GmbH # # Author(s): # * Tom Gottfried <tom@intevation.de> -dropdb --if-exists gemma_test +ME=`basename "$0"` +BASEDIR=`dirname "$0"` + +usage() +{ + cat <<EOF +$ME [OPTION]... + +Options: + -d, --db=NAME create (and drop if exists) the database NAME. + Default: "gemma_test" + -p, --port=PORT connect do the postgresql cluster at PORT. + Default is the postgresql standard port 5432 + --help display this help and exit + +EOF +} + +# Defaults: + +db=gemma_test +port=5432 + +# Parse options: -./install-db.sh -d gemma_test -psql -qv ON_ERROR_STOP= -c 'CREATE EXTENSION pgtap' -d gemma_test +OPTS=`getopt \ + -l help,db:,port: \ + -o d:p: -n "$ME" -- "$@"` +[ $? -eq 0 ] || { usage ; exit 1 ; } + +eval set -- "$OPTS" + +while true ; do + case "$1" in + --db|-d) + db="$2" + shift 2 + ;; + --port|-p) + port="$2" + shift 2 + ;; + --help) + { usage ; exit 0 ; } + ;; + --) + shift + break + ;; + esac +done + +dropdb --if-exists -p "$port" "$db" + +./install-db.sh -d "$db" -p "$port" +psql -qv ON_ERROR_STOP= -c 'CREATE EXTENSION pgtap' -d "$db" -p "$port" # Collect test roles to be dropped # Concatenate with dummy role to prevent syntax error if there is no test role -TEST_ROLES=$(psql -qtc \ +TEST_ROLES=$(psql -d "$db" -p "$port" -qtc \ "SELECT concat_ws(',', 'test', string_agg(rolname, ',')) FROM pg_roles WHERE rolname LIKE 'test%'") # Drop test roles, add test data and run tests -psql -qXv ON_ERROR_STOP= -v -d gemma_test \ +psql -qXv ON_ERROR_STOP= -v -d "$db" -p "$port" \ -c 'SET client_min_messages TO WARNING' \ -c "DROP ROLE IF EXISTS $TEST_ROLES" \ - -f tap_tests_data.sql \ - -c "SELECT plan(71 + ( + -f "$BASEDIR"/tap_tests_data.sql \ + -c "SELECT plan(70 + ( SELECT count(*)::int FROM information_schema.tables WHERE table_schema = 'waterway'))" \ - -f gemma_tests.sql \ - -f isrs_tests.sql \ - -f auth_tests.sql \ - -f manage_users_tests.sql \ + -f "$BASEDIR"/gemma_tests.sql \ + -f "$BASEDIR"/isrs_tests.sql \ + -f "$BASEDIR"/auth_tests.sql \ + -f "$BASEDIR"/manage_users_tests.sql \ -c 'SELECT * FROM finish()'
--- a/schema/tap_tests_data.sql Wed Jul 31 19:08:35 2019 +0200 +++ b/schema/tap_tests_data.sql Wed Jul 31 19:08:53 2019 +0200 @@ -57,7 +57,7 @@ current_timestamp, 'testorganization', current_timestamp) - RETURNING location, validity, validity), + RETURNING location, validity), bns AS ( VALUES ( 'testbottleneck1', @@ -75,7 +75,7 @@ 1, 'depth', current_timestamp, 'testorganization', true )) INSERT INTO waterway.bottlenecks ( - gauge_location, gauge_validity, validity, + gauge_location, validity, bottleneck_id, stretch, area, rb, lb, responsible_country, revisiting_time, limiting, date_info, source_organization, staging_done) SELECT * FROM gs, bns;
--- a/schema/update-db.sh Wed Jul 31 19:08:35 2019 +0200 +++ b/schema/update-db.sh Wed Jul 31 19:08:53 2019 +0200 @@ -21,7 +21,7 @@ $ME [OPTION]... Options: - -d, --db=NAME create the database NAME. Default: "gemma" + -d, --db=NAME update the database NAME. Default: "gemma" -p, --port=PORT connect do the postgresql cluster at PORT. Default is the postgresql standard port 5432 --help display this help and exit