Skip to content

Commit

Permalink
Merge pull request #2646 from peterbe/test-uploading-jpeg
Browse files Browse the repository at this point in the history
test uploading jpeg
  • Loading branch information
peterbe authored Dec 31, 2024
2 parents 61ae0dc + 5b0592a commit 6d3273f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,16 @@ jobs:
du -sh .venv
- name: Install system dependencies
run: sudo apt-get install pngquant
run: |
set -ex
sudo apt-get install pngquant libjpeg-progs
# 'jpegtran --version' fails, hence the '|| echo'
which jpegtran || echo "jpegtran installed"
pngquant --version
which pngquant
- name: Download NLTK dependencies
run: uv run python scripts/nltk-downloads.py
Expand Down
Binary file added peterbecom/api/tests/test_image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions peterbecom/api/tests/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,38 @@ def test_happy_path(admin_client):
assert response.json()["deleted"]


def test_upload_jpeg(admin_client, client):
BlogItem.objects.create(
oid="hello-world",
title="Hello World",
pub_date=timezone.now(),
proper_keywords=["one", "two"],
)
with open(Path(__file__).parent / "test_image.jpg", "rb") as f:
test_file = SimpleUploadedFile(
"test_image.jpg", f.read(), content_type="image/jpeg"
)

url = reverse("api:images", args=["hello-world"])

response = admin_client.post(
url, {"file": test_file, "title": "Some title"}, format="multipart"
)

response = admin_client.get(url)
assert response.status_code == 200
images = response.json()["images"]
assert images

response = client.get(images[0]["full_url"])
assert response.status_code == 200
assert response.headers["content-type"] == "image/jpeg"

response = client.get(images[0]["small"]["url"])
assert response.status_code == 200
assert response.headers["content-type"] == "image/jpeg"


def test_open_graph_image(admin_client):
url = reverse("api:open_graph_image", args=["hello-world"])
response = admin_client.get(url)
Expand Down
2 changes: 1 addition & 1 deletion peterbecom/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def path(*x):

MAX_BLOGCOMMENT_PAGES = 20

MOZJPEG_PATH = "mozjpeg"
MOZJPEG_LOCATION = "jpegtran"
GUETZLI_PATH = "guetzli"
PNGQUANT_PATH = "pngquant"

Expand Down

0 comments on commit 6d3273f

Please sign in to comment.