Example #1
0
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)
Example #2
0
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)
Example #3
0
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)
Example #4
0
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)
Example #5
0
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)
Example #6
0
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
Example #7
0
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
Example #8
0
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
Example #9
0
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
Example #10
0
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
Example #11
0
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
Example #12
0
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
Example #13
0
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
Example #14
0
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
Example #15
0
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
Example #16
0
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
Example #17
0
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