diff --git a/Makefile b/Makefile index d6f150b..482f4d5 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,10 @@ build-dev: build-tests: docker build . -f Dockerfile.tests --tag openslides-media-tests -build-dummy-presenter: - docker build . -f tests/dummy_presenter/Dockerfile.dummy_presenter --tag openslides-media-dummy-presenter +build-dummy-autoupdate: + docker build . -f tests/dummy_autoupdate/Dockerfile.dummy_autoupdate --tag openslides-media-dummy-autoupdate -start-test-setup: | build-dev build-tests build-dummy-presenter +start-test-setup: | build-dev build-tests build-dummy-autoupdate docker compose -f docker-compose.test.yml up -d docker compose -f docker-compose.test.yml exec -T tests wait-for-it "media:9006" diff --git a/README.md b/README.md index de7eebf..fc986e9 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ Delivers media files for OpenSlides. It stores the data in the database. password (default: `/run/secrets/postgres_password`; in dev mode the password is always assumed to be `openslides`) - `MEDIA_BLOCK_SIZE`: The size of the blocks, the file is chunked into (default: `4096`) - `MEDIA_CLIENT_CACHE_DURATION`: The duration in seconds a file should be cached by a client (default: `86400`; disabled when: `0`) -- `AUTOUPDATE_HOST`: Host of the presenter service (default: `autoupdate`) -- `AUTOUPDATE_PORT`: Port of the presenter service (default: `9012`) +- `AUTOUPDATE_HOST`: Host of the autoupdate service (default: `autoupdate`) +- `AUTOUPDATE_PORT`: Port of the autoupdate service (default: `9012`) ## Production setup Use the provided Dockerfile. It creates the tables in Postgresql, if they don't diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 5bfdb70..a4ff3ab 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -16,10 +16,10 @@ services: - ./src:/app/src ports: - 9006:9006 - dummy_presenter: - image: openslides-media-dummy-presenter + dummy_autoupdate: + image: openslides-media-dummy-autoupdate volumes: - - ./tests/dummy_presenter:/app/dummy_presenter + - ./tests/dummy_autoupdate:/app/dummy_autoupdate tests: image: openslides-media-tests environment: @@ -27,7 +27,7 @@ services: depends_on: - media - postgres - - dummy_presenter + - dummy_autoupdate volumes: - ./tests:/app/tests postgres: diff --git a/src/mediaserver.py b/src/mediaserver.py index e322ff1..a95cbd2 100644 --- a/src/mediaserver.py +++ b/src/mediaserver.py @@ -39,11 +39,11 @@ def serve(file_id): return redirect("/") # get file id - presenter_headers = dict(request.headers) - del_keys = [key for key in presenter_headers if "content" in key] + autoupdate_headers = dict(request.headers) + del_keys = [key for key in autoupdate_headers if "content" in key] for key in del_keys: - del presenter_headers[key] - ok, filename, auth_header = check_file_id(file_id, presenter_headers) + del autoupdate_headers[key] + ok, filename, auth_header = check_file_id(file_id, autoupdate_headers) if not ok: raise NotFoundError() diff --git a/tests/dummy_autoupdate/Dockerfile.dummy_autoupdate b/tests/dummy_autoupdate/Dockerfile.dummy_autoupdate new file mode 100644 index 0000000..77aba8d --- /dev/null +++ b/tests/dummy_autoupdate/Dockerfile.dummy_autoupdate @@ -0,0 +1,10 @@ +FROM python:3.10.13-slim-bookworm + +WORKDIR /app + +RUN pip install flask + +ENV FLASK_APP ./dummy_autoupdate/dummy_autoupdate.py +ENV FLASK_ENV development + +CMD ["flask", "run", "--host", "0.0.0.0", "--port", "9012"] diff --git a/tests/dummy_autoupdate/dummy_autoupdate.py b/tests/dummy_autoupdate/dummy_autoupdate.py new file mode 100644 index 0000000..f7ebf29 --- /dev/null +++ b/tests/dummy_autoupdate/dummy_autoupdate.py @@ -0,0 +1,70 @@ +from flask import Flask, jsonify, request + +app = Flask(__name__) + +app.logger.info("Started Dummy-Autoupdate") + + +# for testing +@app.route("/internal/autoupdate", methods=["POST"]) +def dummy_autoupdate(): + app.logger.debug(f"dummy_autoupdate gets: {request.json}") + file_id = request.json[0]["ids"][0] + + # Valid response from autoupdate, but not found in DB + if file_id == 1: + return jsonify( + [ + { + f"mediafile/{file_id}/id": file_id, + f"mediafile/{file_id}/filename": "Does not exist", + } + ] + ) + + # OK-cases for dummy data + if file_id == 2: + return jsonify( + [ + { + f"mediafile/{file_id}/id": file_id, + f"mediafile/{file_id}/filename": "A.txt", + } + ] + ) + if file_id == 3: + return jsonify( + [ + { + f"mediafile/{file_id}/id": file_id, + f"mediafile/{file_id}/filename": "in.jpg", + } + ] + ) + + # OK-cases for uploaded data + if file_id in (4, 5, 6, 7): + return jsonify( + [ + { + f"mediafile/{file_id}/id": file_id, + f"mediafile/{file_id}/filename": str(file_id), + } + ] + ) + + # invalid responses + if file_id == 10: + return jsonify([None]) + if file_id == 11: + return "some text" + if file_id == 12: + return "An error", 500 + if file_id == 13: + return [] + if file_id == 14: + return jsonify([{f"mediafile/{file_id}/id": file_id}]) + + # not found or no perms + if file_id == 20: + return jsonify([]) diff --git a/tests/dummy_presenter/Dockerfile.dummy_presenter b/tests/dummy_presenter/Dockerfile.dummy_presenter deleted file mode 100644 index 203700d..0000000 --- a/tests/dummy_presenter/Dockerfile.dummy_presenter +++ /dev/null @@ -1,10 +0,0 @@ -FROM python:3.10.13-slim-bookworm - -WORKDIR /app - -RUN pip install flask - -ENV FLASK_APP ./dummy_presenter/dummy_presenter.py -ENV FLASK_ENV development - -CMD ["flask", "run", "--host", "0.0.0.0", "--port", "9003"] diff --git a/tests/dummy_presenter/dummy_presenter.py b/tests/dummy_presenter/dummy_presenter.py deleted file mode 100644 index c93fad8..0000000 --- a/tests/dummy_presenter/dummy_presenter.py +++ /dev/null @@ -1,42 +0,0 @@ -from flask import Flask, jsonify, request - -app = Flask(__name__) - -app.logger.info("Started Dummy-Presenter") - - -# for testing -@app.route("/system/presenter/handle_request", methods=["POST"]) -def dummy_presenter(): - app.logger.debug(f"dummy_presenter gets: {request.json}") - file_id = request.json[0]["data"]["mediafile_id"] - - # Valid response from presenter, but not found in DB - if file_id == 1: - return jsonify([{"ok": True, "filename": "Does not exist"}]) - - # OK-cases for dummy data - if file_id == 2: - return jsonify([{"ok": True, "filename": "A.txt"}]) - if file_id == 3: - return jsonify([{"ok": True, "filename": "in.jpg"}]) - - # OK-cases for uploaded data - if file_id in (4, 5, 6, 7): - return jsonify([{"ok": True, "filename": str(file_id)}]) - - # invalid responses - if file_id == 10: - return jsonify([None]) - if file_id == 11: - return "some text" - if file_id == 12: - return "An error", 500 - if file_id == 13: - return {"ok": False} - if file_id == 14: - return jsonify([{"ok": True}]) - - # not found or no perms - if file_id == 20: - return jsonify([{"ok": False}]) diff --git a/tests/test_get.py b/tests/test_get.py index 046188b..5050d84 100644 --- a/tests/test_get.py +++ b/tests/test_get.py @@ -21,7 +21,7 @@ def test_invalid_responses(): assert "message" in response.json() -def test_not_ok_from_presenter(): +def test_not_ok_from_autoupdate(): response = get_mediafile(20) assert response.status_code == 404 assert "message" in response.json()