示例#1
0
def test_render_attribute_to_document():
    document = PyQuery('<a attribute="{ value }" data-riot-id="0"></a>')
    expression =  {'expression': '{ value }', 'attribute': 'attribute', 'type': 'attribute', 'node': document}
    render_document([expression], {'value': 'value'})
    assert document.outer_html() == '<a attribute="value" data-riot-id="0" data-riot-dirty="true"></a>'
    render_document([expression], {'value': 1})
    assert document.outer_html() == '<a attribute="1" data-riot-id="0" data-riot-dirty="true"></a>'
示例#2
0
def test_render_each_to_document():
    document = PyQuery('<custom data-riot-id="0"><button label="{ label }" each="{ items }" data-riot-id="0.0"></button></custom>')
    expressions = parse_document_expressions(document)
    render_document(expressions, {'items': [{'label': 'first'}, {'label': 'second'}]})
    assert document.attr['data-riot-dirty'] == 'true'
    assert len(document.children()) == 2
    assert document('button').eq(0).attr.label == 'first'
    assert document('button').eq(1).attr.label == 'second'
示例#3
0
def test_render_markup_to_document():
    document = PyQuery('<custom data-riot-id="0"><text data-riot-id="0.0"><span class="name">{ name}</span><span class="greet">{ greet }</span></text></custom>')
    expressions = parse_document_expressions(document)
    render_document(expressions, {'name': '@ainesmile', 'greet': 'I love you.'})
    assert document.outer_html() == '<custom data-riot-id="0" data-riot-dirty="true"><text data-riot-id="0.0" data-riot-dirty="true"></text></custom>'
    assert expressions[0]['value'] == [(u'name', '@ainesmile'), (u'greet', 'I love you.')]
    render_document(expressions, {'name': '@soasme', 'greet': 'I love you, too.'})
    assert expressions[0]['value'] == [(u'name', '@soasme'), (u'greet', 'I love you, too.')]
示例#4
0
def test_render_attribute_to_document():
    document = PyQuery('<a attribute="{ value }" data-riot-id="0"></a>')
    expression = {
        'expression': '{ value }',
        'attribute': 'attribute',
        'type': 'attribute',
        'node': document
    }
    render_document([expression], {'value': 'value'})
    assert document.outer_html(
    ) == '<a attribute="value" data-riot-id="0" data-riot-dirty="true"></a>'
    render_document([expression], {'value': 1})
    assert document.outer_html(
    ) == '<a attribute="1" data-riot-id="0" data-riot-dirty="true"></a>'
示例#5
0
def test_render_each_to_document():
    document = PyQuery(
        '<custom data-riot-id="0"><button label="{ label }" each="{ items }" data-riot-id="0.0"></button></custom>'
    )
    expressions = parse_document_expressions(document)
    render_document(expressions,
                    {'items': [{
                        'label': 'first'
                    }, {
                        'label': 'second'
                    }]})
    assert document.attr['data-riot-dirty'] == 'true'
    assert len(document.children()) == 2
    assert document('button').eq(0).attr.label == 'first'
    assert document('button').eq(1).attr.label == 'second'
示例#6
0
def test_render_markup_to_document():
    document = PyQuery(
        '<custom data-riot-id="0"><text data-riot-id="0.0"><span class="name">{ name}</span><span class="greet">{ greet }</span></text></custom>'
    )
    expressions = parse_document_expressions(document)
    render_document(expressions, {
        'name': '@ainesmile',
        'greet': 'I love you.'
    })
    assert document.outer_html(
    ) == '<custom data-riot-id="0" data-riot-dirty="true"><text data-riot-id="0.0" data-riot-dirty="true"></text></custom>'
    assert expressions[0]['value'] == [(u'name', '@ainesmile'),
                                       (u'greet', 'I love you.')]
    render_document(expressions, {
        'name': '@soasme',
        'greet': 'I love you, too.'
    })
    assert expressions[0]['value'] == [(u'name', '@soasme'),
                                       (u'greet', 'I love you, too.')]