示例#1
0
def test_unicode_ajax_response(pyramid_req):
    """Check if the rendering process generates all a valid utf-8 encoded response
    """

    # Create a Transaction with an assigned root_node.
    page = Page(None, pyramid_req)
    page.request.is_xhr = True
    page.page_request.params = {"q": []}
    transaction = page.transaction
    transaction['components_assigned'] = True
    transaction.set_component(
        'root_node', {
            'cid': 'root_node',
            'slot': None,
            'config': {},
            'class': (ComponentContainerBase, {}, ('root_node', None))
        })

    page.handle_transaction()

    # Generate a response with a unicode string.
    page.root_node.add_js_response(u'console.log("ää");')

    # Redraw and handle_ajax_events, so that all necessary output will be generated.
    page.root_node.redraw()

    page.handle_ajax_events()

    assert True not in [c.is_rendered for c in page.get_active_components()]

    out = page.render()
    assert u'console.log("ää");' in out
    out.encode('utf-8')
示例#2
0
def test_unicode_ajax_response(pyramid_req):
    """Check if the rendering process generates all a valid utf-8 encoded response
    """

    # Create a Transaction with an assigned root_node.
    page = Page(None, pyramid_req)
    page.request.is_xhr = True
    page.page_request.params = {"q": []}
    transaction = page.transaction
    transaction['components_assigned'] = True
    transaction.set_component('root_node',
                              {'cid': 'root_node',
                               'slot': None,
                               'config': {},
                               'class': (ComponentContainerBase,
                                         {},
                                         ('root_node', None))})

    page.handle_transaction()

    # Generate a response with a unicode string.
    page.root_node.add_js_response(u'console.log("ää");')

    # Redraw and handle_ajax_events, so that all necessary output will be generated.
    page.root_node.redraw()

    page.handle_ajax_events()

    assert True not in [c.is_rendered for c in page.get_active_components()]

    out = page.render()
    assert u'console.log("ää");' in out
    out.encode('utf-8')
示例#3
0
def test_component_rendering_ajax(pyramid_req):
    """Check if the rendering process generates all required AJAX scripts.
    """

    # Create a Transaction with an assigned root_node.
    page = Page(pyramid_req)
    page.request.is_xhr = True
    page.page_request.params = {"q": []}
    transaction = page.transaction
    transaction['components_assigned'] = True
    transaction.set_component('root_node',
                              {'cid': 'root_node',
                               'slot': None,
                               'config': {},
                               'class': (ComponentContainerBase,
                                         {},
                                         ('root_node', None))})

    page.handle_transaction()

    base_components = 10
    leaf_components = 200

    # Generate a nice round 210 child components.
    page.root_node.add_component(ComponentContainerBase(cid='child_node_0'))
    for i in range(0, base_components):
        getattr(page, 'child_node_%s' % i) \
            .add_component(ComponentContainerBase(cid='child_node_%s' % (i + 1)))
        for x in range(0, leaf_components):
            getattr(page,
                    'child_node_%s' % (i + 1)) \
                .add_component(ComponentContainerBase(cid='child_node_%s_%s' % (i + 1, x)))

    # Redraw and handle_ajax_events, so that all necessary output will be generated.
    page.root_node.redraw()

    page.handle_ajax_events()

    assert True not in [c.is_rendered for c in page.get_active_components()]

    # start_time = time.time()
    out = page.render()
    # print base_components, leaf_components, int((time.time() - start_time) * 1000000)

    # Checking set_component_info calls required to tell EPFLs JS what the component is capable of.
    for i in range(0, base_components):
        assert ('epfl.set_component_info(\\"child_node_%s\\", \\"handle\\", [\'change\', \'reinitialize\', '
                '\'set_row\']);' %
                (i + 1)) in out, "Missing set component info for child_node_%s" % (i + 1)
        out = out.replace('epfl.set_component_info("child_node_%s", "handle", [\'set_row\']);' % (i + 1), '')
        for x in range(0, leaf_components):
            assert ('epfl.set_component_info(\\"child_node_%s_%s\\", \\"handle\\", [\'change\', \'reinitialize\', '
                    '\'set_row\']);' % (i + 1, x)) in out
            out = out.replace('epfl.set_component_info("child_node_%s_%s", "handle", [\'change\', \'set_row\']);' %
                              (i + 1, x), '')
    assert 'epfl.set_component_info(\\"child_node_0\\", \\"handle\\", [\'change\', \'reinitialize\', \'set_row\']);' \
           'epfl.set_component_info(\\"root_node\\", \\"handle\\", [\'change\', \'reinitialize\', \'set_row\']);' in out
示例#4
0
def test_component_rendering_ajax(pyramid_req):
    """Check if the rendering process generates all required AJAX scripts.
    """

    # Create a Transaction with an assigned root_node.
    page = Page(None, pyramid_req)
    page.request.is_xhr = True
    page.page_request.params = {"q": []}
    transaction = page.transaction
    transaction['components_assigned'] = True
    transaction.set_component(
        'root_node', {
            'cid': 'root_node',
            'slot': None,
            'config': {},
            'class': (ComponentContainerBase, {}, ('root_node', None))
        })

    page.handle_transaction()

    base_components = 10
    leaf_components = 200

    # Generate a nice round 210 child components.
    page.root_node.add_component(ComponentContainerBase(cid='child_node_0'))
    for i in range(0, base_components):
        getattr(page, 'child_node_%s' % i) \
            .add_component(ComponentContainerBase(cid='child_node_%s' % (i + 1)))
        for x in range(0, leaf_components):
            getattr(page,
                    'child_node_%s' % (i + 1)) \
                .add_component(ComponentContainerBase(cid='child_node_%s_%s' % (i + 1, x)))

    # Redraw and handle_ajax_events, so that all necessary output will be generated.
    page.root_node.redraw()

    page.handle_ajax_events()

    assert True not in [c.is_rendered for c in page.get_active_components()]

    # start_time = time.time()
    out = page.render()
示例#5
0
def test_component_rendering_ajax(pyramid_req):
    """Check if the rendering process generates all required AJAX scripts.
    """

    # Create a Transaction with an assigned root_node.
    page = Page(None, pyramid_req)
    page.request.is_xhr = True
    page.page_request.params = {"q": []}
    transaction = page.transaction
    transaction['components_assigned'] = True
    transaction.set_component('root_node',
                              {'cid': 'root_node',
                               'slot': None,
                               'config': {},
                               'class': (ComponentContainerBase,
                                         {},
                                         ('root_node', None))})

    page.handle_transaction()

    base_components = 10
    leaf_components = 200

    # Generate a nice round 210 child components.
    page.root_node.add_component(ComponentContainerBase(cid='child_node_0'))
    for i in range(0, base_components):
        getattr(page, 'child_node_%s' % i) \
            .add_component(ComponentContainerBase(cid='child_node_%s' % (i + 1)))
        for x in range(0, leaf_components):
            getattr(page,
                    'child_node_%s' % (i + 1)) \
                .add_component(ComponentContainerBase(cid='child_node_%s_%s' % (i + 1, x)))

    # Redraw and handle_ajax_events, so that all necessary output will be generated.
    page.root_node.redraw()

    page.handle_ajax_events()

    assert True not in [c.is_rendered for c in page.get_active_components()]

    # start_time = time.time()
    out = page.render()
示例#6
0
def test_re_rendering_components(pyramid_req):
    """Check if components can be rendered correctly when regenerated from a Transaction.
    """
    # Generate a transaction with the appropriate components.
    page = Page(pyramid_req)
    page.request.is_xhr = True
    page.page_request.params = {"q": []}
    transaction = page.transaction
    transaction['components_assigned'] = True
    transaction.set_component('root_node',
                              {'cid': 'root_node',
                               'slot': None,
                               'config': {},
                               'class': (ComponentContainerBase,
                                         {},
                                         ('root_node', None))})
    transaction.set_component('child_node_0',
                              {'ccid': 'root_node',
                               'cid': 'child_node_0',
                               'slot': None,
                               'config': {},
                               'class': (ComponentContainerBase,
                                         {},
                                         ('child_node_0', None))})
    # This one is about precision, 55 components suffice, we're not after performance here.
    compo_depth = 5
    compo_width = 10

    for i in range(0, compo_depth):
        transaction.set_component('child_node_%s' % (i + 1),
                                  {'ccid': 'child_node_%s' % i,
                                   'cid': 'child_node_%s' % (i + 1),
                                   'slot': None,
                                   'config': {},
                                   'class': (ComponentContainerBase,
                                             {},
                                             ('child_node_%s' % (i + 1), None))})
        for x in range(0, compo_width):
            transaction.set_component('child_node_%s_%s' % (i + 1, x),
                                      {'ccid': 'child_node_%s' % i,
                                       'cid': 'child_node_%s_%s' % (i + 1, x),
                                       'slot': None,
                                       'config': {},
                                       'class': (ComponentContainerBase,
                                                 {},
                                                 ('child_node_%s_%s' % (i + 1, x), None))})

    # Set everything up.
    page.handle_transaction()

    # root_node redraw should supersede following child redraws.
    page.root_node.redraw()
    page.child_node_3_1.redraw()

    page.handle_ajax_events()

    out = page.render()

    # Make sure the appropriate replace_component calls are all there. Almost exclusively JS, since HTML will be in the
    # root_node replace_component.
    for i in range(0, compo_depth):
        assert out.count(
            "epfl.replace_component('child_node_%s'" % (i + 1)
        ) == out.count("epfl.replace_component('child_node_0'")
        for x in range(0, compo_width):
            assert out.count(
                "epfl.replace_component('child_node_%s_%s'" % (i + 1, x)
            ) == out.count("epfl.replace_component('child_node_0'")
示例#7
0
def test_re_rendering_components(pyramid_req):
    """Check if components can be rendered correctly when regenerated from a Transaction.
    """
    # Generate a transaction with the appropriate components.
    page = Page(None, pyramid_req)
    page.request.is_xhr = True
    page.page_request.params = {"q": []}
    transaction = page.transaction
    transaction['components_assigned'] = True
    transaction.set_component(
        'root_node', {
            'cid': 'root_node',
            'slot': None,
            'config': {},
            'class': (ComponentContainerBase, {}, ('root_node', None))
        })
    transaction.set_component(
        'child_node_0', {
            'ccid': 'root_node',
            'cid': 'child_node_0',
            'slot': None,
            'config': {},
            'class': (ComponentContainerBase, {}, ('child_node_0', None))
        })
    # This one is about precision, 55 components suffice, we're not after performance here.
    compo_depth = 5
    compo_width = 10

    for i in range(0, compo_depth):
        transaction.set_component(
            'child_node_%s' % (i + 1), {
                'ccid':
                'child_node_%s' % i,
                'cid':
                'child_node_%s' % (i + 1),
                'slot':
                None,
                'config': {},
                'class':
                (ComponentContainerBase, {}, ('child_node_%s' % (i + 1), None))
            })
        for x in range(0, compo_width):
            transaction.set_component(
                'child_node_%s_%s' % (i + 1, x), {
                    'ccid':
                    'child_node_%s' % i,
                    'cid':
                    'child_node_%s_%s' % (i + 1, x),
                    'slot':
                    None,
                    'config': {},
                    'class': (ComponentContainerBase, {},
                              ('child_node_%s_%s' % (i + 1, x), None))
                })

    # Set everything up.
    page.handle_transaction()

    # root_node redraw should supersede following child redraws.
    page.root_node.redraw()
    page.child_node_3_1.redraw()

    page.handle_ajax_events()

    out = page.render()

    # Make sure the appropriate replace_component calls are all there. Almost exclusively JS, since HTML will be in the
    # root_node replace_component.
    for i in range(0, compo_depth):
        assert out.count(
            "epfl.replace_component('child_node_%s'" %
            (i + 1)) == out.count("epfl.replace_component('child_node_0'")
        for x in range(0, compo_width):
            assert out.count(
                "epfl.replace_component('child_node_%s_%s'" %
                (i + 1,
                 x)) == out.count("epfl.replace_component('child_node_0'")