<s> import unittest2 as unittest <EOL> from mock import Mock , patch <EOL> from flask_views . edit import FormMixin , ProcessFormMixin <EOL> class FormMixinTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_initial ( self ) : <EOL> """<STR_LIT>""" <EOL> mixin = FormMixin ( ) <EOL> mixin . initial = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } <EOL> self . assertEqual ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , mixin . get_initial ( ) ) <EOL> def test_get_success_url ( self ) : <EOL> """<STR_LIT>""" <EOL> mixin = FormMixin ( ) <EOL> mixin . success_url = '<STR_LIT>' <EOL> self . assertEqual ( '<STR_LIT>' , mixin . get_success_url ( ) ) <EOL> def test_get_context_data ( self ) : <EOL> """<STR_LIT>""" <EOL> mixin = FormMixin ( ) <EOL> self . assertEqual ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , mixin . get_context_data ( foo = '<STR_LIT:bar>' ) ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_get_form_kwargs ( self , request ) : <EOL> """<STR_LIT>""" <EOL> request . form = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } <EOL> mixin = FormMixin ( ) <EOL> mixin . get_initial = Mock ( return_value = { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( { <EOL> '<STR_LIT>' : { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> } , mixin . get_form_kwargs ( ) ) <EOL> mixin . get_initial . assert_called_once_with ( ) <EOL> def test_get_form ( self ) : <EOL> """<STR_LIT>""" <EOL> mixin = FormMixin ( ) <EOL> mixin . form_class = Mock ( return_value = '<STR_LIT>' ) <EOL> mixin . get_form_kwargs = Mock ( return_value = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> self . assertEqual ( '<STR_LIT>' , mixin . get_form ( ) ) <EOL> mixin . get_form_kwargs . assert_called_once_with ( ) <EOL> mixin . form_class . assert_called_once_with ( foo = '<STR_LIT:bar>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_form_valid ( self , redirect ) : <EOL> """<STR_LIT>""" <EOL> redirect . return_value = '<STR_LIT>' <EOL> mixin = FormMixin ( ) <EOL> mixin . get_success_url = Mock ( return_value = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , mixin . form_valid ( Mock ( ) ) ) <EOL> redirect . assert_called_once_with ( '<STR_LIT>' ) <EOL> def test_form_invalid ( self ) : <EOL> """<STR_LIT>""" <EOL> mixin = FormMixin ( ) <EOL> mixin . get_context_data = Mock ( return_value = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> mixin . render_to_response = Mock ( return_value = '<STR_LIT>' ) <EOL> form_mock = Mock ( ) <EOL> self . assertEqual ( '<STR_LIT>' , mixin . form_invalid ( form = form_mock ) ) <EOL> mixin . get_context_data . assert_called_once_with ( form = form_mock ) <EOL> mixin . render_to_response . assert_called_once_with ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> class ProcessFormMixinTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_get ( self ) : <EOL> """<STR_LIT>""" <EOL> mixin = ProcessFormMixin ( ) <EOL> mixin . get_form = Mock ( return_value = '<STR_LIT>' ) <EOL> mixin . get_context_data = Mock ( return_value = { '<STR_LIT>' : '<STR_LIT:data>' } ) <EOL> mixin . render_to_response = Mock ( return_value = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , mixin . get ( ) ) <EOL> mixin . get_context_data . assert_called_once_with ( form = '<STR_LIT>' ) <EOL> mixin . render_to_response . assert_called_once_with ( { '<STR_LIT>' : '<STR_LIT:data>' } ) <EOL> def test_post_form_valid ( self ) : <EOL> """<STR_LIT>""" <EOL> form_instance = Mock ( ) <EOL> form_instance . validate . return_value = True <EOL> mixin = ProcessFormMixin ( ) <EOL> mixin . get_form = Mock ( return_value = form_instance ) <EOL> mixin . form_valid = Mock ( return_value = '<STR_LIT>' ) <EOL> mixin . form_invalid = Mock ( return_value = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , mixin . post ( ) ) <EOL> form_instance . validate . assert_called_once_with ( ) <EOL> mixin . form_valid . assert_called_once_with ( form_instance ) <EOL> self . assertEqual ( <NUM_LIT:0> , mixin . form_invalid . call_count ) <EOL> def test_post_form_invalid ( self ) : <EOL> """<STR_LIT>""" <EOL> form_instance = Mock ( ) <EOL> form_instance . validate . return_value = False <EOL> mixin = ProcessFormMixin ( ) <EOL> mixin . get_form = Mock ( return_value = form_instance ) <EOL> mixin . form_valid = Mock ( return_value = '<STR_LIT>' ) <EOL> mixin . form_invalid = Mock ( return_value = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , mixin . post ( ) ) <EOL> form_instance . validate . assert_called_once_with ( ) <EOL> mixin . form_invalid . assert_called_once_with ( form_instance ) <EOL> self . assertEqual ( <NUM_LIT:0> , mixin . form_valid . call_count ) </s>
