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 #11716: Failure in Dynamic Image ServeView #11825

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

afonsomatos3
Copy link

Following the line of thought of @LANCECORREIA, I added back the line that was removed in a previous commit,"rendition.file.open("rb")" in serve.py. I also, created a test in admin/tests/viewsets , test_image_presence.py that confirms that the issue has been resolved. The test looks for a status error code 500 in the display of an image, something that happenned when the dynamic serve view failed. If it finds it, the test fails. The test also passes when we dont't use a dynamic serve view.
Have in mind that test_image_presence.py in order to run, needs to have already have an image in our home page that we are trying to display.
I am new to wagtail so if something isn't to your liking, please let me know.

Added back a line that was removed in a previous commit,"rendition.file.open("rb")" in serve.py.
Also, created a test in admin/tests/viewsets , test_image_presence.py that confirms that
the issue has been resolved. The test looks for a status error code 500 in the display of an image,
something that happenned when the dynamic serve view failed. If it finds it, the test fails.
The test also passes when we dont't use a dynamic serve view.
Copy link

squash-labs bot commented Apr 5, 2024

Manage this branch in Squash

Test this branch here: https://afonsomatos3bugfix11716-dynami-k1g5h.squash.io



class TestImagePresence(WagtailTestUtils, TestCase):
def test_image_presence(self):
Copy link
Member

Choose a reason for hiding this comment

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

Issue: This test case feels rather complex considering what it's testing. You should be able to create an image URL for an existing image, and then check the response looks like an image.

There are already tests for the image serve view, so this would make sense there. I'm also not sure what this is testing that the other tests aren't already.

Copy link
Author

Choose a reason for hiding this comment

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

I added test_image_presence.py because i saw that all of the tests that were in the main code were passing while the bug was still present. Pardon me if i am mistaken but it seems none of them were testing the Dynamic Serve View. To resolve that, I made this test and i made sure that it passed with the fix and it failed without it. All of this code stands for the fact that i had some troubles replicating the bug on a test, hence all of the code. With that being said, you prefer i reduce the complexety of the test? I could try to do that but i think it's presence is necessary to verify the bug fix. I am new to wagtail and open source code in general, so I apologize in advance for my lack of experience, and especially my late reply.

Thank you for your time,
Afonso Matos

Copy link
Member

Choose a reason for hiding this comment

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

There are definitely tests for the serve view here:

class TestFrontendServeView(TestCase):

You should be able to adapt what you have to work with the setup there, which shows you how to find the serve URL for a given image. Your tests seem to also assume you have a separate Wagtail instance running on port 8000, which is definitely not right - you'll need to be using the test client.

To write the test, I'd recommend something test-driven. Undo the fix in serve.py, and then write a test case which fails, and thus exercises the bug. Fix the bug, and the test case should pass. That is the perfect test 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants