Skip to content

test: add coverage for picture_profile feature#51

Merged
emidiovaleretto merged 2 commits into
mainfrom
test/picture-profile-coverage
Jun 16, 2026
Merged

test: add coverage for picture_profile feature#51
emidiovaleretto merged 2 commits into
mainfrom
test/picture-profile-coverage

Conversation

@emidiovaleretto

Copy link
Copy Markdown
Owner

Context

The picture_profile feature (upload, resize, JPEG conversion, placeholder,
auto-creation via signal) had no test coverage. This adds it and along the
way the tests exposed a real bug with transparent PNGs.

What

Added 5 tests in tests/test_user_profile.py:

  • resize_image shrinks large images to 400px width
  • convert_type_image produces a real JPEG (checks actual format, not just filename)
  • the serializer returns the placeholder URL when a profile has no picture
  • a UserProfile is auto-created via signal when a User is created
  • transparent PNGs (RGBA) are converted to a valid JPEG

Also added tests/helpers.py with a reusable create_test_image helper.

Bug fix included

The RGBA test revealed that convert_type_image crashed on transparent images
(cannot write mode RGBA as JPEG), since JPEG has no alpha channel. Fixed by
converting any non-RGB image to RGB before saving as JPEG. This would have
broken in production for any user uploading a PNG with transparency.

How to verify

pytest tests/test_user_profile.py -v — all 5 pass. Full suite stays green.

Closes #39

@emidiovaleretto emidiovaleretto self-assigned this Jun 16, 2026
@emidiovaleretto emidiovaleretto merged commit bd9b8d1 into main Jun 16, 2026
2 checks passed
@emidiovaleretto emidiovaleretto deleted the test/picture-profile-coverage branch June 16, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TEST] add coverage for picture_profile feature

1 participant