def test_features_save_checks_csrf_token(Feature, check_csrf_token): Feature.all.return_value = [] request = DummyRequest(post={}) views.features_save(request) check_csrf_token.assert_called_with(request)
def test_features_save_checks_csrf_token(Feature, check_csrf_token, req): Feature.all.return_value = [] req.POST = {} views.features_save(req) check_csrf_token.assert_called_with(req)
def test_features_save_checks_csrf_token(Feature, check_csrf_token, pyramid_request): Feature.all.return_value = [] pyramid_request.POST = {} views.features_save(pyramid_request) check_csrf_token.assert_called_with(pyramid_request)
def test_features_save_ignores_unknown_fields(Feature, pyramid_request): foo = DummyFeature(name='foo') Feature.all.return_value = [foo] pyramid_request.POST = {'foo[wibble]': 'on', 'foo[admins]': 'ignoreme'} views.features_save(pyramid_request) assert foo.admins == False
def test_features_save_ignores_unknown_fields(Feature): foo = DummyFeature(name='foo') Feature.all.return_value = [foo] request = DummyRequest(post={'foo[wibble]': 'on', 'foo[admins]': 'ignoreme'}) views.features_save(request) assert foo.admins == False
def test_features_save_sets_attributes_when_checkboxes_off(Feature): foo = DummyFeature(name='foo') foo.everyone = True foo.staff = True Feature.all.return_value = [foo] request = DummyRequest(post={}) views.features_save(request) assert foo.everyone == foo.staff == False
def test_features_save_sets_attributes_when_checkboxes_off(Feature, pyramid_request): foo = DummyFeature(name='foo') foo.everyone = True foo.staff = True Feature.all.return_value = [foo] pyramid_request.POST = {} views.features_save(pyramid_request) assert foo.everyone == foo.staff == False
def test_features_save_ignores_unknown_fields(Feature): foo = DummyFeature(name='foo') Feature.all.return_value = [foo] request = DummyRequest(post={ 'foo[wibble]': 'on', 'foo[admins]': 'ignoreme' }) views.features_save(request) assert foo.admins == False
def test_features_save_sets_attributes_when_checkboxes_on(Feature, pyramid_request): foo = DummyFeature(name='foo') bar = DummyFeature(name='bar') Feature.all.return_value = [foo, bar] pyramid_request.POST = {'foo[everyone]': 'on', 'foo[staff]': 'on', 'bar[admins]': 'on'} views.features_save(pyramid_request) assert foo.everyone == foo.staff == bar.admins == True
def test_features_save_sets_cohorts_when_checkboxes_on(pyramid_request): feat = models.Feature(name='feat') cohort = models.FeatureCohort(name='cohort') pyramid_request.db.add(feat) pyramid_request.db.add(cohort) pyramid_request.db.flush() pyramid_request.POST = {'feat[cohorts][cohort]': 'on'} views.features_save(pyramid_request) feat = pyramid_request.db.query(models.Feature).filter_by(name='feat').first() cohort = pyramid_request.db.query(models.FeatureCohort).filter_by(name='cohort').first() assert len(feat.cohorts) == 1 assert cohort in feat.cohorts