<s> from __future__ import unicode_literals <EOL> from django . core . urlresolvers import reverse <EOL> from django . http import QueryDict <EOL> from django . test import TestCase <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . formtools . wizard . views import ( NamedUrlSessionWizardView , <EOL> NamedUrlCookieWizardView ) <EOL> from django . contrib . formtools . tests . wizard . forms import get_request , Step1 , Step2 <EOL> class NamedWizardTests ( object ) : <EOL> urls = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> self . testuser , created = User . objects . get_or_create ( username = '<STR_LIT>' ) <EOL> self . wizard_step_data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] = self . testuser . pk <EOL> def test_initial_call ( self ) : <EOL> response = self . client . get ( reverse ( '<STR_LIT>' % self . wizard_urlname ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> wizard = response . context [ '<STR_LIT>' ] <EOL> self . assertEqual ( wizard [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> self . assertEqual ( wizard [ '<STR_LIT>' ] . step0 , <NUM_LIT:0> ) <EOL> self . assertEqual ( wizard [ '<STR_LIT>' ] . step1 , <NUM_LIT:1> ) <EOL> self . assertEqual ( wizard [ '<STR_LIT>' ] . last , '<STR_LIT>' ) <EOL> self . assertEqual ( wizard [ '<STR_LIT>' ] . prev , None ) <EOL> self . assertEqual ( wizard [ '<STR_LIT>' ] . next , '<STR_LIT>' ) <EOL> self . assertEqual ( wizard [ '<STR_LIT>' ] . count , <NUM_LIT:4> ) <EOL> self . assertEqual ( wizard [ '<STR_LIT>' ] , self . wizard_urlname ) <EOL> def test_initial_call_with_params ( self ) : <EOL> get_params = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> response = self . client . get ( reverse ( '<STR_LIT>' % self . wizard_urlname ) , <EOL> get_params ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> location = response [ '<STR_LIT>' ] <EOL> self . assertNotEqual ( location . find ( '<STR_LIT:?>' ) , - <NUM_LIT:1> ) <EOL> querydict = QueryDict ( location [ location . find ( '<STR_LIT:?>' ) + <NUM_LIT:1> : ] ) <EOL> self . assertEqual ( dict ( querydict . items ( ) ) , get_params ) <EOL> def test_form_post_error ( self ) : <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> self . wizard_step_1_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . errors , <EOL> { '<STR_LIT:name>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT:user>' : [ '<STR_LIT>' ] } ) <EOL> def test_form_post_success ( self ) : <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> self . wizard_step_data [ <NUM_LIT:0> ] ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> wizard = response . context [ '<STR_LIT>' ] <EOL> self . assertEqual ( wizard [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> self . assertEqual ( wizard [ '<STR_LIT>' ] . step0 , <NUM_LIT:1> ) <EOL> self . assertEqual ( wizard [ '<STR_LIT>' ] . prev , '<STR_LIT>' ) <EOL> self . assertEqual ( wizard [ '<STR_LIT>' ] . next , '<STR_LIT>' ) <EOL> def test_form_stepback ( self ) : <EOL> response = self . client . get ( <EOL> reverse ( self . wizard_urlname , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> self . wizard_step_data [ <NUM_LIT:0> ] ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , kwargs = { <EOL> '<STR_LIT>' : response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current <EOL> } ) , { '<STR_LIT>' : response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . prev } ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> def test_form_jump ( self ) : <EOL> response = self . client . get ( <EOL> reverse ( self . wizard_urlname , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> response = self . client . get ( <EOL> reverse ( self . wizard_urlname , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> def test_form_finish ( self ) : <EOL> response = self . client . get ( <EOL> reverse ( self . wizard_urlname , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , <EOL> kwargs = { '<STR_LIT>' : response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current } ) , <EOL> self . wizard_step_data [ <NUM_LIT:0> ] ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> post_data = self . wizard_step_data [ <NUM_LIT:1> ] <EOL> post_data [ '<STR_LIT>' ] . close ( ) <EOL> post_data [ '<STR_LIT>' ] = open ( __file__ , '<STR_LIT:rb>' ) <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , <EOL> kwargs = { '<STR_LIT>' : response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current } ) , <EOL> post_data ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , <EOL> kwargs = { '<STR_LIT>' : response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current } ) , <EOL> self . wizard_step_data [ <NUM_LIT:2> ] ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , <EOL> kwargs = { '<STR_LIT>' : response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current } ) , <EOL> self . wizard_step_data [ <NUM_LIT:3> ] ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> all_data = response . context [ '<STR_LIT>' ] <EOL> with open ( __file__ , '<STR_LIT:rb>' ) as f : <EOL> self . assertEqual ( all_data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] . read ( ) , f . read ( ) ) <EOL> all_data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] . close ( ) <EOL> del all_data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] <EOL> self . assertEqual ( all_data , [ <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : True , '<STR_LIT:user>' : self . testuser } , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> [ { '<STR_LIT>' : '<STR_LIT>' } , { '<STR_LIT>' : '<STR_LIT>' } ] ] ) <EOL> def test_cleaned_data ( self ) : <EOL> response = self . client . get ( <EOL> reverse ( self . wizard_urlname , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , <EOL> kwargs = { '<STR_LIT>' : response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current } ) , <EOL> self . wizard_step_data [ <NUM_LIT:0> ] ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> post_data = self . wizard_step_data [ <NUM_LIT:1> ] <EOL> post_data [ '<STR_LIT>' ] = open ( __file__ , '<STR_LIT:rb>' ) <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , <EOL> kwargs = { '<STR_LIT>' : response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current } ) , <EOL> post_data ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> step2_url = reverse ( self . wizard_urlname , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> response = self . client . get ( step2_url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> with open ( __file__ , '<STR_LIT:rb>' ) as f : <EOL> self . assertEqual ( <EOL> response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . files [ '<STR_LIT>' ] . read ( ) , <EOL> f . read ( ) ) <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , <EOL> kwargs = { '<STR_LIT>' : response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current } ) , <EOL> self . wizard_step_data [ <NUM_LIT:2> ] ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , <EOL> kwargs = { '<STR_LIT>' : response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current } ) , <EOL> self . wizard_step_data [ <NUM_LIT:3> ] ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> all_data = response . context [ '<STR_LIT>' ] <EOL> with open ( __file__ , '<STR_LIT:rb>' ) as f : <EOL> self . assertEqual ( all_data [ '<STR_LIT>' ] . read ( ) , f . read ( ) ) <EOL> all_data [ '<STR_LIT>' ] . close ( ) <EOL> del all_data [ '<STR_LIT>' ] <EOL> self . assertEqual ( <EOL> all_data , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : True , '<STR_LIT:user>' : self . testuser , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : [ <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' } <EOL> ] } ) <EOL> def test_manipulated_data ( self ) : <EOL> response = self . client . get ( <EOL> reverse ( self . wizard_urlname , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , <EOL> kwargs = { '<STR_LIT>' : response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current } ) , <EOL> self . wizard_step_data [ <NUM_LIT:0> ] ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> post_data = self . wizard_step_data [ <NUM_LIT:1> ] <EOL> post_data [ '<STR_LIT>' ] . close ( ) <EOL> post_data [ '<STR_LIT>' ] = open ( __file__ , '<STR_LIT:rb>' ) <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , <EOL> kwargs = { '<STR_LIT>' : response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current } ) , <EOL> post_data ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , <EOL> kwargs = { '<STR_LIT>' : response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current } ) , <EOL> self . wizard_step_data [ <NUM_LIT:2> ] ) <EOL> loc = response [ '<STR_LIT>' ] <EOL> response = self . client . get ( loc ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> , loc ) <EOL> self . client . cookies . pop ( '<STR_LIT>' , None ) <EOL> self . client . cookies . pop ( '<STR_LIT>' , None ) <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , <EOL> kwargs = { '<STR_LIT>' : response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current } ) , <EOL> self . wizard_step_data [ <NUM_LIT:3> ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> def test_form_reset ( self ) : <EOL> response = self . client . post ( <EOL> reverse ( self . wizard_urlname , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> self . wizard_step_data [ <NUM_LIT:0> ] ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> response = self . client . get ( <EOL> '<STR_LIT>' % reverse ( '<STR_LIT>' % self . wizard_urlname ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> response = self . client . get ( response [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . current , '<STR_LIT>' ) <EOL> class NamedSessionWizardTests ( NamedWizardTests , TestCase ) : <EOL> wizard_urlname = '<STR_LIT>' <EOL> wizard_step_1_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> wizard_step_data = ( <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> ) <EOL> class NamedCookieWizardTests ( NamedWizardTests , TestCase ) : <EOL> wizard_urlname = '<STR_LIT>' <EOL> wizard_step_1_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> wizard_step_data = ( <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> ) <EOL> class NamedFormTests ( object ) : <EOL> urls = '<STR_LIT>' <EOL> def test_revalidation ( self ) : <EOL> request = get_request ( ) <EOL> testform = self . formwizard_class . as_view ( <EOL> [ ( '<STR_LIT:start>' , Step1 ) , ( '<STR_LIT>' , Step2 ) ] , <EOL> url_name = self . wizard_urlname ) <EOL> response , instance = testform ( request , step = '<STR_LIT>' ) <EOL> instance . render_done ( None ) <EOL> self . assertEqual ( instance . storage . current_step , '<STR_LIT:start>' ) <EOL> class TestNamedUrlSessionWizardView ( NamedUrlSessionWizardView ) : <EOL> def dispatch ( self , request , * args , ** kwargs ) : <EOL> response = super ( TestNamedUrlSessionWizardView , self ) . dispatch ( request , * args , ** kwargs ) <EOL> return response , self <EOL> class TestNamedUrlCookieWizardView ( NamedUrlCookieWizardView ) : <EOL> def dispatch ( self , request , * args , ** kwargs ) : <EOL> response = super ( TestNamedUrlCookieWizardView , self ) . dispatch ( request , * args , ** kwargs ) <EOL> return response , self <EOL> class NamedSessionFormTests ( NamedFormTests , TestCase ) : <EOL> formwizard_class = TestNamedUrlSessionWizardView <EOL> wizard_urlname = '<STR_LIT>' <EOL> class NamedCookieFormTests ( NamedFormTests , TestCase ) : <EOL> formwizard_class = TestNamedUrlCookieWizardView <EOL> wizard_urlname = '<STR_LIT>' </s>
