[Grok-dev] Suggested contents for a skeleton functional doctest

Luciano Ramalho luciano at ramalho.org
Sat Aug 11 02:08:30 EDT 2007


A fresh grokproject generated sample app passes the doctest below the ###.

The doctest shows basic operation of the test browser, and also how to
instantiate and exercise the app.

I think including a test like this in grokproject will make it much
easier for beginning grok users to get in the habit of writing
functional tests.

Regards,

Luciano


###
Create an instance of the app::

  >>> from zope.testbrowser.testing import Browser
  >>> browser = Browser()
  >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
  >>> browser.handleErrors = False
  >>> browser.open('http://localhost:8080/')
  >>> browser.getControl('Application').displayValue = ['sample.app.Sample']
  >>> browser.getControl('Name').value = 'sample1'
  >>> browser.getControl('Add').click()

Navigate to the index page and verify it's contents::

  >>> browser.getLink('sample').click()
  >>> "Your Grok application is up and running." in browser.contents
  True

The default Grok app is also a container, but initially it's empty::

  >>> root = getRootFolder()
  >>> sample = root['sample1']
  >>> print sample.keys()
  <OOBTreeItems object at ...>
  >>> print len(sample.keys())
  0

To test your sample app with this doctest, run::

  ~/sample$ bin/test


More information about the Grok-dev mailing list