From ab4440ee92d2f53108389055ccfb815146b2fd1c 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 | 6 +++--- src/clear_layman_role_service_schema.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/clear_layman_role_service_schema.py diff --git a/Makefile b/Makefile index 9d8a15476..82a021524 100644 --- a/Makefile +++ b/Makefile @@ -205,7 +205,7 @@ 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 clear_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 @@ -226,7 +226,7 @@ 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 clear_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)" @@ -247,7 +247,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 clear_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/clear_layman_role_service_schema.py b/src/clear_layman_role_service_schema.py new file mode 100644 index 000000000..b1515c31f --- /dev/null +++ b/src/clear_layman_role_service_schema.py @@ -0,0 +1,19 @@ +import psycopg2 +import layman_settings as settings + + +def main(): + print(f"Clearing 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()