[1494] | 1 | Introduction |
---|
| 2 | ============ |
---|
| 3 | |
---|
| 4 | This is a full-blown functional test. The emphasis here is on testing what |
---|
| 5 | the user may input and see, and the system is largely tested as a black box. |
---|
| 6 | We use PloneTestCase to set up this test as well, so we have a full Plone site |
---|
| 7 | to play with. We *can* inspect the state of the portal, e.g. using |
---|
| 8 | self.portal and self.folder, but it is often frowned upon since you are not |
---|
| 9 | treating the system as a black box. Also, if you, for example, log in or set |
---|
| 10 | roles using calls like self.setRoles(), these are not reflected in the test |
---|
| 11 | browser, which runs as a separate session. |
---|
| 12 | |
---|
| 13 | Being a doctest, we can tell a story here. |
---|
| 14 | |
---|
| 15 | First, we must perform some setup. We use the testbrowser that is shipped |
---|
| 16 | with Five, as this provides proper Zope 2 integration. Most of the |
---|
| 17 | documentation, though, is in the underlying zope.testbrower package. |
---|
| 18 | |
---|
| 19 | >>> from Products.Five.testbrowser import Browser |
---|
| 20 | >>> browser = Browser() |
---|
| 21 | >>> portal_url = self.portal.absolute_url() |
---|
| 22 | |
---|
| 23 | The following is useful when writing and debugging testbrowser tests. It lets |
---|
| 24 | us see all error messages in the error_log. |
---|
| 25 | |
---|
| 26 | >>> self.portal.error_log._ignored_exceptions = () |
---|
| 27 | |
---|
| 28 | With that in place, we can go to the portal front page and log in. We will |
---|
| 29 | do this using the default user from PloneTestCase: |
---|
| 30 | |
---|
| 31 | >>> from Products.PloneTestCase.setup import portal_owner, default_password |
---|
| 32 | |
---|
| 33 | >>> browser.open(portal_url) |
---|
| 34 | |
---|
| 35 | We have the login portlet, so let's use that. |
---|
| 36 | |
---|
| 37 | >>> browser.getControl(name='__ac_name').value = portal_owner |
---|
| 38 | >>> browser.getControl(name='__ac_password').value = default_password |
---|
| 39 | >>> browser.getControl(name='submit').click() |
---|
| 40 | |
---|
| 41 | Here, we set the value of the fields on the login form and then simulate a |
---|
| 42 | submit click. |
---|
| 43 | |
---|
| 44 | We then test that we are still on the portal front page: |
---|
| 45 | >>> browser.url == portal_url |
---|
| 46 | True |
---|
| 47 | |
---|
| 48 | And we ensure that we get the friendly logged-in message: |
---|
| 49 | |
---|
| 50 | >>> "You are now logged in" in browser.contents |
---|
| 51 | True |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | -*- extra stuff goes here -*- |
---|
| 55 | The my tests |
---|
| 56 | =============================== |
---|
| 57 | |
---|