Пример #1
0
def test_assets_render_any_fragment_from_style():
    register_style(
        'my_style',
        Style(
            test,
            assets__an_asset=Fragment('This is a fragment!'),
        ))

    class MyPage(Page):
        class Meta:
            iommi_style = 'my_style'

    expected = prettify('''
        <!DOCTYPE html>
        <html>
            <head>
                <title/>
                This is a fragment!
            </head>
            <body/>
        </html>
    ''')
    actual = prettify(
        MyPage().bind(request=req('get')).render_to_response().content)
    assert actual == expected

    unregister_style('my_style')
Пример #2
0
def test_assets_render_from_style():
    register_style(
        'my_style',
        Style(
            test,
            assets__an_asset=Asset.css(attrs__href='http://foo.bar/baz'),
        ))

    class MyPage(Page):
        class Meta:
            iommi_style = 'my_style'

    expected = prettify('''
        <!DOCTYPE html>
        <html>
            <head>
                <title/>
                <link href='http://foo.bar/baz' rel="stylesheet"/>
            </head>
            <body/>
        </html>
    ''')
    actual = prettify(
        MyPage().bind(request=req('get')).render_to_response().content)
    assert actual == expected

    unregister_style('my_style')
Пример #3
0
def test_deprecated_assets_style(settings, capsys):
    settings.DEBUG = True
    register_style(
        'my_style',
        Style(
            test,
            assets__an_asset=Asset.css(attrs__href='http://foo.bar/baz'),
        ))

    captured = capsys.readouterr()
    assert 'Warning: The preferred way to add top level assets config' in captured.out

    settings.DEBUG = False

    expected = prettify('''
        <!DOCTYPE html>
        <html>
            <head>
                <title/>
                <link href='http://foo.bar/baz' rel="stylesheet"/>
            </head>
            <body/>
        </html>
    ''')
    actual = prettify(
        Page(iommi_style='my_style').bind(
            request=req('get')).render_to_response().content)
    assert actual == expected

    unregister_style('my_style')
Пример #4
0
 def ready(self):
     register_style(
         'forum',
         Style(
             base,
             base_template='iommi/base_forum.html',
             Form__attrs__class__form=True,
             Field__attrs__class__field=True,
         )
     )
Пример #5
0
def test_style_bulk_form_broken_on_no_form():
    from iommi import Table
    from tests.models import Foo

    register_style('my_style',
                   Style(
                       base,
                       Table__bulk__attrs__class__foo=True,
                   ))

    class MyTable(Table):
        class Meta:
            iommi_style = 'my_style'
            model = Foo

    table = MyTable()
    table = table.bind(request=None)

    assert table.bulk is None

    unregister_style('my_style')
Пример #6
0
def test_style_bulk_form():
    from iommi import Column, Table
    from tests.models import Foo

    register_style('my_style',
                   Style(
                       base,
                       Table__bulk__attrs__class__foo=True,
                   ))

    class MyTable(Table):
        class Meta:
            iommi_style = 'my_style'
            model = Foo

        bar = Column(bulk__include=True)

    table = MyTable()
    table = table.bind(request=None)

    assert 'foo' in render_attrs(table.bulk.attrs)

    unregister_style('my_style')