Exemplo n.º 1
0
def test_table_form():
    """Base tests : values and behavior.
    FIXME : this needs more tests.
    """
    request = TestRequest()
    form = TableForm(content, request)
    form.tableFields = Fields(*fields.values())
    form.actions = Actions(Action(u'Do not use'))

    assert verifyObject(ITableForm, form)

    # We make sure getItems return the right amount of items.
    # This is used by ``updateLines`` to create widgets for all lines. Those
    # are have a line prefix:
    assert len(form.getItems()) == 3

    # We can proceed.
    form.update()
    form.updateForm()

    assert len(form.lines) == len(form.lineWidgets) == 3
    assert [line.prefix for line in form.lines] == [
        'form.line-0', 'form.line-1', 'form.line-2']
    html = form.render()

    # The result should contain HTML base tags
    assert '<html>' in html

    html = etree.fromstring(html)

    # table headers
    assert [elt.text for elt in html.findall('.//table/thead//th')] == [
            None, 'age', 'name']
Exemplo n.º 2
0
def test_batching():
    """Base batching test. The Batcher is tested in ``dolmen.batch``.
    We simply need to make sure we have plugged it correctly and that
    it gets the right values out of the form.
    """
    request = TestRequest()
    form = TableForm(content, request)

    # The table can generate a batch out-of-the-box.
    # However, that capability has to be activated.
    form = TableForm(content, request)
    form.createBatch = True

    # @ testing conf.
    # To be able to compute the URL, we need to define a publication root
    directlyProvides(form, IPublicationRoot)

    # Now, we can test it:
    form.batchSize = 1
    form.update()
    form.updateForm()
    assert form.batcher.size == 1
    assert form.batcher.url == 'http://localhost'