<s> from pyramid . testing import DummyRequest <EOL> import pytest <EOL> from h . admin . views import features as views <EOL> class DummyFeature ( object ) : <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> self . everyone = False <EOL> self . admins = False <EOL> self . staff = False <EOL> features_save_fixtures = pytest . mark . usefixtures ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> @ features_save_fixtures <EOL> def test_features_save_sets_attributes_when_checkboxes_on ( Feature ) : <EOL> foo = DummyFeature ( name = '<STR_LIT:foo>' ) <EOL> bar = DummyFeature ( name = '<STR_LIT:bar>' ) <EOL> Feature . all . return_value = [ foo , bar ] <EOL> request = DummyRequest ( post = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> views . features_save ( request ) <EOL> assert foo . everyone == foo . staff == bar . admins == True <EOL> @ features_save_fixtures <EOL> def test_features_save_sets_attributes_when_checkboxes_off ( Feature ) : <EOL> foo = DummyFeature ( name = '<STR_LIT:foo>' ) <EOL> foo . everyone = True <EOL> foo . staff = True <EOL> Feature . all . return_value = [ foo ] <EOL> request = DummyRequest ( post = { } ) <EOL> views . features_save ( request ) <EOL> assert foo . everyone == foo . staff == False <EOL> @ features_save_fixtures <EOL> def test_features_save_ignores_unknown_fields ( Feature ) : <EOL> foo = DummyFeature ( name = '<STR_LIT:foo>' ) <EOL> Feature . all . return_value = [ foo ] <EOL> request = DummyRequest ( post = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> views . features_save ( request ) <EOL> assert foo . admins == False <EOL> @ features_save_fixtures <EOL> def test_features_save_checks_csrf_token ( Feature , check_csrf_token ) : <EOL> Feature . all . return_value = [ ] <EOL> request = DummyRequest ( post = { } ) <EOL> views . features_save ( request ) <EOL> check_csrf_token . assert_called_with ( request ) <EOL> @ pytest . fixture ( autouse = True ) <EOL> def routes ( config ) : <EOL> config . add_route ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ pytest . fixture <EOL> def Feature ( patch ) : <EOL> return patch ( '<STR_LIT>' ) <EOL> @ pytest . fixture <EOL> def check_csrf_token ( patch ) : <EOL> return patch ( '<STR_LIT>' ) </s>
