<s> import os <EOL> import unittest <EOL> import shutil <EOL> import tempfile <EOL> import types <EOL> from mock import patch <EOL> from mock import Mock <EOL> from pyramid import testing <EOL> from pyramid . exceptions import ConfigurationError <EOL> class TestFormView ( unittest . TestCase ) : <EOL> def _getTargetClass ( self ) : <EOL> from pyramid_deform import FormView <EOL> return FormView <EOL> def _makeOne ( self , request ) : <EOL> klass = self . _getTargetClass ( ) <EOL> inst = klass ( request ) <EOL> return inst <EOL> def test___call__show ( self ) : <EOL> schema = DummySchema ( ) <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> inst . schema = schema <EOL> inst . form_class = DummyForm <EOL> result = inst ( ) <EOL> self . assertEqual ( result , { '<STR_LIT>' : ( ) , '<STR_LIT>' : ( ) , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test___call__show_with_appstruct ( self ) : <EOL> schema = DummySchema ( ) <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> inst . schema = schema <EOL> inst . form_class = DummyForm <EOL> inst . appstruct = lambda : { '<STR_LIT>' : '<STR_LIT>' } <EOL> result = inst ( ) <EOL> self . assertEqual ( result , { '<STR_LIT>' : ( ) , '<STR_LIT>' : ( ) , <EOL> '<STR_LIT>' : "<STR_LIT>" } ) <EOL> def test___call__show_result_response ( self ) : <EOL> from webob import Response <EOL> schema = DummySchema ( ) <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> inst . schema = schema <EOL> inst . form_class = DummyForm <EOL> response = Response ( ) <EOL> inst . show = lambda * arg : response <EOL> result = inst ( ) <EOL> self . assertEqual ( result , response ) <EOL> def test___call__button_in_request ( self ) : <EOL> schema = DummySchema ( ) <EOL> request = DummyRequest ( ) <EOL> request . POST [ '<STR_LIT>' ] = True <EOL> inst = self . _makeOne ( request ) <EOL> inst . schema = schema <EOL> inst . buttons = ( DummyButton ( '<STR_LIT>' ) , ) <EOL> inst . submit_success = lambda * x : '<STR_LIT:success>' <EOL> inst . form_class = DummyForm <EOL> result = inst ( ) <EOL> self . assertEqual ( result , '<STR_LIT:success>' ) <EOL> def test___call__button_in_request_fail ( self ) : <EOL> schema = DummySchema ( ) <EOL> request = DummyRequest ( ) <EOL> request . POST [ '<STR_LIT>' ] = True <EOL> inst = self . _makeOne ( request ) <EOL> inst . schema = schema <EOL> inst . buttons = ( DummyButton ( '<STR_LIT>' ) , ) <EOL> import deform . exception <EOL> def raiseit ( * arg ) : <EOL> raise deform . exception . ValidationFailure ( None , None , None ) <EOL> inst . submit_success = raiseit <EOL> inst . form_class = DummyForm <EOL> inst . submit_failure = lambda * arg : '<STR_LIT>' <EOL> result = inst ( ) <EOL> self . assertEqual ( result , '<STR_LIT>' ) <EOL> def test___call__button_in_request_fail_no_failure_handler ( self ) : <EOL> schema = DummySchema ( ) <EOL> request = DummyRequest ( ) <EOL> request . POST [ '<STR_LIT>' ] = True <EOL> inst = self . _makeOne ( request ) <EOL> inst . schema = schema <EOL> inst . buttons = ( DummyButton ( '<STR_LIT>' ) , ) <EOL> import deform . exception <EOL> def raiseit ( * arg ) : <EOL> exc = deform . exception . ValidationFailure ( None , None , None ) <EOL> exc . render = lambda * arg : '<STR_LIT>' <EOL> raise exc <EOL> inst . submit_success = raiseit <EOL> inst . form_class = DummyForm <EOL> result = inst ( ) <EOL> self . assertEqual ( result , <EOL> { '<STR_LIT>' : ( ) , '<STR_LIT>' : ( ) , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_get_bind_data_contains_request ( self ) : <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> data = inst . get_bind_data ( ) <EOL> self . assertTrue ( '<STR_LIT>' in data ) <EOL> def test__call__binds_schema_with_get_bind_data ( self ) : <EOL> schema = DummySchema ( ) <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> inst . schema = schema <EOL> inst . form_class = DummyForm <EOL> inst ( ) <EOL> self . assertEqual ( schema . kw , inst . get_bind_data ( ) ) <EOL> def test_form_options_applied ( self ) : <EOL> schema = DummySchema ( ) <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> inst . schema = schema <EOL> inst . form_class = DummyForm <EOL> form_options = ( ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:action>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:GET>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> inst . form_options = form_options <EOL> def check_form ( self , form ) : <EOL> self . form = form <EOL> inst . before = types . MethodType ( check_form , inst ) <EOL> inst ( ) <EOL> form = inst . form <EOL> for key , value in dict ( form_options ) . items ( ) : <EOL> self . assertEqual ( getattr ( form , key ) , value ) <EOL> class TestFormWizardView ( unittest . TestCase ) : <EOL> def _makeOne ( self , wizard ) : <EOL> from pyramid_deform import FormWizardView <EOL> return FormWizardView ( wizard ) <EOL> def test___call__step_zero_no_schemas ( self ) : <EOL> wizard = DummyFormWizard ( ) <EOL> inst = self . _makeOne ( wizard ) <EOL> request = DummyRequest ( ) <EOL> result = inst ( request ) <EOL> self . assertEqual ( result , '<STR_LIT>' ) <EOL> def test___call__step_zero_one_schema ( self ) : <EOL> schema = DummySchema ( ) <EOL> wizard = DummyFormWizard ( schema ) <EOL> inst = self . _makeOne ( wizard ) <EOL> inst . form_view_class = DummyFormView <EOL> request = DummyRequest ( ) <EOL> result = inst ( request ) <EOL> self . assertEqual ( result , '<STR_LIT>' ) <EOL> def test___call__prev_not_ok ( self ) : <EOL> schema = DummySchema ( ) <EOL> schema . prev_ok = lambda * arg : False <EOL> wizard = DummyFormWizard ( schema ) <EOL> inst = self . _makeOne ( wizard ) <EOL> inst . form_view_class = DummyFormView <EOL> request = DummyRequest ( ) <EOL> result = inst ( request ) <EOL> self . assertEqual ( result , '<STR_LIT>' ) <EOL> def test___call__next_not_ok ( self ) : <EOL> schema = DummySchema ( ) <EOL> schema . next_ok = lambda * arg : False <EOL> wizard = DummyFormWizard ( schema ) <EOL> inst = self . _makeOne ( wizard ) <EOL> inst . form_view_class = DummyFormView <EOL> request = DummyRequest ( ) <EOL> result = inst ( request ) <EOL> self . assertEqual ( result , '<STR_LIT>' ) <EOL> def test_show ( self ) : <EOL> from pyramid_deform import WizardState <EOL> form = DummyForm ( None ) <EOL> wizard = DummyFormWizard ( ) <EOL> inst = self . _makeOne ( wizard ) <EOL> request = DummyRequest ( ) <EOL> inst . request = request <EOL> inst . wizard_state = WizardState ( request , '<STR_LIT:name>' ) <EOL> result = inst . show ( form ) <EOL> self . assertEqual ( result , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( form . appstruct , { } ) <EOL> def test_show_with_appstruct ( self ) : <EOL> from pyramid_deform import WizardState <EOL> form = DummyForm ( None ) <EOL> wizard = DummyFormWizard ( ) <EOL> inst = self . _makeOne ( wizard ) <EOL> class DummySchemaWithAppstruct ( object ) : <EOL> appstruct = { '<STR_LIT:1>' : '<STR_LIT:2>' } <EOL> inst . schema = DummySchemaWithAppstruct ( ) <EOL> request = DummyRequest ( ) <EOL> inst . request = request <EOL> inst . wizard_state = WizardState ( request , '<STR_LIT:name>' ) <EOL> result = inst . show ( form ) <EOL> self . assertEqual ( result , { '<STR_LIT>' : "<STR_LIT>" } ) <EOL> self . assertEqual ( form . appstruct , { '<STR_LIT:1>' : '<STR_LIT:2>' } ) <EOL> def test_show_with_deserialize ( self ) : <EOL> from pyramid_deform import WizardState <EOL> form = DummyForm ( None ) <EOL> wizard = DummyFormWizard ( ) <EOL> inst = self . _makeOne ( wizard ) <EOL> request = DummyRequest ( ) <EOL> inst . request = request <EOL> inst . schema = DummySchema ( ) <EOL> inst . schema . wizard_serializer = lambda * arg : DummySerializer ( '<STR_LIT>' ) <EOL> inst . wizard_state = WizardState ( request , '<STR_LIT:name>' ) <EOL> result = inst . show ( form ) <EOL> self . assertEqual ( result , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( form . appstruct , '<STR_LIT>' ) <EOL> def test_next_success ( self ) : <EOL> from pyramid_deform import WizardState <EOL> wizard = DummyFormWizard ( ) <EOL> inst = self . _makeOne ( wizard ) <EOL> request = DummyRequest ( ) <EOL> inst . request = request <EOL> inst . wizard_state = WizardState ( request , '<STR_LIT:name>' ) <EOL> inst . schema = DummySchema ( ) <EOL> result = inst . next_success ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( result . status , '<STR_LIT>' ) <EOL> self . assertEqual ( result . location , '<STR_LIT>' ) <EOL> state = request . session [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] <EOL> self . assertEqual ( state [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( state [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( state [ '<STR_LIT>' ] [ '<STR_LIT>' ] , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_next_success_with_serializer ( self ) : <EOL> from pyramid_deform import WizardState <EOL> wizard = DummyFormWizard ( ) <EOL> inst = self . _makeOne ( wizard ) <EOL> request = DummyRequest ( ) <EOL> inst . request = request <EOL> inst . wizard_state = WizardState ( request , '<STR_LIT:name>' ) <EOL> inst . schema = DummySchema ( ) <EOL> inst . schema . wizard_serializer = lambda * arg : DummySerializer ( '<STR_LIT>' ) <EOL> result = inst . next_success ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( result . status , '<STR_LIT>' ) <EOL> self . assertEqual ( result . location , '<STR_LIT>' ) <EOL> state = request . session [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] <EOL> self . assertEqual ( state [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( state [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( state [ '<STR_LIT>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_previous_success_at_step_zero ( self ) : <EOL> from pyramid_deform import WizardState <EOL> wizard = DummyFormWizard ( ) <EOL> inst = self . _makeOne ( wizard ) <EOL> request = DummyRequest ( ) <EOL> inst . request = request <EOL> inst . wizard_state = WizardState ( request , '<STR_LIT:name>' ) <EOL> inst . schema = DummySchema ( ) <EOL> result = inst . previous_success ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( result . status , '<STR_LIT>' ) <EOL> self . assertEqual ( result . location , '<STR_LIT>' ) <EOL> state = request . session [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] <EOL> self . assertEqual ( state [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( state [ '<STR_LIT>' ] [ '<STR_LIT>' ] , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertFalse ( '<STR_LIT>' in state ) <EOL> def test_previous_success_at_step_one ( self ) : <EOL> from pyramid_deform import WizardState <EOL> wizard = DummyFormWizard ( ) <EOL> inst = self . _makeOne ( wizard ) <EOL> request = DummyRequest ( ) <EOL> inst . request = request <EOL> inst . wizard_state = WizardState ( request , '<STR_LIT:name>' ) <EOL> inst . schema = DummySchema ( ) <EOL> states = inst . request . session [ '<STR_LIT>' ] = { } <EOL> states [ '<STR_LIT:name>' ] = { '<STR_LIT>' : <NUM_LIT:1> } <EOL> result = inst . previous_success ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( result . status , '<STR_LIT>' ) <EOL> self . assertEqual ( result . location , '<STR_LIT>' ) <EOL> state = request . session [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] <EOL> self . assertEqual ( state [ '<STR_LIT>' ] [ <NUM_LIT:1> ] , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( state [ '<STR_LIT>' ] [ '<STR_LIT>' ] , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( state [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> def test_previous_success_with_serializer ( self ) : <EOL> from pyramid_deform import WizardState <EOL> wizard = DummyFormWizard ( ) <EOL> inst = self . _makeOne ( wizard ) <EOL> request = DummyRequest ( ) <EOL> inst . request = request <EOL> inst . wizard_state = WizardState ( request , '<STR_LIT:name>' ) <EOL> inst . schema = DummySchema ( ) <EOL> inst . schema . wizard_serializer = lambda * arg : DummySerializer ( '<STR_LIT>' ) <EOL> result = inst . previous_success ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( result . status , '<STR_LIT>' ) <EOL> self . assertEqual ( result . location , '<STR_LIT>' ) <EOL> state = request . session [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] <EOL> self . assertEqual ( state [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( state [ '<STR_LIT>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_previous_failure_at_step_zero ( self ) : <EOL> from pyramid_deform import WizardState <EOL> wizard = DummyFormWizard ( ) <EOL> inst = self . _makeOne ( wizard ) <EOL> request = DummyRequest ( ) <EOL> inst . request = request <EOL> inst . schema = DummySchema ( ) <EOL> inst . wizard_state = WizardState ( request , '<STR_LIT:name>' ) <EOL> result = inst . previous_failure ( None ) <EOL> self . assertEqual ( result . status , '<STR_LIT>' ) <EOL> self . assertEqual ( result . location , '<STR_LIT>' ) <EOL> state = request . session [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] <EOL> self . assertFalse ( '<STR_LIT>' in state ) <EOL> def test_previous_failure_at_step_one ( self ) : <EOL> from pyramid_deform import WizardState <EOL> wizard = DummyFormWizard ( ) <EOL> inst = self . _makeOne ( wizard ) <EOL> request = DummyRequest ( ) <EOL> inst . request = request <EOL> inst . schema = DummySchema ( ) <EOL> inst . wizard_state = WizardState ( request , '<STR_LIT:name>' ) <EOL> states = inst . request . session [ '<STR_LIT>' ] = { } <EOL> states [ '<STR_LIT:name>' ] = { '<STR_LIT>' : <NUM_LIT:1> } <EOL> result = inst . previous_failure ( None ) <EOL> self . assertEqual ( result . status , '<STR_LIT>' ) <EOL> self . assertEqual ( result . location , '<STR_LIT>' ) <EOL> state = request . session [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] <EOL> self . assertEqual ( state [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> def test_get_schema_serializer_no_serializer ( self ) : <EOL> wizard = DummyFormWizard ( ) <EOL> inst = self . _makeOne ( wizard ) <EOL> inst . schema = DummySchema ( ) <EOL> self . assertEqual ( inst . get_schema_serializer ( ) , None ) <EOL> def test_get_schema_serializer ( self ) : <EOL> wizard = DummyFormWizard ( ) <EOL> inst = self . _makeOne ( wizard ) <EOL> inst . schema = DummySchema ( ) <EOL> inst . schema . wizard_serializer = lambda schema : '<STR_LIT>' <EOL> self . assertEqual ( inst . get_schema_serializer ( ) , '<STR_LIT>' ) <EOL> def test_deserialize ( self ) : <EOL> wizard = DummyFormWizard ( ) <EOL> inst = self . _makeOne ( wizard ) <EOL> inst . schema = DummySchema ( ) <EOL> inst . schema . wizard_serializer = lambda * arg : DummySerializer ( '<STR_LIT>' ) <EOL> self . assertEqual ( inst . deserialize ( '<STR_LIT:state>' ) , '<STR_LIT>' ) <EOL> def test_serialize ( self ) : <EOL> wizard = DummyFormWizard ( ) <EOL> inst = self . _makeOne ( wizard ) <EOL> inst . schema = DummySchema ( ) <EOL> inst . schema . wizard_serializer = lambda * arg : DummySerializer ( '<STR_LIT>' ) <EOL> self . assertEqual ( inst . serialize ( '<STR_LIT:state>' ) , '<STR_LIT>' ) <EOL> class TestWizardState ( unittest . TestCase ) : <EOL> def _makeOne ( self , request ) : <EOL> from pyramid_deform import WizardState <EOL> return WizardState ( request , '<STR_LIT:name>' ) <EOL> def test__get_wizard_data_no_existing_data ( self ) : <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> data = inst . _get_wizard_data ( ) <EOL> self . assertEqual ( data , { } ) <EOL> self . assertTrue ( '<STR_LIT:name>' in request . session [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( request . session . _changed ) <EOL> def test__get_wizard_data_with_existing_data ( self ) : <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> state = { '<STR_LIT:abc>' : '<STR_LIT>' } <EOL> states = request . session [ '<STR_LIT>' ] = { } <EOL> states [ '<STR_LIT:name>' ] = state <EOL> inst . request = request <EOL> data = inst . _get_wizard_data ( ) <EOL> self . assertEqual ( data , state ) <EOL> self . assertFalse ( request . session . _changed ) <EOL> def test_clear ( self ) : <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> state = { '<STR_LIT:abc>' : '<STR_LIT>' } <EOL> states = request . session [ '<STR_LIT>' ] = { } <EOL> states [ '<STR_LIT:name>' ] = state <EOL> inst . request = request <EOL> inst . clear ( ) <EOL> self . assertEqual ( request . session [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] , { } ) <EOL> def test_clear_get_step_num_from_params ( self ) : <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> request . GET [ '<STR_LIT>' ] = '<STR_LIT:1>' <EOL> inst . request = request <EOL> self . assertEqual ( inst . get_step_num ( ) , <NUM_LIT:1> ) <EOL> def test_clear_get_step_num_from_session ( self ) : <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> states = request . session [ '<STR_LIT>' ] = { } <EOL> states [ '<STR_LIT:name>' ] = { '<STR_LIT>' : '<STR_LIT:1>' } <EOL> inst . request = request <EOL> self . assertEqual ( inst . get_step_num ( ) , <NUM_LIT:1> ) <EOL> def test_set_step_num ( self ) : <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> inst . request = request <EOL> inst . set_step_num ( <NUM_LIT:5> ) <EOL> self . assertEqual ( inst . get_step_num ( ) , <NUM_LIT:5> ) <EOL> def test_get_step_states ( self ) : <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> states = request . session [ '<STR_LIT>' ] = { } <EOL> states [ '<STR_LIT:name>' ] = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:0> } <EOL> inst . request = request <EOL> self . assertEqual ( inst . get_step_states ( ) , '<STR_LIT>' ) <EOL> def test_get_step_state ( self ) : <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> states = request . session [ '<STR_LIT>' ] = { } <EOL> states [ '<STR_LIT:name>' ] = { '<STR_LIT>' : { <NUM_LIT:0> : '<STR_LIT:state>' } , '<STR_LIT>' : <NUM_LIT:0> } <EOL> inst . request = request <EOL> self . assertEqual ( inst . get_step_state ( ) , '<STR_LIT:state>' ) <EOL> def test_get_step_state_nondefault ( self ) : <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> request . session [ '<STR_LIT>' ] = { } <EOL> inst . request = request <EOL> self . assertEqual ( inst . get_step_state ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_set_step_state ( self ) : <EOL> request = DummyRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> states = request . session [ '<STR_LIT>' ] = { } <EOL> states [ '<STR_LIT:name>' ] = { '<STR_LIT>' : { <NUM_LIT:0> : '<STR_LIT:state>' } , '<STR_LIT>' : <NUM_LIT:0> } <EOL> inst . request = request <EOL> inst . set_step_state ( <NUM_LIT:0> , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( states [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( states [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> class TestFormWizard ( unittest . TestCase ) : <EOL> def _makeOne ( self , name , done , * schemas ) : <EOL> from pyramid_deform import FormWizard <EOL> return FormWizard ( name , done , * schemas ) <EOL> def test___call__ ( self ) : <EOL> inst = self . _makeOne ( '<STR_LIT:name>' , None , '<STR_LIT>' , '<STR_LIT>' ) <EOL> inst . form_wizard_view_class = DummyFormWizardView <EOL> request = DummyRequest ( ) <EOL> result = inst ( request ) <EOL> self . assertEqual ( result . wizard , inst ) <EOL> def test_get_summary ( self ) : <EOL> schema1 = DummySchema ( ) <EOL> schema2 = DummySchema ( ) <EOL> inst = self . _makeOne ( '<STR_LIT:name>' , None , schema1 , schema2 ) <EOL> request = DummyRequest ( ) <EOL> summary = inst . get_summary ( request ) <EOL> self . assertEqual ( <EOL> summary , <EOL> [ { '<STR_LIT>' : True , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : '<STR_LIT:title>' , <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT:class>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : False , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : '<STR_LIT:title>' , <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:class>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> ] ) <EOL> class TestCRSFSchema ( unittest . TestCase ) : <EOL> def _getTargetClass ( self ) : <EOL> from pyramid_deform import CSRFSchema <EOL> return CSRFSchema <EOL> def _makeOne ( self ) : <EOL> return self . _getTargetClass ( ) ( ) <EOL> def test_validate_failure ( self ) : <EOL> from colander import Invalid <EOL> inst = self . _makeOne ( ) <EOL> request = DummyRequest ( ) <EOL> inst2 = inst . bind ( request = request ) <EOL> self . assertRaises ( Invalid , inst2 . deserialize , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_validate_missing ( self ) : <EOL> from colander import Invalid <EOL> inst = self . _makeOne ( ) <EOL> request = DummyRequest ( ) <EOL> inst2 = inst . bind ( request = request ) <EOL> self . assertRaises ( Invalid , inst2 . deserialize , { } ) <EOL> def test_validate_success ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> request = DummyRequest ( ) <EOL> inst2 = inst . bind ( request = request ) <EOL> self . assertEqual ( inst2 . deserialize ( { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> class TestSessionFileUploadTempStore ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . tempdir = tempfile . mkdtemp ( ) <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . tempdir ) <EOL> def _getTargetClass ( self ) : <EOL> from . import SessionFileUploadTempStore <EOL> return SessionFileUploadTempStore <EOL> def _makeOne ( self , request ) : <EOL> return self . _getTargetClass ( ) ( request ) <EOL> def _makeRequest ( self ) : <EOL> request = testing . DummyRequest ( ) <EOL> request . registry . settings = { } <EOL> request . registry . settings [ '<STR_LIT>' ] = self . tempdir <EOL> request . session = DummySession ( ) <EOL> return request <EOL> def test_no_tempdir_in_settings ( self ) : <EOL> request = testing . DummyRequest ( ) <EOL> request . registry . settings = { } <EOL> self . assertRaises ( ConfigurationError , self . _makeOne , request ) <EOL> def test_preview_url ( self ) : <EOL> request = self . _makeRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> self . assertEqual ( inst . preview_url ( None ) , None ) <EOL> def test_contains_true ( self ) : <EOL> request = self . _makeRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> inst . tempstore [ '<STR_LIT:a>' ] = <NUM_LIT:1> <EOL> self . assertTrue ( '<STR_LIT:a>' in inst ) <EOL> def test_contains_false ( self ) : <EOL> request = self . _makeRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> self . assertFalse ( '<STR_LIT:a>' in inst ) <EOL> def test_setitem_stream_None ( self ) : <EOL> request = self . _makeRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> inst [ '<STR_LIT:a>' ] = { } <EOL> self . assertEqual ( inst . tempstore [ '<STR_LIT:a>' ] , { } ) <EOL> self . assertTrue ( request . session . _changed ) <EOL> def test_setitem_stream_file ( self ) : <EOL> request = self . _makeRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> here = os . path . dirname ( __file__ ) <EOL> thisfile = os . path . join ( here , '<STR_LIT>' ) <EOL> fp = open ( thisfile , '<STR_LIT:rb>' ) <EOL> inst [ '<STR_LIT:a>' ] = { '<STR_LIT>' : fp } <EOL> self . assertTrue ( inst . tempstore [ '<STR_LIT:a>' ] [ '<STR_LIT>' ] ) <EOL> fn = os . path . join ( self . tempdir , inst . tempstore [ '<STR_LIT:a>' ] [ '<STR_LIT>' ] ) <EOL> with open ( thisfile , '<STR_LIT:rb>' ) as f : <EOL> expected = f . read ( ) <EOL> with open ( fn , '<STR_LIT:rb>' ) as f : <EOL> received = f . read ( ) <EOL> self . assertTrue ( received , expected ) <EOL> self . assertTrue ( request . session . _changed ) <EOL> fp . close ( ) <EOL> inst [ '<STR_LIT:a>' ] [ '<STR_LIT>' ] . close ( ) <EOL> def test_get_data_None ( self ) : <EOL> request = self . _makeRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> self . assertEqual ( inst . get ( '<STR_LIT:a>' , True ) , True ) <EOL> def test_get_no_randid ( self ) : <EOL> request = self . _makeRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> inst . tempstore [ '<STR_LIT:a>' ] = { '<STR_LIT>' : True } <EOL> self . assertEqual ( inst . get ( '<STR_LIT:a>' ) , { '<STR_LIT>' : True } ) <EOL> def test_get_with_randid ( self ) : <EOL> request = self . _makeRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> fn = os . path . join ( self . tempdir , '<STR_LIT>' ) <EOL> with open ( fn , '<STR_LIT:wb>' ) as f : <EOL> f . write ( b'<STR_LIT:abc>' ) <EOL> inst . tempstore [ '<STR_LIT:a>' ] = { '<STR_LIT>' : '<STR_LIT>' } <EOL> with open ( fn , '<STR_LIT:rb>' ) as f : <EOL> expected = f . read ( ) <EOL> with inst [ '<STR_LIT:a>' ] [ '<STR_LIT>' ] as f : <EOL> received = f . read ( ) <EOL> self . assertEqual ( received , expected ) <EOL> def test_get_with_randid_file_doesntexist ( self ) : <EOL> request = self . _makeRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> inst . tempstore [ '<STR_LIT:a>' ] = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertFalse ( '<STR_LIT>' in inst . get ( '<STR_LIT:a>' ) ) <EOL> def test___getitem___notfound ( self ) : <EOL> request = self . _makeRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> self . assertRaises ( KeyError , inst . __getitem__ , '<STR_LIT:a>' ) <EOL> def test___getitem___found ( self ) : <EOL> request = self . _makeRequest ( ) <EOL> inst = self . _makeOne ( request ) <EOL> inst . tempstore [ '<STR_LIT:a>' ] = { } <EOL> self . assertEqual ( inst [ '<STR_LIT:a>' ] , { } ) <EOL> class DummyForm ( object ) : <EOL> def __init__ ( self , schema , buttons = None , use_ajax = False , ajax_options = '<STR_LIT>' , <EOL> formid = '<STR_LIT>' , action = '<STR_LIT>' , method = '<STR_LIT:POST>' , ** kw ) : <EOL> self . schema = schema <EOL> self . buttons = buttons <EOL> self . use_ajax = use_ajax <EOL> self . ajax_options = ajax_options <EOL> self . formid = formid <EOL> self . action = action <EOL> self . method = method <EOL> self . __dict__ . update ( kw ) <EOL> def get_widget_resources ( self ) : <EOL> return { '<STR_LIT>' : ( ) , '<STR_LIT>' : ( ) } <EOL> def render ( self , appstruct = None ) : <EOL> self . appstruct = appstruct <EOL> return '<STR_LIT>' . format ( appstruct ) <EOL> def validate ( self , controls ) : <EOL> return '<STR_LIT>' <EOL> class DummySchema ( object ) : <EOL> name = '<STR_LIT>' <EOL> description = '<STR_LIT>' <EOL> title = '<STR_LIT:title>' <EOL> def bind ( self , ** kw ) : <EOL> self . kw = kw <EOL> return self <EOL> class DummyButton ( object ) : <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> class DummyFormWizardView ( object ) : <EOL> def __init__ ( self , wizard ) : <EOL> self . wizard = wizard <EOL> def __call__ ( self , request ) : <EOL> return self <EOL> class DummyFormWizard ( object ) : <EOL> name = '<STR_LIT:name>' <EOL> def __init__ ( self , * schemas ) : <EOL> self . schemas = schemas <EOL> def done ( self , request , states ) : <EOL> return '<STR_LIT>' <EOL> class DummySession ( dict ) : <EOL> _changed = False <EOL> def changed ( self ) : <EOL> self . _changed = True <EOL> def get_csrf_token ( self ) : <EOL> return '<STR_LIT>' <EOL> class DummyRequest ( testing . DummyRequest ) : <EOL> def __init__ ( self , * arg , ** kw ) : <EOL> testing . DummyRequest . __init__ ( self , * arg , ** kw ) <EOL> self . session = DummySession ( ) <EOL> class DummyFormView ( object ) : <EOL> def __init__ ( self , request ) : <EOL> self . request = request <EOL> def __call__ ( self ) : <EOL> return '<STR_LIT>' <EOL> class DummySerializer ( object ) : <EOL> def __init__ ( self , result ) : <EOL> self . result = result <EOL> def deserialize ( self , state ) : <EOL> return self . result <EOL> def serialize ( self , state ) : <EOL> return self . result <EOL> class TestConfigureZPTRenderer ( unittest . TestCase ) : <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_translator ( self , Form ) : <EOL> from pyramid_deform import translator <EOL> from pyramid_deform import configure_zpt_renderer <EOL> configure_zpt_renderer ( ) <EOL> assert Form . default_renderer . translate is translator <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_search_path ( self , Form ) : <EOL> from pyramid_deform import configure_zpt_renderer <EOL> search_path_before = ( '<STR_LIT>' , ) <EOL> Form . default_renderer . loader . search_path = search_path_before <EOL> configure_zpt_renderer ( [ '<STR_LIT>' ] ) <EOL> search_path = Form . default_renderer . loader . search_path <EOL> assert len ( Form . default_renderer . loader . search_path ) == <NUM_LIT:2> <EOL> assert ( search_path [ - <NUM_LIT:1> ] , ) == search_path_before <EOL> assert search_path [ <NUM_LIT:0> ] . endswith ( '<STR_LIT>' + os . path . sep + '<STR_LIT>' ) <EOL> class TestIncludeMe ( unittest . TestCase ) : <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_default ( self , Form , configure_zpt_renderer ) : <EOL> from pyramid_deform import includeme <EOL> config = Mock ( ) <EOL> config . registry . settings = { } <EOL> includeme ( config ) <EOL> assert config . add_translation_dirs . call_count == <NUM_LIT:1> <EOL> assert config . add_static_view . call_count == <NUM_LIT:1> <EOL> config . add_static_view . assert_called_with ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> configure_zpt_renderer . assert_called_with ( [ ] ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_static_path ( self , Form , configure_zpt_renderer ) : <EOL> from pyramid_deform import includeme <EOL> config = Mock ( ) <EOL> config . registry . settings = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> includeme ( config ) <EOL> assert config . add_translation_dirs . call_count == <NUM_LIT:1> <EOL> assert config . add_static_view . call_count == <NUM_LIT:1> <EOL> config . add_static_view . assert_called_with ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> configure_zpt_renderer . assert_called_with ( [ ] ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_template_search_path ( self , Form , configure_zpt_renderer ) : <EOL> from pyramid_deform import includeme <EOL> config = Mock ( ) <EOL> config . registry . settings = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> includeme ( config ) <EOL> assert config . add_translation_dirs . call_count == <NUM_LIT:1> <EOL> assert config . add_static_view . call_count == <NUM_LIT:1> <EOL> configure_zpt_renderer . assert_called_with ( [ '<STR_LIT>' ] ) </s>
