Ejemplo n.º 1
0
def test_includeme(mapper, monkeypatch):
    if mapper:

        class Mapper:
            pass

        mapper = Mapper

    mapper_cls = pretend.stub()
    csrf_mapper_factory = pretend.call_recorder(lambda m: mapper_cls)
    monkeypatch.setattr(csrf, "csrf_mapper_factory", csrf_mapper_factory)

    config = pretend.stub(
        commit=pretend.call_recorder(lambda: None),
        registry=pretend.stub(
            queryUtility=pretend.call_recorder(lambda x: mapper), ),
        set_view_mapper=pretend.call_recorder(lambda m: None))

    csrf.includeme(config)

    assert config.commit.calls == [pretend.call()]
    assert config.registry.queryUtility.calls == [
        pretend.call(IViewMapperFactory),
    ]
    assert csrf_mapper_factory.calls == [
        pretend.call(mapper if mapper is not None else DefaultViewMapper),
    ]
    assert config.set_view_mapper.calls == [pretend.call(mapper_cls)]
Ejemplo n.º 2
0
def test_includeme(mapper, monkeypatch):
    if mapper:
        class Mapper:
            pass

        mapper = Mapper

    mapper_cls = pretend.stub()
    csrf_mapper_factory = pretend.call_recorder(lambda m: mapper_cls)
    monkeypatch.setattr(csrf, "csrf_mapper_factory", csrf_mapper_factory)

    config = pretend.stub(
        commit=pretend.call_recorder(lambda: None),
        registry=pretend.stub(
            queryUtility=pretend.call_recorder(lambda x: mapper),
        ),
        set_view_mapper=pretend.call_recorder(lambda m: None)
    )

    csrf.includeme(config)

    assert config.commit.calls == [pretend.call()]
    assert config.registry.queryUtility.calls == [
        pretend.call(IViewMapperFactory),
    ]
    assert csrf_mapper_factory.calls == [
        pretend.call(mapper if mapper is not None else DefaultViewMapper),
    ]
    assert config.set_view_mapper.calls == [pretend.call(mapper_cls)]
Ejemplo n.º 3
0
def test_includeme():
    config = pretend.stub(
        set_default_csrf_options=pretend.call_recorder(lambda **kw: None),
        add_view_deriver=pretend.call_recorder(lambda *args, **kw: None),
    )

    csrf.includeme(config)

    assert config.set_default_csrf_options.calls == [
        pretend.call(require_csrf=True)
    ]
    assert config.add_view_deriver.calls == [
        pretend.call(csrf_view, under=INGRESS, over="secured_view"),
        pretend.call(csrf.require_method_view, under=INGRESS,
                     over="csrf_view"),
    ]
Ejemplo n.º 4
0
def test_includeme():
    config = pretend.stub(
        set_default_csrf_options=pretend.call_recorder(lambda **kw: None),
        add_view_deriver=pretend.call_recorder(lambda *args, **kw: None),
    )

    csrf.includeme(config)

    assert config.set_default_csrf_options.calls == [
        pretend.call(require_csrf=True),
    ]
    assert config.add_view_deriver.calls == [
        pretend.call(csrf_view, under=INGRESS, over="secured_view"),
        pretend.call(
            csrf.require_method_view,
            under=INGRESS,
            over="csrf_view",
        ),
    ]