Exemplo n.º 1
0
def test_can_register_handlers():
    def handler(page_instructions, renderer, assembly):
        global handler_called
        assembly.add_page_instructions(page_instructions, "dummyapp/page/uses.yaml")
        handler_called = True
        assert page_instructions.other_yaml == ["dummyapp/page/uses.yaml"]
        assert page_instructions.uses_yaml == []
        assert page_instructions.root_yaml == "dummyapp/page/sample.yaml"

    request = get_request_fixture()
    c = RequestContext(request, {"foo": "bar"})
    pa = PageAssembly("dummyapp/page/sample.yaml", c)

    pa.register_handler(handler)
    # Make sure we can't get a dupe
    pa.register_handler(handler)

    assert len(BaseAssembly._page_assembly_handlers) == 1

    content = pa.dumps()

    assert handler_called

    pa.unregister_all()

    assert len(BaseAssembly._page_assembly_handlers) == 0
Exemplo n.º 2
0
def test_can_unregister_handlers():
    def handler(page_instructions, renderer, assembly):
        pass

    request = get_request_fixture()
    c = RequestContext(request, {"foo": "bar"})
    pa = PageAssembly("dummyapp/page/sample.yaml", c)

    pa.register_handler(handler)
    pa.unregister_handler(handler)

    assert len(BaseAssembly._page_assembly_handlers) == 0