Beispiel #1
0
def test_register_inclusion_renderer():
    foo = Library('foo', '')

    with pytest.raises(UnknownResourceExtensionError):
        # The renderer for '.unknown' is not yet defined.
        Resource(foo, 'nothing.unknown')

    def render_unknown(url):
        return '<link rel="unknown" href="%s" />' % url

    register_inclusion_renderer('.unknown', render_unknown)
    a = Resource(foo, 'nothing.unknown')

    needed = NeededResources()
    needed.need(a)
    assert needed.render() == ('<link rel="unknown" href="/fanstatic/foo/nothing.unknown" />')
Beispiel #2
0
def test_register_inclusion_renderer():
    foo = Library('foo', '')

    with pytest.raises(UnknownResourceExtensionError):
        # The renderer for '.unknown' is not yet defined.
        Resource(foo, 'nothing.unknown')

    def render_unknown(url):
        return '<link rel="unknown" href="%s" />' % url

    register_inclusion_renderer('.unknown', render_unknown)
    a = Resource(foo, 'nothing.unknown')

    needed = NeededResources()
    needed.need(a)
    assert needed.render() == (
        '<link rel="unknown" href="/fanstatic/foo/nothing.unknown" />')
Beispiel #3
0
def test_register_inclusion_renderer():
    foo = Library('foo', '')

    with pytest.raises(UnknownResourceExtensionError):
        # The renderer for '.unknown' is not yet defined.
        Resource(foo, 'nothing.unknown')

    def render_unknown(url):
        return '<link rel="unknown" href="%s" />' % url

    register_inclusion_renderer('.unknown', render_unknown)
    a = Resource(foo, 'stuff.unknown')

    needed = init_needed(resources=[a])
    incl = Inclusion(needed)
    assert incl.render() == \
        '<link rel="unknown" href="/fanstatic/foo/stuff.unknown" />'
Beispiel #4
0
def test_sort_registered_inclusion_renderers_in_order():
    from fanstatic import get_library_registry
    foo = Library('foo', '')

    def render_unknown(url):
        return '<unknown href="%s"/>' % url

    register_inclusion_renderer('.later', render_unknown, 50)
    register_inclusion_renderer('.sooner', render_unknown, 5)
    register_inclusion_renderer('.between', render_unknown, 25)
    a = Resource(foo, 'nothing.later')
    b = Resource(foo, 'something.js')
    c = Resource(foo, 'something.css')
    d = Resource(foo, 'something.ico')
    e = Resource(foo, 'nothing.sooner')
    f = Resource(foo, 'nothing.between')

    get_library_registry().prepare()
    assert sort_resources([a, b, c, d]) == [c, b, d, a]
    assert sort_resources([a, b, c, d, e]) == [e, c, b, d, a]
    assert sort_resources([a, b, c, d, e, f]) == [e, c, b, f, d, a]
Beispiel #5
0
def test_sort_registered_inclusion_renderers_in_order():
    foo = Library('foo', '')

    def render_unknown(url):
        return '<unknown href="%s"/>' % url

    register_inclusion_renderer('.later', render_unknown, 50)
    a = Resource(foo, 'nothing.later')
    b = Resource(foo, 'something.js')
    c = Resource(foo, 'something.css')
    d = Resource(foo, 'something.ico')

    assert sort_resources([a, b, c, d]) == [c, b, d, a]

    register_inclusion_renderer('.sooner', render_unknown, 5)
    e = Resource(foo, 'nothing.sooner')
    assert sort_resources([a, b, c, d, e]) == [e, c, b, d, a]

    register_inclusion_renderer('.between', render_unknown, 25)
    f = Resource(foo, 'nothing.between')
    assert sort_resources([a, b, c, d, e, f]) == [e, c, b, f, d, a]
Beispiel #6
0
def test_registered_inclusion_renderers_in_order():
    foo = Library('foo', '')

    def render_unknown(url):
        return '<unknown href="%s"/>' % url

    register_inclusion_renderer('.later', render_unknown, 50)
    a = Resource(foo, 'nothing.later')
    b = Resource(foo, 'something.js')
    c = Resource(foo, 'something.css')
    d = Resource(foo, 'something.ico')

    needed = NeededResources()
    needed.need(a)
    needed.need(b)
    needed.need(c)
    needed.need(d)

    assert needed.render() == """\
<link rel="stylesheet" type="text/css" href="/fanstatic/foo/something.css" />
<script type="text/javascript" src="/fanstatic/foo/something.js"></script>
<link rel="shortcut icon" type="image/x-icon" href="/fanstatic/foo/something.ico"/>
<unknown href="/fanstatic/foo/nothing.later"/>"""

    register_inclusion_renderer('.sooner', render_unknown, 5)
    e = Resource(foo, 'nothing.sooner')
    needed.need(e)
    assert needed.render() == """\
<unknown href="/fanstatic/foo/nothing.sooner"/>
<link rel="stylesheet" type="text/css" href="/fanstatic/foo/something.css" />
<script type="text/javascript" src="/fanstatic/foo/something.js"></script>
<link rel="shortcut icon" type="image/x-icon" href="/fanstatic/foo/something.ico"/>
<unknown href="/fanstatic/foo/nothing.later"/>"""

    register_inclusion_renderer('.between', render_unknown, 25)
    f = Resource(foo, 'nothing.between')
    needed.need(f)
    assert needed.render() == """\
Beispiel #7
0
def test_registered_inclusion_renderers_in_order():
    foo = Library('foo', '')

    def render_unknown(url):
        return '<unknown href="%s"/>' % url

    register_inclusion_renderer('.later', render_unknown, 50)
    a = Resource(foo, 'nothing.later')
    b = Resource(foo, 'something.js')
    c = Resource(foo, 'something.css')
    d = Resource(foo, 'something.ico')

    needed = NeededResources()
    needed.need(a)
    needed.need(b)
    needed.need(c)
    needed.need(d)

    assert needed.render() == """\
<link rel="stylesheet" type="text/css" href="/fanstatic/foo/something.css" />
<script type="text/javascript" src="/fanstatic/foo/something.js"></script>
<link rel="shortcut icon" type="image/x-icon" href="/fanstatic/foo/something.ico"/>
<unknown href="/fanstatic/foo/nothing.later"/>"""

    register_inclusion_renderer('.sooner', render_unknown, 5)
    e = Resource(foo, 'nothing.sooner')
    needed.need(e)
    assert needed.render() == """\
<unknown href="/fanstatic/foo/nothing.sooner"/>
<link rel="stylesheet" type="text/css" href="/fanstatic/foo/something.css" />
<script type="text/javascript" src="/fanstatic/foo/something.js"></script>
<link rel="shortcut icon" type="image/x-icon" href="/fanstatic/foo/something.ico"/>
<unknown href="/fanstatic/foo/nothing.later"/>"""

    register_inclusion_renderer('.between', render_unknown, 25)
    f = Resource(foo, 'nothing.between')
    needed.need(f)
    assert needed.render() == """\