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>'
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'
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.')]
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>'
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'
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.')]