source: products/quintagroup.gdocs.spreadsheet/trunk/quintagroup/gdocs/spreadsheet/README.txt @ 2756

Last change on this file since 2756 was 2756, checked in by liebster, 14 years ago

CleanUp? code

File size: 8.1 KB
Line 
1Introduction
2============
3
4This is a full-blown functional test. The emphasis here is on testing what
5the user may input and see, and the system is largely tested as a black box.
6We use PloneTestCase to set up this test as well, so we have a full Plone site
7to play with. We *can* inspect the state of the portal, e.g. using
8self.portal and self.folder, but it is often frowned upon since you are not
9treating the system as a black box. Also, if you, for example, log in or set
10roles using calls like self.setRoles(), these are not reflected in the test
11browser, which runs as a separate session.
12
13Being a doctest, we can tell a story here.
14
15First, we must perform some setup. We use the testbrowser that is shipped
16with Five, as this provides proper Zope 2 integration. Most of the
17documentation, 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
23The following is useful when writing and debugging testbrowser tests. It lets
24us see all error messages in the error_log.
25
26    >>> self.portal.error_log._ignored_exceptions = ()
27
28With that in place, we can go to the portal front page and log in. We will
29do 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
35We 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
42Here, we set the value of the fields on the login form and then simulate a
43submit click.
44
45We then test that we are still on the portal front page:
46
47    >>> browser.url == portal_url
48    True
49
50And 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 -*-
57The GSpreadsheet content type
58===============================
59
60In this section we are tesing the GSpreadsheet content type by performing
61basic operations like adding, updadating and deleting GSpreadsheet content
62items.
63
64Adding a new GSpreadsheet content item
65--------------------------------
66
67We use the 'Add new' menu to add a new content item.
68
69    >>> browser.getLink('Add new').click()
70
71Then 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
79Now 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
92And we are done! We added a new 'GSpreadsheet' content item to the portal.
93
94Updating an existing GSpreadsheet content item
95---------------------------------------
96
97Let'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
113We 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
122Let'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
130We 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
137Removing a/an GSpreadsheet content item
138--------------------------------
139
140If we go to the home page, we can see a tab with the 'New GSpreadsheet
141Sample' title in the global navigation tabs.
142
143    >>> browser.open(portal_url)
144    >>> 'New GSpreadsheet Sample' in browser.contents
145    True
146
147Now we are going to delete the 'New GSpreadsheet Sample' object. First we
148go to the contents tab and select the 'New GSpreadsheet Sample' for
149deletion.
150
151    >>> browser.getLink('Contents').click()
152    >>> browser.getControl('New GSpreadsheet Sample').click()
153
154We click on the 'Delete' button.
155
156    >>> browser.getControl('Delete').click()
157    >>> 'Item(s) deleted' in browser.contents
158    True
159
160So, if we go back to the home page, there is no longer a 'New GSpreadsheet
161Sample' tab.
162
163    >>> browser.open(portal_url)
164    >>> 'New GSpreadsheet Sample' in browser.contents
165    False
166
167Adding a new GSpreadsheet content item as contributor
168------------------------------------------------
169
170Not only site managers are allowed to add GSpreadsheet content items, but
171also site contributors.
172
173Let's logout and then login as 'contributor', a portal member that has the
174contributor 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
184We use the 'Add new' menu to add a new content item.
185
186    >>> browser.getLink('Add new').click()
187
188We 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
195Now 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
204Done! We added a new GSpreadsheet content item logged in as contributor.
205
206Finally, 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)
Note: See TracBrowser for help on using the repository browser.