<s> from __future__ import with_statement <EOL> from flask import Flask , render_template , jsonify <EOL> from wtforms import StringField , HiddenField , SubmitField <EOL> from wtforms . validators import DataRequired <EOL> from flask_wtf import Form <EOL> from flask_wtf . _compat import text_type <EOL> def to_unicode ( text ) : <EOL> if not isinstance ( text , text_type ) : <EOL> return text . decode ( '<STR_LIT:utf-8>' ) <EOL> return text <EOL> class MyForm ( Form ) : <EOL> SECRET_KEY = "<STR_LIT>" <EOL> name = StringField ( "<STR_LIT:Name>" , validators = [ DataRequired ( ) ] ) <EOL> submit = SubmitField ( "<STR_LIT>" ) <EOL> class HiddenFieldsForm ( Form ) : <EOL> SECRET_KEY = "<STR_LIT>" <EOL> name = HiddenField ( ) <EOL> url = HiddenField ( ) <EOL> method = HiddenField ( ) <EOL> secret = HiddenField ( ) <EOL> submit = SubmitField ( "<STR_LIT>" ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( HiddenFieldsForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . method . name = '<STR_LIT>' <EOL> class SimpleForm ( Form ) : <EOL> SECRET_KEY = "<STR_LIT>" <EOL> pass <EOL> class TestCase ( object ) : <EOL> def setUp ( self ) : <EOL> self . app = self . create_app ( ) <EOL> self . client = self . app . test_client ( ) <EOL> def create_app ( self ) : <EOL> app = Flask ( __name__ ) <EOL> app . secret_key = "<STR_LIT>" <EOL> @ app . route ( "<STR_LIT:/>" , methods = ( "<STR_LIT:GET>" , "<STR_LIT:POST>" ) ) <EOL> def index ( ) : <EOL> form = MyForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> name = form . name . data . upper ( ) <EOL> else : <EOL> name = '<STR_LIT>' <EOL> return render_template ( "<STR_LIT>" , <EOL> form = form , <EOL> name = name ) <EOL> @ app . route ( "<STR_LIT>" , methods = ( "<STR_LIT:POST>" , ) ) <EOL> def simple ( ) : <EOL> form = SimpleForm ( ) <EOL> form . validate ( ) <EOL> assert form . csrf_enabled <EOL> assert not form . validate ( ) <EOL> return "<STR_LIT:OK>" <EOL> @ app . route ( "<STR_LIT>" , methods = ( "<STR_LIT:POST>" , ) ) <EOL> def two_forms ( ) : <EOL> form = SimpleForm ( ) <EOL> assert form . csrf_enabled <EOL> assert form . validate ( ) <EOL> assert form . validate ( ) <EOL> form2 = SimpleForm ( ) <EOL> assert form2 . csrf_enabled <EOL> assert form2 . validate ( ) <EOL> return "<STR_LIT:OK>" <EOL> @ app . route ( "<STR_LIT>" ) <EOL> def hidden ( ) : <EOL> form = HiddenFieldsForm ( ) <EOL> return render_template ( "<STR_LIT>" , form = form ) <EOL> @ app . route ( "<STR_LIT>" , methods = ( "<STR_LIT:POST>" , ) ) <EOL> def ajax_submit ( ) : <EOL> form = MyForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> return jsonify ( name = form . name . data , <EOL> success = True , <EOL> errors = None ) <EOL> return jsonify ( name = None , <EOL> success = False ) <EOL> return app </s>
