<s> import unittest <EOL> from django import forms <EOL> from django . conf import settings <EOL> from django . contrib . formtools import preview , wizard , utils <EOL> from django import http <EOL> from django . test import TestCase <EOL> success_string = "<STR_LIT>" <EOL> class TestFormPreview ( preview . FormPreview ) : <EOL> def done ( self , request , cleaned_data ) : <EOL> return http . HttpResponse ( success_string ) <EOL> class TestForm ( forms . Form ) : <EOL> field1 = forms . CharField ( ) <EOL> field1_ = forms . CharField ( ) <EOL> bool1 = forms . BooleanField ( required = False ) <EOL> class PreviewTests ( TestCase ) : <EOL> urls = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> self . preview = preview . FormPreview ( TestForm ) <EOL> input_template = '<STR_LIT>' <EOL> self . input = input_template % ( self . preview . unused_name ( '<STR_LIT>' ) , "<STR_LIT>" ) <EOL> self . test_data = { '<STR_LIT>' : u'<STR_LIT:foo>' , '<STR_LIT>' : u'<STR_LIT>' } <EOL> def test_unused_name ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . preview . unused_name ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_form_get ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> stage = self . input % <NUM_LIT:1> <EOL> self . assertContains ( response , stage , <NUM_LIT:1> ) <EOL> def test_form_preview ( self ) : <EOL> """<STR_LIT>""" <EOL> self . test_data . update ( { '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> response = self . client . post ( '<STR_LIT>' , self . test_data ) <EOL> stage = self . input % <NUM_LIT:2> <EOL> self . assertContains ( response , stage , <NUM_LIT:1> ) <EOL> def test_form_submit ( self ) : <EOL> """<STR_LIT>""" <EOL> self . test_data . update ( { '<STR_LIT>' : <NUM_LIT:2> } ) <EOL> response = self . client . post ( '<STR_LIT>' , self . test_data ) <EOL> self . failIfEqual ( response . content , success_string ) <EOL> hash = self . preview . security_hash ( None , TestForm ( self . test_data ) ) <EOL> self . test_data . update ( { '<STR_LIT>' : hash } ) <EOL> response = self . client . post ( '<STR_LIT>' , self . test_data ) <EOL> self . assertEqual ( response . content , success_string ) <EOL> def test_bool_submit ( self ) : <EOL> """<STR_LIT>""" <EOL> self . test_data . update ( { '<STR_LIT>' : <NUM_LIT:2> } ) <EOL> hash = self . preview . security_hash ( None , TestForm ( self . test_data ) ) <EOL> self . test_data . update ( { '<STR_LIT>' : hash , '<STR_LIT>' : u'<STR_LIT:False>' } ) <EOL> response = self . client . post ( '<STR_LIT>' , self . test_data ) <EOL> self . assertEqual ( response . content , success_string ) <EOL> class SecurityHashTests ( unittest . TestCase ) : <EOL> def test_textfield_hash ( self ) : <EOL> """<STR_LIT>""" <EOL> f1 = HashTestForm ( { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> f2 = HashTestForm ( { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> hash1 = utils . security_hash ( None , f1 ) <EOL> hash2 = utils . security_hash ( None , f2 ) <EOL> self . assertEqual ( hash1 , hash2 ) <EOL> def test_empty_permitted ( self ) : <EOL> """<STR_LIT>""" <EOL> f1 = HashTestBlankForm ( { } ) <EOL> f2 = HashTestForm ( { } , empty_permitted = True ) <EOL> hash1 = utils . security_hash ( None , f1 ) <EOL> hash2 = utils . security_hash ( None , f2 ) <EOL> self . assertEqual ( hash1 , hash2 ) <EOL> class HashTestForm ( forms . Form ) : <EOL> name = forms . CharField ( ) <EOL> bio = forms . CharField ( ) <EOL> class HashTestBlankForm ( forms . Form ) : <EOL> name = forms . CharField ( required = False ) <EOL> bio = forms . CharField ( required = False ) <EOL> class WizardPageOneForm ( forms . Form ) : <EOL> field = forms . CharField ( ) <EOL> class WizardPageTwoForm ( forms . Form ) : <EOL> field = forms . CharField ( ) <EOL> class WizardPageTwoAlternativeForm ( forms . Form ) : <EOL> field = forms . CharField ( ) <EOL> class WizardPageThreeForm ( forms . Form ) : <EOL> field = forms . CharField ( ) <EOL> class WizardClass ( wizard . FormWizard ) : <EOL> def render_template ( self , * args , ** kw ) : <EOL> return http . HttpResponse ( "<STR_LIT>" ) <EOL> def done ( self , request , cleaned_data ) : <EOL> return http . HttpResponse ( success_string ) <EOL> class DummyRequest ( http . HttpRequest ) : <EOL> def __init__ ( self , POST = None ) : <EOL> super ( DummyRequest , self ) . __init__ ( ) <EOL> self . method = POST and "<STR_LIT:POST>" or "<STR_LIT:GET>" <EOL> if POST is not None : <EOL> self . POST . update ( POST ) <EOL> self . _dont_enforce_csrf_checks = True <EOL> class WizardTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . old_SECRET_KEY = settings . SECRET_KEY <EOL> settings . SECRET_KEY = "<STR_LIT>" <EOL> def tearDown ( self ) : <EOL> settings . SECRET_KEY = self . old_SECRET_KEY <EOL> def test_step_starts_at_zero ( self ) : <EOL> """<STR_LIT>""" <EOL> wizard = WizardClass ( [ WizardPageOneForm , WizardPageTwoForm ] ) <EOL> request = DummyRequest ( ) <EOL> wizard ( request ) <EOL> self . assertEquals ( <NUM_LIT:0> , wizard . step ) <EOL> def test_step_increments ( self ) : <EOL> """<STR_LIT>""" <EOL> wizard = WizardClass ( [ WizardPageOneForm , WizardPageTwoForm ] ) <EOL> request = DummyRequest ( POST = { "<STR_LIT>" : "<STR_LIT:test>" , "<STR_LIT>" : "<STR_LIT:0>" } ) <EOL> response = wizard ( request ) <EOL> self . assertEquals ( <NUM_LIT:1> , wizard . step ) <EOL> def test_14498 ( self ) : <EOL> """<STR_LIT>""" <EOL> that = self <EOL> reached = [ False ] <EOL> class WizardWithProcessStep ( WizardClass ) : <EOL> def process_step ( self , request , form , step ) : <EOL> reached [ <NUM_LIT:0> ] = True <EOL> that . assertTrue ( hasattr ( form , '<STR_LIT>' ) ) <EOL> wizard = WizardWithProcessStep ( [ WizardPageOneForm , <EOL> WizardPageTwoForm , <EOL> WizardPageThreeForm ] ) <EOL> data = { "<STR_LIT>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:1>" } <EOL> wizard ( DummyRequest ( POST = data ) ) <EOL> self . assertTrue ( reached [ <NUM_LIT:0> ] ) <EOL> def test_14576 ( self ) : <EOL> """<STR_LIT>""" <EOL> reached = [ False ] <EOL> that = self <EOL> class Wizard ( WizardClass ) : <EOL> def done ( self , request , form_list ) : <EOL> reached [ <NUM_LIT:0> ] = True <EOL> that . assertTrue ( len ( form_list ) == <NUM_LIT:2> ) <EOL> wizard = Wizard ( [ WizardPageOneForm , <EOL> WizardPageTwoForm ] ) <EOL> data = { "<STR_LIT>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:1>" } <EOL> wizard ( DummyRequest ( POST = data ) ) <EOL> self . assertTrue ( reached [ <NUM_LIT:0> ] ) <EOL> def test_15075 ( self ) : <EOL> """<STR_LIT>""" <EOL> reached = [ False ] <EOL> that = self <EOL> class WizardWithProcessStep ( WizardClass ) : <EOL> def process_step ( self , request , form , step ) : <EOL> if step == <NUM_LIT:0> : <EOL> self . form_list [ <NUM_LIT:1> ] = WizardPageTwoAlternativeForm <EOL> if step == <NUM_LIT:1> : <EOL> that . assertTrue ( isinstance ( form , WizardPageTwoAlternativeForm ) ) <EOL> reached [ <NUM_LIT:0> ] = True <EOL> wizard = WizardWithProcessStep ( [ WizardPageOneForm , <EOL> WizardPageTwoForm , <EOL> WizardPageThreeForm ] ) <EOL> data = { "<STR_LIT>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:1>" } <EOL> wizard ( DummyRequest ( POST = data ) ) <EOL> self . assertTrue ( reached [ <NUM_LIT:0> ] ) </s>
