Pylons / Pylons/webtest

int & files in a form

Open
#81 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
346
Forks
113
PR merge metrics
No merged PRs in 30d

Description

The integer on a field don't seem to work when a file is uploaded. I was using django-webtest but the crash occurs in webtest and it seems to be the source of that small bug:

copied from here: https://github.com/kmike/django-webtest/issues/18

I used to have a form like this with the test passing:
form = response.form
form['structure-total_number_of_employees'] = 50
...
response = form.submit()

Then when I've added a file to that and updated my code:
form = response.form
form['logo'] = ...
form['structure-total_number_of_employees'] = 50
...
response = form.submit()

It crashed with the following error:
virtual_env/dev_env/lib/python2.7/site-packages/webtest/app.py", line 382, in encode_multipart
body = b'\r\n'.join(lines)
TypeError: sequence item 12: expected string, int found

To get it to work, I've replaced 50 by "50":
form = response.form
form['logo'] = ...
form['structure-total_number_of_employees'] = "50"
...
response = form.submit()

I reckon that the encode multipart should be updated to handle integers.

Thanks !

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in webtest/app.py at encode_multipart and reproduce the form submission described with an uploaded file and an integer field. Confirm that multipart encoding handles the integer without the reported TypeError, and add or update coverage for this case if the repository has a relevant test location.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.