Changeset f0e64eb in OpenWorkouts-current for ow/tests


Ignore:
Timestamp:
Feb 15, 2019, 11:00:35 AM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current, feature/docs, master
Children:
0fa21cd
Parents:
eb20dc8
Message:

(#51) Fixed profile images were too big:

  • Added new dependency (Pillow)
  • Modified the user profile picture view. Now it accepts a GET parameter (size) telling the size of the image we want. Only one value is needed, the code will scale the image appropiately.
  • Modified the dashboard, profile and edit_profile templates to ask for a smaller version (200px) of the user profile picture.

IMPORTANT: Ensure you install Pillow in any existing environments after pulling:

pip install Pillow

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/tests/views/test_user.py

    reb20dc8 rf0e64eb  
    55from shutil import copyfileobj
    66from unittest.mock import Mock, patch
     7from io import BytesIO
    78
    89import pytest
     
    1516
    1617from webob.multidict import MultiDict
     18
     19from PIL import Image
    1720
    1821from ow.models.root import OpenWorkouts
     
    417420        assert response.status_int == 200
    418421        assert response.content_type == 'image'
     422        # as we did not pass a specific size as a get parameter, the size is
     423        # the same as the original image
     424        original_image = Image.open(image_path)
     425        returned_image = Image.open(BytesIO(response.body))
     426        assert original_image.size == returned_image.size
     427
     428        # now, ask for a smaller image
     429        request.GET['size'] = original_image.size[0] - 20
     430        response = user_views.profile_picture(user, request)
     431        assert isinstance(response, Response)
     432        assert response.status_int == 200
     433        assert response.content_type == 'image'
     434        # now the size of the original image is bigger
     435        returned_image = Image.open(BytesIO(response.body))
     436        assert original_image.size > returned_image.size
     437
     438        # now, ask for a size that is bigger than the original image,
     439        # image will be the same size, as we do not "grow" its size
     440        request.GET['size'] = original_image.size[0] + 1000
     441        response = user_views.profile_picture(user, request)
     442        assert isinstance(response, Response)
     443        assert response.status_int == 200
     444        assert response.content_type == 'image'
     445        # now the size of the original image is bigger
     446        returned_image = Image.open(BytesIO(response.body))
     447        assert original_image.size == returned_image.size
     448
    419449
    420450    def test_edit_profile_get(self, dummy_request, john):
Note: See TracChangeset for help on using the changeset viewer.