[3129] | 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 | Because add-on themes or products may remove or hide the login portlet, this test will use the login form that comes with plone. |
---|
| 34 | |
---|
| 35 | >>> browser.open(portal_url + '/login_form') |
---|
| 36 | >>> browser.getControl(name='__ac_name').value = portal_owner |
---|
| 37 | >>> browser.getControl(name='__ac_password').value = default_password |
---|
| 38 | >>> browser.getControl(name='submit').click() |
---|
| 39 | |
---|
| 40 | Here, we set the value of the fields on the login form and then simulate a |
---|
| 41 | submit click. We then ensure that we get the friendly logged-in message: |
---|
| 42 | |
---|
| 43 | >>> "You are now logged in" in browser.contents |
---|
| 44 | True |
---|
| 45 | |
---|
| 46 | Finally, let's return to the front page of our site before continuing |
---|
| 47 | |
---|
| 48 | >>> browser.open(portal_url) |
---|
| 49 | |
---|
| 50 | -*- extra stuff goes here -*- |
---|
| 51 | The Bounty Program Submission content type |
---|
| 52 | =============================== |
---|
| 53 | |
---|
| 54 | In this section we are tesing the Bounty Program Submission content type by performing |
---|
| 55 | basic operations like adding, updadating and deleting Bounty Program Submission content |
---|
| 56 | items. |
---|
| 57 | |
---|
| 58 | Adding a new Bounty Program Submission content item |
---|
| 59 | -------------------------------- |
---|
| 60 | |
---|
| 61 | We use the 'Add new' menu to add a new content item. |
---|
| 62 | |
---|
| 63 | >>> browser.getLink('Add new').click() |
---|
| 64 | |
---|
| 65 | Then we select the type of item we want to add. In this case we select |
---|
| 66 | 'Bounty Program Submission' and click the 'Add' button to get to the add form. |
---|
| 67 | |
---|
| 68 | >>> browser.getControl('Bounty Program Submission').click() |
---|
| 69 | >>> browser.getControl(name='form.button.Add').click() |
---|
| 70 | >>> 'Bounty Program Submission' in browser.contents |
---|
| 71 | True |
---|
| 72 | |
---|
| 73 | Now we fill the form and submit it. |
---|
| 74 | |
---|
| 75 | >>> browser.getControl(name='title').value = 'Bounty Program Submission Sample' |
---|
| 76 | >>> browser.getControl('Save').click() |
---|
| 77 | >>> 'Changes saved' in browser.contents |
---|
| 78 | True |
---|
| 79 | |
---|
| 80 | And we are done! We added a new 'Bounty Program Submission' content item to the portal. |
---|
| 81 | |
---|
| 82 | Updating an existing Bounty Program Submission content item |
---|
| 83 | --------------------------------------- |
---|
| 84 | |
---|
| 85 | Let's click on the 'edit' tab and update the object attribute values. |
---|
| 86 | |
---|
| 87 | >>> browser.getLink('Edit').click() |
---|
| 88 | >>> browser.getControl(name='title').value = 'New Bounty Program Submission Sample' |
---|
| 89 | >>> browser.getControl('Save').click() |
---|
| 90 | |
---|
| 91 | We check that the changes were applied. |
---|
| 92 | |
---|
| 93 | >>> 'Changes saved' in browser.contents |
---|
| 94 | True |
---|
| 95 | >>> 'New Bounty Program Submission Sample' in browser.contents |
---|
| 96 | True |
---|
| 97 | |
---|
| 98 | Removing a/an Bounty Program Submission content item |
---|
| 99 | -------------------------------- |
---|
| 100 | |
---|
| 101 | If we go to the home page, we can see a tab with the 'New Bounty Program Submission |
---|
| 102 | Sample' title in the global navigation tabs. |
---|
| 103 | |
---|
| 104 | >>> browser.open(portal_url) |
---|
| 105 | >>> 'New Bounty Program Submission Sample' in browser.contents |
---|
| 106 | True |
---|
| 107 | |
---|
| 108 | Now we are going to delete the 'New Bounty Program Submission Sample' object. First we |
---|
| 109 | go to the contents tab and select the 'New Bounty Program Submission Sample' for |
---|
| 110 | deletion. |
---|
| 111 | |
---|
| 112 | >>> browser.getLink('Contents').click() |
---|
| 113 | >>> browser.getControl('New Bounty Program Submission Sample').click() |
---|
| 114 | |
---|
| 115 | We click on the 'Delete' button. |
---|
| 116 | |
---|
| 117 | >>> browser.getControl('Delete').click() |
---|
| 118 | >>> 'Item(s) deleted' in browser.contents |
---|
| 119 | True |
---|
| 120 | |
---|
| 121 | So, if we go back to the home page, there is no longer a 'New Bounty Program Submission |
---|
| 122 | Sample' tab. |
---|
| 123 | |
---|
| 124 | >>> browser.open(portal_url) |
---|
| 125 | >>> 'New Bounty Program Submission Sample' in browser.contents |
---|
| 126 | False |
---|
| 127 | |
---|
| 128 | Adding a new Bounty Program Submission content item as contributor |
---|
| 129 | ------------------------------------------------ |
---|
| 130 | |
---|
| 131 | Not only site managers are allowed to add Bounty Program Submission content items, but |
---|
| 132 | also site contributors. |
---|
| 133 | |
---|
| 134 | Let's logout and then login as 'contributor', a portal member that has the |
---|
| 135 | contributor role assigned. |
---|
| 136 | |
---|
| 137 | >>> browser.getLink('Log out').click() |
---|
| 138 | >>> browser.open(portal_url + '/login_form') |
---|
| 139 | >>> browser.getControl(name='__ac_name').value = 'contributor' |
---|
| 140 | >>> browser.getControl(name='__ac_password').value = default_password |
---|
| 141 | >>> browser.getControl(name='submit').click() |
---|
| 142 | >>> browser.open(portal_url) |
---|
| 143 | |
---|
| 144 | We use the 'Add new' menu to add a new content item. |
---|
| 145 | |
---|
| 146 | >>> browser.getLink('Add new').click() |
---|
| 147 | |
---|
| 148 | We select 'Bounty Program Submission' and click the 'Add' button to get to the add form. |
---|
| 149 | |
---|
| 150 | >>> browser.getControl('Bounty Program Submission').click() |
---|
| 151 | >>> browser.getControl(name='form.button.Add').click() |
---|
| 152 | >>> 'Bounty Program Submission' in browser.contents |
---|
| 153 | True |
---|
| 154 | |
---|
| 155 | Now we fill the form and submit it. |
---|
| 156 | |
---|
| 157 | >>> browser.getControl(name='title').value = 'Bounty Program Submission Sample' |
---|
| 158 | >>> browser.getControl('Save').click() |
---|
| 159 | >>> 'Changes saved' in browser.contents |
---|
| 160 | True |
---|
| 161 | |
---|
| 162 | Done! We added a new Bounty Program Submission content item logged in as contributor. |
---|
| 163 | |
---|
| 164 | Finally, let's login back as manager. |
---|
| 165 | |
---|
| 166 | >>> browser.getLink('Log out').click() |
---|
| 167 | >>> browser.open(portal_url + '/login_form') |
---|
| 168 | >>> browser.getControl(name='__ac_name').value = portal_owner |
---|
| 169 | >>> browser.getControl(name='__ac_password').value = default_password |
---|
| 170 | >>> browser.getControl(name='submit').click() |
---|
| 171 | >>> browser.open(portal_url) |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | |
---|