Skip to content

Commit

Permalink
Update test and changlog for enctype fix
Browse files Browse the repository at this point in the history
  • Loading branch information
greyli committed Apr 21, 2020
1 parent 596005b commit 5b0cc76
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
==========

1.3.0
------

- Fix ``enctype`` attribute setting for WTForms ``MultipleFileField``.

1.2.0
------

Expand Down
34 changes: 33 additions & 1 deletion test_bootstrap_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from flask import Flask, render_template_string, current_app, request, flash
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, BooleanField, PasswordField
from wtforms import StringField, SubmitField, BooleanField, PasswordField, FileField, MultipleFileField
from wtforms.validators import DataRequired, Length

from flask_bootstrap import Bootstrap
Expand Down Expand Up @@ -328,3 +328,35 @@ def test_dismiss_animate():
self.assertIn('alert-dismissible', data)
self.assertIn('<button type="button" class="close" data-dismiss="alert"', data)
self.assertIn('fade show', data)

# test WTForm fields for render_form and render_field
def test_render_form_enctype(self):
class SingleUploadForm(FlaskForm):
avatar = FileField('Avatar')

class MultiUploadForm(FlaskForm):
photos = MultipleFileField('Multiple photos')

@self.app.route('/single')
def single():
form = SingleUploadForm()
return render_template_string('''
{% from 'bootstrap/form.html' import render_form %}
{{ render_form(form) }}
''', form=form)

@self.app.route('/multi')
def multi():
form = SingleUploadForm()
return render_template_string('''
{% from 'bootstrap/form.html' import render_form %}
{{ render_form(form) }}
''', form=form)

response = self.client.get('/single')
data = response.get_data(as_text=True)
self.assertIn('multipart/form-data', data)

response = self.client.get('/multi')
data = response.get_data(as_text=True)
self.assertIn('multipart/form-data', data)

0 comments on commit 5b0cc76

Please sign in to comment.