Skip to content

Commit

Permalink
Generate image in get_image_from_mock_server instead of using a stati…
Browse files Browse the repository at this point in the history
…c file
  • Loading branch information
TvanWalen committed May 13, 2024
1 parent a12e32b commit 994caeb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ WORKDIR /app_install
ADD requirements_dev.txt requirements_dev.txt
RUN pip install -r requirements_dev.txt

RUN mkdir -p /static && chown datapunt /static

WORKDIR /src
USER datapunt

Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ services:
USE_JWKS_TEST_KEY: 'true'
MOCK_GET_IMAGE_FROM_SERVER: 'true'
METADATA_SERVER_BASE_URL: 'http://metadata-server:8000'
volumes:
- ./static:/static
command: python manage.py runserver 0.0.0.0:8000

test:
Expand Down
14 changes: 11 additions & 3 deletions src/iiif/image_server.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import logging
import re
from io import BytesIO

import requests
from django.conf import settings
from django.http import HttpResponse
from PIL import Image
from requests.exceptions import RequestException

from main.utils import ImmediateHttpResponse
Expand Down Expand Up @@ -41,13 +43,19 @@ def create_file_url_and_headers(url_info, metadata):
return iiif_image_url, {"Authorization": settings.WABO_AUTHORIZATION}


def create_mock_image(format):
img = Image.new("RGB", (32, 32), color="green")
buf = BytesIO()
img.save(buf, format=format)
return buf.getvalue()


# For develop/test environments where we don't have access to the upstream server
def get_image_from_mock_server():
response = requests.Response()
response.status_code = 200
with open(settings.STATIC_IMAGE, "rb") as f:
response._content = f.read()
response.headers["Content-Type"] = "image/png"
response.headers["Content-Type"] = "image/jpeg"
response._content = create_mock_image("JPEG")
return response


Expand Down
Binary file removed static/example.jpg
Binary file not shown.

0 comments on commit 994caeb

Please sign in to comment.