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.getLink('Log in').click() |
---|
38 | >>> browser.getControl(name='__ac_name').value = portal_owner |
---|
39 | >>> browser.getControl(name='__ac_password').value = default_password |
---|
40 | >>> browser.getControl(name='submit').click() |
---|
41 | |
---|
42 | Here, we set the value of the fields on the login form and then simulate a |
---|
43 | submit click. |
---|
44 | |
---|
45 | We then test that we are still on the portal front page: |
---|
46 | |
---|
47 | >>> browser.url == portal_url |
---|
48 | True |
---|
49 | |
---|
50 | And we ensure that we get the friendly logged-in message: |
---|
51 | |
---|
52 | >>> "You are now logged in" in browser.contents |
---|
53 | True |
---|
54 | |
---|
55 | |
---|
56 | -*- extra stuff goes here -*- |
---|
57 | The GSpreadsheet content type |
---|
58 | =============================== |
---|
59 | |
---|
60 | In this section we are tesing the GSpreadsheet content type by performing |
---|
61 | basic operations like adding, updadating and deleting GSpreadsheet content |
---|
62 | items. |
---|
63 | |
---|
64 | Adding a new GSpreadsheet content item |
---|
65 | -------------------------------- |
---|
66 | |
---|
67 | We use the 'Add new' menu to add a new content item. |
---|
68 | |
---|
69 | >>> browser.getLink('Add new').click() |
---|
70 | |
---|
71 | Then we select the type of item we want to add. In this case we select |
---|
72 | 'GSpreadsheet' and click the 'Add' button to get to the add form. |
---|
73 | |
---|
74 | >>> browser.getControl('GSpreadsheet').click() |
---|
75 | >>> browser.getControl(name='form.button.Add').click() |
---|
76 | >>> 'GSpreadsheet' in browser.contents |
---|
77 | True |
---|
78 | |
---|
79 | Now we fill the form and submit it. |
---|
80 | |
---|
81 | >>> browser.getControl(name='title').value = 'GSpreadsheet Sample' |
---|
82 | >>> browser.getControl(name='spreadsheet_id').value = 'sp_id1' |
---|
83 | >>> browser.getControl(name='worksheet_id').value = 'od6' |
---|
84 | >>> browser.getControl(name='order_columns.column_key:records',index=0).value |
---|
85 | [] |
---|
86 | >>> browser.getControl(name='order_columns.column_title:records', index=0).value |
---|
87 | '' |
---|
88 | >>> browser.getControl('Save').click() |
---|
89 | >>> 'Changes saved' in browser.contents |
---|
90 | True |
---|
91 | |
---|
92 | And we are done! We added a new 'GSpreadsheet' content item to the portal. |
---|
93 | |
---|
94 | Updating an existing GSpreadsheet content item |
---|
95 | --------------------------------------- |
---|
96 | |
---|
97 | Let's click on the 'edit' tab and update the object attribute values. |
---|
98 | |
---|
99 | >>> browser.getLink('Edit').click() |
---|
100 | >>> browser.getControl(name='title').value = 'New GSpreadsheet Sample' |
---|
101 | >>> browser.getControl(name='spreadsheet_id').value = 'id1' |
---|
102 | >>> browser.getControl(name='worksheet_id').value = 'od6' |
---|
103 | >>> browser.getControl(name='order_columns.orderindex_:records',index=0).value = '1' |
---|
104 | >>> browser.getControl(name='order_columns.column_key:records',index=0).value = ['col1'] |
---|
105 | >>> browser.getControl(name='order_columns.column_title:records', index=0).value = 'Title 1' |
---|
106 | >>> browser.getControl('Save').click() |
---|
107 | >>> browser.getLink('Edit').click() |
---|
108 | >>> browser.getControl(name='order_columns.orderindex_:records',index=1).value = '2' |
---|
109 | >>> browser.getControl(name='order_columns.column_key:records',index=1).value = ['col2'] |
---|
110 | >>> browser.getControl(name='order_columns.column_title:records', index=1).value = 'Title 2' |
---|
111 | >>> browser.getControl('Save').click() |
---|
112 | |
---|
113 | We check that the changes were applied. |
---|
114 | |
---|
115 | >>> 'Changes saved' in browser.contents |
---|
116 | True |
---|
117 | >>> 'New GSpreadsheet Sample' in browser.contents |
---|
118 | True |
---|
119 | >>> browser.contents |
---|
120 | '...<table id="sshwsh"><tr><th>Title 1</th><th>Title 2</th></tr><tr><td>11</td><td>12</td></tr>\n<tr><td>21</td><td>22</td></tr>\n<tr><td>31</td><td>32</td></tr>\n<tr><td>41</td><td>42</td></tr>\n<tr><td>51</td><td>52</td></tr>\n</table>...' |
---|
121 | |
---|
122 | Let's click on the 'edit' tab and update the object attribute values. |
---|
123 | |
---|
124 | >>> browser.getLink('Edit').click() |
---|
125 | >>> browser.getControl(name='order_columns.orderindex_:records',index=1).value = '2' |
---|
126 | >>> browser.getControl(name='order_columns.column_key:records',index=1).value = ['col3'] |
---|
127 | >>> browser.getControl(name='order_columns.column_title:records', index=1).value = 'Title 3' |
---|
128 | >>> browser.getControl('Save').click() |
---|
129 | |
---|
130 | We check that the changes were applied. |
---|
131 | |
---|
132 | >>> 'Changes saved' in browser.contents |
---|
133 | True |
---|
134 | >>> browser.contents |
---|
135 | '...<table id="sshwsh"><tr><th>Title 1</th><th>Title 3</th></tr><tr><td>11</td><td>13</td></tr>\n<tr><td>21</td><td>23</td></tr>\n<tr><td>31</td><td>33</td></tr>\n<tr><td>41</td><td>43</td></tr>\n<tr><td>51</td><td>53</td></tr>\n</table>...' |
---|
136 | |
---|
137 | Removing a/an GSpreadsheet content item |
---|
138 | -------------------------------- |
---|
139 | |
---|
140 | If we go to the home page, we can see a tab with the 'New GSpreadsheet |
---|
141 | Sample' title in the global navigation tabs. |
---|
142 | |
---|
143 | >>> browser.open(portal_url) |
---|
144 | >>> 'New GSpreadsheet Sample' in browser.contents |
---|
145 | True |
---|
146 | |
---|
147 | Now we are going to delete the 'New GSpreadsheet Sample' object. First we |
---|
148 | go to the contents tab and select the 'New GSpreadsheet Sample' for |
---|
149 | deletion. |
---|
150 | |
---|
151 | >>> browser.getLink('Contents').click() |
---|
152 | >>> browser.getControl('New GSpreadsheet Sample').click() |
---|
153 | |
---|
154 | We click on the 'Delete' button. |
---|
155 | |
---|
156 | >>> browser.getControl('Delete').click() |
---|
157 | >>> 'Item(s) deleted' in browser.contents |
---|
158 | True |
---|
159 | |
---|
160 | So, if we go back to the home page, there is no longer a 'New GSpreadsheet |
---|
161 | Sample' tab. |
---|
162 | |
---|
163 | >>> browser.open(portal_url) |
---|
164 | >>> 'New GSpreadsheet Sample' in browser.contents |
---|
165 | False |
---|
166 | |
---|
167 | Adding a new GSpreadsheet content item as contributor |
---|
168 | ------------------------------------------------ |
---|
169 | |
---|
170 | Not only site managers are allowed to add GSpreadsheet content items, but |
---|
171 | also site contributors. |
---|
172 | |
---|
173 | Let's logout and then login as 'contributor', a portal member that has the |
---|
174 | contributor role assigned. |
---|
175 | |
---|
176 | >>> browser.getLink('Log out').click() |
---|
177 | >>> browser.open(portal_url) |
---|
178 | >>> browser.getLink('Log in').click() |
---|
179 | >>> browser.getControl(name='__ac_name').value = 'contributor' |
---|
180 | >>> browser.getControl(name='__ac_password').value = default_password |
---|
181 | >>> browser.getControl(name='submit').click() |
---|
182 | >>> browser.open(portal_url) |
---|
183 | |
---|
184 | We use the 'Add new' menu to add a new content item. |
---|
185 | |
---|
186 | >>> browser.getLink('Add new').click() |
---|
187 | |
---|
188 | We select 'GSpreadsheet' and click the 'Add' button to get to the add form. |
---|
189 | |
---|
190 | >>> browser.getControl('GSpreadsheet').click() |
---|
191 | >>> browser.getControl(name='form.button.Add').click() |
---|
192 | >>> 'GSpreadsheet' in browser.contents |
---|
193 | True |
---|
194 | |
---|
195 | Now we fill the form and submit it. |
---|
196 | |
---|
197 | >>> browser.getControl(name='title').value = 'GSpreadsheet Sample' |
---|
198 | >>> browser.getControl(name='spreadsheet_id').value = 'sp_id1' |
---|
199 | >>> browser.getControl(name='worksheet_id').value = 'od6' |
---|
200 | >>> browser.getControl('Save').click() |
---|
201 | >>> 'Changes saved' in browser.contents |
---|
202 | True |
---|
203 | |
---|
204 | Done! We added a new GSpreadsheet content item logged in as contributor. |
---|
205 | |
---|
206 | Finally, let's login back as manager. |
---|
207 | |
---|
208 | >>> browser.getLink('Log out').click() |
---|
209 | >>> browser.open(portal_url) |
---|
210 | >>> browser.getLink('Log in').click() |
---|
211 | >>> browser.getControl(name='__ac_name').value = portal_owner |
---|
212 | >>> browser.getControl(name='__ac_password').value = default_password |
---|
213 | >>> browser.getControl(name='submit').click() |
---|
214 | >>> browser.open(portal_url) |
---|