Op 05-06-11 17:57, Héctor Velarde schreef:
I'm writing a functional test for a content type that has, among other,
the following fields:

StringField('role',
widget=MasterSelectWidget(
label=_(u'Role'),
slave_fields=(
{'name': 'record_number',
'action': 'hide',
'hide_values': (READER, )},
),
),
vocabulary=DisplayList((
(READER, 'Reader'),
(JUDGE, 'Judge'),
)),
),

StringField('record',
widget=StringWidget(
label=_(u'Record'),
),
),

DataGridField('students',
required=True,
columns=('register', 'name'),
widget=DataGridWidget(
auto_insert=False,
label=_(u'Students'),
columns={
'register': Column(u'Register'),
'name': Column(u'Name'),
},
),
allow_empty_rows=False,
allow_oddeven=True,
),

in the first part of my test I create the content type, and give a value
to "role" and "students":

 >>> add_link = browser.getLink(id='examiner')
 >>> add_link.click()
 >>> browser.getControl(name='title').value = 'Test'
 >>> browser.getControl(name='role').getControl('Reader').selected = True
 >>> browser.getControl(name='students.register:records').value = '12345'
 >>> browser.getControl(name='students.name:records').value = 'John Doe'
 >>> >>> browser.getControl(name='form.button.save').click()
 >>> 'test' in folder.objectIds()
True

in the second part I want to edit the of "role" to test a validator that
enforces "record" is not empty:

 >>> url = '%s/test/edit' % folder.absolute_url()
 >>> browser.open(url)
 >>> browser.getControl(name='role').getControl('Judge').selected = True
 >>> browser.getControl(name='form.button.save').click()
 >>> 'You need to specify a record number' in browser.contents
True
 >>> browser.getControl(name='record').value = '12345'
 >>> browser.getControl(name='form.button.save').click()
 >>> browser.contents
 >>> 'Changes saved.' in browser.contents
True

the last test fails because, at this point, the DataGridField records,
"register" and "name", are empty and I don't know why.

do DataGridFields are populated using JavaScript? do I need to populate
again the records on the field? how can I test something like this?

Javascript is used, but datagrids should work fine without it, AFAIK.

The tests look fine at first glance. You may want to have a look at the tests in Products.DataGridField itself to see if it is handled differently there.

Also, I usually add a line in the doctests to write the browser contents to a file and then look at it in a real browser, like this:

open('/tmp/test.html', 'w').write(browser.contents)

A good spot may be right before you hit the Save button; perhaps add that line in both cases (once with test2.html).


--
Maurits van Rees
Web App Programmer at Zest Software: http://zestsoftware.nl
Personal website: http://maurits.vanrees.org/

_______________________________________________
Product-Developers mailing list
[email protected]
https://lists.plone.org/mailman/listinfo/plone-product-developers

Reply via email to