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
int & files in a form #81
Comments
Form values are always string. It should not work with an integer. Same with other python types (eg: datetime, float, etc.). |
Good point - it could be improved with some checking and clear exception for incorrect type (anything but string). Especially since it's working if no file is uploaded while it shouldn't. |
API-wise, what's wrong with passing integers to Webtest? Not supporting datetimes can prevent errors because there are many ways to convert datetime to string, and it is better to be explicit here. Same with floats (e.g. decimal point vs comma). But I don't see how not supporting integer values could prevent errors. If user sets So +1 for auto-converting integers to strings, because this use case is quite common. |
I'm +0. Because if you expect that form.field = 3 work you can expect that form.field == 3 work too. But this will require much more magic. |
Anyone want to provide a pull request ? If not I'll close this issue. |
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: django-webtest/django-webtest#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 !
The text was updated successfully, but these errors were encountered: