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('Save').click() |
---|
85 | >>> 'Changes saved' in browser.contents |
---|
86 | True |
---|
87 | |
---|
88 | And we are done! We added a new 'GSpreadsheet' content item to the portal. |
---|
89 | |
---|
90 | Updating an existing GSpreadsheet content item |
---|
91 | --------------------------------------- |
---|
92 | |
---|
93 | Let's click on the 'edit' tab and update the object attribute values. |
---|
94 | |
---|
95 | >>> browser.getLink('Edit').click() |
---|
96 | >>> browser.getControl(name='title').value = 'New GSpreadsheet Sample' |
---|
97 | >>> browser.getControl(name='spreadsheet_id').value = 'id1' |
---|
98 | >>> browser.getControl(name='worksheet_id').value = 'od6' |
---|
99 | >>> browser.getControl('Save').click() |
---|
100 | |
---|
101 | We check that the changes were applied. |
---|
102 | |
---|
103 | >>> 'Changes saved' in browser.contents |
---|
104 | True |
---|
105 | >>> 'New GSpreadsheet Sample' in browser.contents |
---|
106 | True |
---|
107 | |
---|
108 | Removing a/an GSpreadsheet content item |
---|
109 | -------------------------------- |
---|
110 | |
---|
111 | If we go to the home page, we can see a tab with the 'New GSpreadsheet |
---|
112 | Sample' title in the global navigation tabs. |
---|
113 | |
---|
114 | >>> browser.open(portal_url) |
---|
115 | >>> 'New GSpreadsheet Sample' in browser.contents |
---|
116 | True |
---|
117 | |
---|
118 | Now we are going to delete the 'New GSpreadsheet Sample' object. First we |
---|
119 | go to the contents tab and select the 'New GSpreadsheet Sample' for |
---|
120 | deletion. |
---|
121 | |
---|
122 | >>> browser.getLink('Contents').click() |
---|
123 | >>> browser.getControl('New GSpreadsheet Sample').click() |
---|
124 | |
---|
125 | We click on the 'Delete' button. |
---|
126 | |
---|
127 | >>> browser.getControl('Delete').click() |
---|
128 | >>> 'Item(s) deleted' in browser.contents |
---|
129 | True |
---|
130 | |
---|
131 | So, if we go back to the home page, there is no longer a 'New GSpreadsheet |
---|
132 | Sample' tab. |
---|
133 | |
---|
134 | >>> browser.open(portal_url) |
---|
135 | >>> 'New GSpreadsheet Sample' in browser.contents |
---|
136 | False |
---|
137 | |
---|
138 | Adding a new GSpreadsheet content item as contributor |
---|
139 | ------------------------------------------------ |
---|
140 | |
---|
141 | Not only site managers are allowed to add GSpreadsheet content items, but |
---|
142 | also site contributors. |
---|
143 | |
---|
144 | Let's logout and then login as 'contributor', a portal member that has the |
---|
145 | contributor role assigned. |
---|
146 | |
---|
147 | >>> browser.getLink('Log out').click() |
---|
148 | >>> browser.open(portal_url) |
---|
149 | >>> browser.getLink('Log in').click() |
---|
150 | >>> browser.getControl(name='__ac_name').value = 'contributor' |
---|
151 | >>> browser.getControl(name='__ac_password').value = default_password |
---|
152 | >>> browser.getControl(name='submit').click() |
---|
153 | >>> browser.open(portal_url) |
---|
154 | |
---|
155 | We use the 'Add new' menu to add a new content item. |
---|
156 | |
---|
157 | >>> browser.getLink('Add new').click() |
---|
158 | |
---|
159 | We select 'GSpreadsheet' and click the 'Add' button to get to the add form. |
---|
160 | |
---|
161 | >>> browser.getControl('GSpreadsheet').click() |
---|
162 | >>> browser.getControl(name='form.button.Add').click() |
---|
163 | >>> 'GSpreadsheet' in browser.contents |
---|
164 | True |
---|
165 | |
---|
166 | Now we fill the form and submit it. |
---|
167 | |
---|
168 | >>> browser.getControl(name='title').value = 'GSpreadsheet Sample' |
---|
169 | >>> browser.getControl(name='spreadsheet_id').value = 'sp_id1' |
---|
170 | >>> browser.getControl(name='worksheet_id').value = 'od6' |
---|
171 | >>> browser.getControl('Save').click() |
---|
172 | >>> 'Changes saved' in browser.contents |
---|
173 | True |
---|
174 | |
---|
175 | Done! We added a new GSpreadsheet content item logged in as contributor. |
---|
176 | |
---|
177 | Finally, let's login back as manager. |
---|
178 | |
---|
179 | >>> browser.getLink('Log out').click() |
---|
180 | >>> browser.open(portal_url) |
---|
181 | >>> browser.getLink('Log in').click() |
---|
182 | >>> browser.getControl(name='__ac_name').value = portal_owner |
---|
183 | >>> browser.getControl(name='__ac_password').value = default_password |
---|
184 | >>> browser.getControl(name='submit').click() |
---|
185 | >>> browser.open(portal_url) |
---|