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

RDISCROWD-5567 enhance task guidelines images #801

Merged
merged 20 commits into from
Jan 19, 2023

Conversation

n00rsy
Copy link

@n00rsy n00rsy commented Jan 12, 2023

  • Enhance Image Uploading for GIGwork Project Instructions
  • Enable uploading task guidelines images to cloud storage

Re: bloomberg/pybossa-default-theme#386

@coveralls
Copy link

coveralls commented Jan 12, 2023

Pull Request Test Coverage Report for Build 3959929636

  • 35 of 35 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 93.97%

Totals Coverage Status
Change from base Build 3766833203: 0.01%
Covered Lines: 16456
Relevant Lines: 17512

💛 - Coveralls

Copy link

@kbecker42 kbecker42 left a comment

Choose a reason for hiding this comment

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

The update to the themes pointer (static/..., templates/..., etc) would probably need to be done after the templates PR has been merged. This way, this PR can point to themes in the main branch.

@n00rsy n00rsy changed the title Rdiscrowd 5567 enhance task guidelines images RDISCROWD-5567 enhance task guidelines images Jan 12, 2023
Copy link

@kbecker42 kbecker42 left a comment

Choose a reason for hiding this comment

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

This looks good!

I'm wondering if we should consider avoiding increasing the size of the repo with the large binary image (14.8MB) in the unit test, with two options:

  1. Use a smaller image that is just over 5MB in size to trigger the error condition.
  2. Skip the large image upload and instead refactor the file size calculation into a separate method and mock this method to return True in the unit test, thus triggering the error condition without actually uploading a large image. preferable

In this case, the large image could then be deleted from the commit. Thank you.

Adding @XiChenn for comment as well.

pybossa/view/projects.py Outdated Show resolved Hide resolved
test/test_web.py Outdated Show resolved Hide resolved
pybossa/view/projects.py Outdated Show resolved Hide resolved
@XiChenn
Copy link

XiChenn commented Jan 13, 2023

This looks good!

I'm wondering if we should consider avoiding increasing the size of the repo with the large binary image (14.8MB) in the unit test, with two options:

  1. Use a smaller image that is just over 5MB in size to trigger the error condition.
  2. Skip the large image upload and instead refactor the file size calculation into a separate method and mock this method to return True in the unit test, thus triggering the error condition without actually uploading a large image. preferable

In this case, the large image could then be deleted from the commit. Thank you.

Adding @XiChenn for comment as well.

I'm with Kory not to upload large files to the repo. How about using a a small file (~10k) for the "test_task_presenter_image_upload" and using Mock as Kory suggested to test this function "upload_task_guidelines_image" specifically with mock of large file? Some reference with "mock" could be found here.

file_size_mb = file.seek(0, os.SEEK_END) / 1024 / 1024
file.seek(0, os.SEEK_SET)
file.filename = secure_filename(file.filename)
if file_size_mb < 5:
Copy link

@XiChenn XiChenn Jan 13, 2023

Choose a reason for hiding this comment

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

How about putting the magic number "5" to the configuration (e.g. settings_local.py)? It will not only be easier for future changes, but also the unit test could be beneficial from it (you can configure a much smaller value for the unit test). It will add some one-time complexity for the code deployment. At minimum, we can consider use a const variable.

current_app.config.get('AVATAR_ABSOLUTE')
))
else:
flash(gettext('File must be smaller than 5 MB.'))
Copy link

Choose a reason for hiding this comment

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

Same here for the magic number.

file_size_mb = file.seek(0, os.SEEK_END) / 1024 / 1024
file.seek(0, os.SEEK_SET)
file.filename = secure_filename(file.filename)
if file_size_mb < current_app.config.get('MAX_IMAGE_UPLOAD_SIZE_MB'):
Copy link

@kbecker42 kbecker42 Jan 17, 2023

Choose a reason for hiding this comment

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

It would be a good idea to also include a default value in case a dev does not have this setting. Otherwise, if the setting is missing, the upload will always fail.

current_app.config.get('MAX_IMAGE_UPLOAD_SIZE_MB', 5)

current_app.config.get('AVATAR_ABSOLUTE')
))
else:
flash(gettext('File must be smaller than ' + str(current_app.config.get('MAX_IMAGE_UPLOAD_SIZE_MB')) + ' MB.'))

Choose a reason for hiding this comment

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

current_app.config.get('MAX_IMAGE_UPLOAD_SIZE_MB', 5)

@n00rsy n00rsy marked this pull request as ready for review January 19, 2023 15:27
Copy link

@XiChenn XiChenn left a comment

Choose a reason for hiding this comment

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

great job! Thank you

@n00rsy n00rsy merged commit 9400f8e into main Jan 19, 2023
@XiChenn XiChenn deleted the RDISCROWD-5567-enhance-task-guidelines-images branch February 8, 2023 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants