Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix text wrapping in watermarked images #2467

Merged
merged 3 commits into from
Jun 23, 2023
Merged

Fix text wrapping in watermarked images #2467

merged 3 commits into from
Jun 23, 2023

Conversation

zackkrida
Copy link
Member

Fixes

Fixes #2466 by @zackkrida

Description

Fixes the watermark endpoint's ability to wrap text to multiple lines.

Testing Instructions

Make sure tests pass. Also, you could add this test to main and verify that it fails there:

diff --git a/api/test/unit/utils/test_watermark.py b/api/test/unit/utils/test_watermark.py
index f9a8c994d..1fb5814a3 100644
--- a/api/test/unit/utils/test_watermark.py
+++ b/api/test/unit/utils/test_watermark.py
@@ -51,3 +51,17 @@ def test_sends_UA_header(requests):
     assert len(requests.requests) > 0
     for r in requests.requests:
         assert r.headers == HEADERS
+
+def test_long_title_returns_correctly(requests):
+    # Make the title 400 chars long
+    _MOCK_IMAGE_INFO_LONG_TITLE = dict(_MOCK_IMAGE_INFO)
+    _MOCK_IMAGE_INFO_LONG_TITLE["title"] = "a" * 400
+
+    watermark("http://example.com/", _MOCK_IMAGE_INFO_LONG_TITLE)
+
+    assert len(requests.requests) > 0
+    for r in requests.requests:
+        assert r.headers == HEADERS
+
+    # Assert that the content of the response is the mock image bytes
+    assert requests.requests[0].response.content == _MOCK_IMAGE_BYTES

on macos copy the diff here and pbpaste | git apply. Otherwise save it to a file and cat diff.patch | git apply.

Then, run the test file with just api/test test/unit/utils/test_watermark.py

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (if applicable).

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@zackkrida zackkrida requested a review from a team as a code owner June 21, 2023 19:35
@zackkrida zackkrida requested review from obulat and stacimc June 21, 2023 19:35
@github-actions github-actions bot added the 🧱 stack: api Related to the Django API label Jun 21, 2023
@openverse-bot openverse-bot added 🟨 priority: medium Not blocking but should be addressed soon 🛠 goal: fix Bug fix 💻 aspect: code Concerns the software code in the repository labels Jun 21, 2023
Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so weird! I would never think that integer division with float would return a float.
Great find!

@zackkrida
Copy link
Member Author

Yup, who knew?

>>> 10.2 // 10
1.0

Copy link
Collaborator

@stacimc stacimc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Member

@dhruvkb dhruvkb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that // calculates the integer quotient but in a float type is just plain silly.

@zackkrida zackkrida merged commit e131815 into main Jun 23, 2023
@zackkrida zackkrida deleted the fix-#2466 branch June 23, 2023 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🛠 goal: fix Bug fix 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: api Related to the Django API
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Watermark endpoint 500 errors related to character encoding
5 participants