From 50e91cc18678896a75502da178b680c7bac63512 Mon Sep 17 00:00:00 2001 From: Jiri Kozel Date: Wed, 20 Dec 2023 13:24:22 +0100 Subject: [PATCH] Drop role service DB schema before tests --- Makefile | 8 +++++--- src/drop_layman_role_service_schema.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/drop_layman_role_service_schema.py diff --git a/Makefile b/Makefile index 9d8a15476..7739fd322 100644 --- a/Makefile +++ b/Makefile @@ -205,11 +205,12 @@ test: docker compose -f docker-compose.deps.yml -f docker-compose.test.yml rm -f layman_test docker compose -f docker-compose.deps.yml -f docker-compose.test.yml up -d postgresql docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps layman_test bash -c "bash ensure-test-data.sh && python3 src/assert_db.py" - docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B setup_geoserver.py" + docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B drop_layman_role_service_schema.py && python3 -B setup_geoserver.py" docker compose -f docker-compose.deps.yml -f docker-compose.test.yml up --force-recreate --no-deps -d celery_worker_test docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --name layman_test_run_1 layman_test test-fast: + docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B drop_layman_role_service_schema.py && python3 -B setup_geoserver.py" docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps --name layman_test_run_1 layman_test test-separated: @@ -226,11 +227,12 @@ test-separated: docker compose -f docker-compose.deps.yml -f docker-compose.test.yml rm -f layman_test docker compose -f docker-compose.deps.yml -f docker-compose.test.yml up -d postgresql docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps layman_test bash -c "bash ensure-test-data.sh && python3 src/assert_db.py" - docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B setup_geoserver.py" + docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B drop_layman_role_service_schema.py && python3 -B setup_geoserver.py" docker compose -f docker-compose.deps.yml -f docker-compose.test.yml up --force-recreate --no-deps -d celery_worker_test docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --name layman_test_run_1 -e "TEST_TYPE=$(test_type)" layman_test bash -c "bash test_separated.sh $(max_fail)" test-separated-fast: + docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B drop_layman_role_service_schema.py && python3 -B setup_geoserver.py" docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps --name layman_test_run_1 -e "TEST_TYPE=$(test_type)" layman_test bash -c "bash test_separated.sh $(max_fail)" test-static: @@ -247,7 +249,7 @@ test-static: docker compose -f docker-compose.deps.yml -f docker-compose.test.yml rm -f layman_test docker compose -f docker-compose.deps.yml -f docker-compose.test.yml up -d postgresql docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps layman_test bash -c "bash ensure-test-data.sh && python3 src/assert_db.py" - docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B setup_geoserver.py" + docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B drop_layman_role_service_schema.py && python3 -B setup_geoserver.py" docker compose -f docker-compose.deps.yml -f docker-compose.test.yml up --force-recreate --no-deps -d celery_worker_test docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --name layman_test_run_1 layman_test bash -c "bash test_static.sh" diff --git a/src/drop_layman_role_service_schema.py b/src/drop_layman_role_service_schema.py new file mode 100644 index 000000000..271b6e698 --- /dev/null +++ b/src/drop_layman_role_service_schema.py @@ -0,0 +1,19 @@ +import psycopg2 +import layman_settings as settings + + +def main(): + print(f"Drop Layman role service DB schema.") + + # Layman DB + conn = psycopg2.connect(**settings.PG_CONN) + conn.autocommit = True + cur = conn.cursor() + cur.execute(f""" +DROP SCHEMA IF EXISTS "{settings.LAYMAN_INTERNAL_ROLE_SERVICE_SCHEMA}" CASCADE; +""") + conn.commit() + + +if __name__ == "__main__": + main()