From a2603775e99dc2fb767db89178f6c47ecffe1aa3 Mon Sep 17 00:00:00 2001 From: fistutzenste Date: Wed, 29 Jul 2020 15:50:47 +0200 Subject: [PATCH] Small rework regarding tests for the big setup. Removed CHECK_REQUEST_URL. --- Dockerfile | 1 - Dockerfile.dev | 9 +++++---- Dockerfile.tests | 7 +------ Makefile | 9 +++++++++ README.md | 2 -- docker-compose-test.yml => docker-compose.test.yml | 2 -- docker-compose.yml | 1 - entrypoint-tests.sh | 6 ------ entrypoint.sh | 1 + execute-cleanup.sh | 8 ++++++++ requirements.txt | 2 -- requirements_development.txt | 2 ++ src/auth.py | 11 ++++++----- src/config_handling.py | 3 +-- 14 files changed, 33 insertions(+), 31 deletions(-) rename docker-compose-test.yml => docker-compose.test.yml (91%) delete mode 100755 entrypoint-tests.sh create mode 100755 execute-cleanup.sh delete mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile index c38e704..18cb991 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,6 @@ RUN apt-get -y update && apt-get -y upgrade && \ postgresql-client WORKDIR /app -#ENV FLASK_APP mediafileserver.py COPY requirements_production.txt requirements_production.txt RUN pip install -r requirements_production.txt diff --git a/Dockerfile.dev b/Dockerfile.dev index 5a0e45b..19da1f0 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -6,18 +6,19 @@ RUN apt-get -y update && apt-get -y upgrade && \ WORKDIR /app -COPY requirements_production.txt requirements_production.txt -RUN pip install -r requirements_production.txt -COPY requirements_development.txt requirements_development.txt +COPY requirements_production.txt . +COPY requirements_development.txt . RUN pip install -r requirements_development.txt COPY entrypoint.sh . +COPY execute-cleanup.sh . +COPY setup.cfg . EXPOSE 9006 # TODO: Make the port configurable via ENV -ENTRYPOINT ["./entrypoint.sh"] ENV FLASK_APP ./src/mediaserver.py ENV FLASK_ENV development +ENTRYPOINT ["./entrypoint.sh"] CMD ["flask", "run", "--host", "0.0.0.0", "--port", "9006"] diff --git a/Dockerfile.tests b/Dockerfile.tests index bb63450..a36268c 100644 --- a/Dockerfile.tests +++ b/Dockerfile.tests @@ -7,10 +7,5 @@ WORKDIR /app COPY requirements_tests.txt requirements_tests.txt RUN pip install -r requirements_tests.txt -COPY requirements_development.txt requirements_development.txt -RUN pip install -r requirements_development.txt -COPY entrypoint-tests.sh . -COPY setup.cfg . - -ENTRYPOINT ["./entrypoint-tests.sh"] +CMD ["bash", "-c", "sleep infinity"] diff --git a/Makefile b/Makefile index 2e43b7e..514a4a8 100644 --- a/Makefile +++ b/Makefile @@ -3,3 +3,12 @@ build-dev: build-tests: docker build . -f Dockerfile.tests --tag openslides-media-tests + +run-tests: | build-dev build-tests + docker-compose -f docker-compose.test.yml up -d + docker-compose -f docker-compose.test.yml exec tests wait-for-it "media:9006" + docker-compose -f docker-compose.test.yml exec tests pytest + docker-compose -f docker-compose.test.yml down + +run-cleanup: | build-dev + docker run -ti --entrypoint="" -v `pwd`/src:/app/src -v `pwd`/tests:/app/tests openslides-media-dev bash -c "./execute-cleanup.sh" \ No newline at end of file diff --git a/README.md b/README.md index 09c0d10..c67337d 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,6 @@ variables. Configs without default must be specified. All configs (see - `URL_PREFIX`: Default `/media/`. The prefix, the server listens to. E.g. for the default, all files must be requested this way: `/media/`. -- `CHECK_REQUEST_URL`: The url to make the chack request to. The host and port - must be given. E.g.: `worker:9006/check-media/` - `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER`, `DB_PASSWORD`: The host, port, database name, user and password for the mediafile db - `BLOCK_SIZE`: Default 4096. The size of the blocks, the file is chunked into. diff --git a/docker-compose-test.yml b/docker-compose.test.yml similarity index 91% rename from docker-compose-test.yml rename to docker-compose.test.yml index 99b6c54..03d542e 100644 --- a/docker-compose-test.yml +++ b/docker-compose.test.yml @@ -14,7 +14,6 @@ services: - MEDIA_DATABASE_NAME=openslides - MEDIA_DATABASE_USER=openslides - MEDIA_DATABASE_PASSWORD=openslides - - CHECK_REQUEST_URL=test/ volumes: - ./src:/app/src ports: @@ -26,4 +25,3 @@ services: - media-postgresql volumes: - ./tests:/app/tests - - ./src:/app/src diff --git a/docker-compose.yml b/docker-compose.yml index d1b5773..b02917c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,6 @@ services: - MEDIA_DATABASE_NAME=openslides - MEDIA_DATABASE_USER=openslides - MEDIA_DATABASE_PASSWORD=openslides - - CHECK_REQUEST_URL=test/ volumes: - ./src:/app/src ports: diff --git a/entrypoint-tests.sh b/entrypoint-tests.sh deleted file mode 100755 index a0cdb2b..0000000 --- a/entrypoint-tests.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -wait-for-it -t 0 "media:9006" - -black src/ tests/ && isort --recursive src/ tests/ && flake8 src/ tests/ && \ - pytest diff --git a/entrypoint.sh b/entrypoint.sh index 528d65d..79cd7dc 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e export MEDIA_DATABASE_HOST="${MEDIA_DATABASE_HOST:-db}" export MEDIA_DATABASE_PORT="${MEDIA_DATABASE_PORT:-5432}" diff --git a/execute-cleanup.sh b/execute-cleanup.sh new file mode 100755 index 0000000..daa171a --- /dev/null +++ b/execute-cleanup.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +printf "Black:\n" +black src/ tests/ +printf "\nIsort:\n" +isort src/ tests/ +printf "\nFlake8:\n" +flake8 src/ tests/ \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index af6ede3..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ --r requirements_production.txt --r requirements_development.txt diff --git a/requirements_development.txt b/requirements_development.txt index fc2daa3..bb77954 100644 --- a/requirements_development.txt +++ b/requirements_development.txt @@ -1,3 +1,5 @@ +-r requirements_production.txt + flake8 black isort diff --git a/src/auth.py b/src/auth.py index 296780c..4c0c97c 100644 --- a/src/auth.py +++ b/src/auth.py @@ -5,6 +5,8 @@ def get_mediafile_id(meeting_id, path, app, cookie): return meeting_id + + # TODO: Enable the call to the presenter check_request_url = get_check_request_url(meeting_id, path, app) app.logger.debug(f"Send check request: {check_request_url}") @@ -29,8 +31,7 @@ def get_mediafile_id(meeting_id, path, app, cookie): return id -def get_check_request_url(meeting_id, path, app): - check_request_url = app.config["CHECK_REQUEST_URL"] - if not check_request_url.endswith("/"): - raise ServerError("The CHECK_REQUEST_URL must end with an slash.") - return f"http://{check_request_url}/{meeting_id}/{path}" +def get_check_request_url(): + presenter_host = "todo" + presenter_port = "todo" + return f"http://{presenter_host}:{presenter_port}/system/presenter" diff --git a/src/config_handling.py b/src/config_handling.py index 4b16987..a800eca 100644 --- a/src/config_handling.py +++ b/src/config_handling.py @@ -3,7 +3,7 @@ def get_type_for(config_value): - if config_value in ["MEDIA_DATABASE_PORT", "BLOCK_SIZE"]: + if config_value in ("MEDIA_DATABASE_PORT", "BLOCK_SIZE"): return int return str @@ -15,7 +15,6 @@ def get_default_for(config_value): def init_config(app): all_configs = ( - "CHECK_REQUEST_URL", "MEDIA_DATABASE_HOST", "MEDIA_DATABASE_PORT", "MEDIA_DATABASE_NAME",