source: products/quintagroup.plonegooglesitemaps/branches/blacklist/quintagroup/plonegooglesitemaps/filters.txt @ 2950

Last change on this file since 2950 was 2950, checked in by mylan, 14 years ago

#228: Fixed default behavior filter doctests

  • Property svn:eol-style set to native
File size: 7.3 KB
Line 
1
2Blackout filtering
3==================
4
5Sitemaps has option to filterout objects, which shouldn't present
6in a sitemap. This option is accessable in sitemap edit form
7and present as "Blackout entries" lines field.
8
9In earlier (<3.0.7 and <4.0.1) versions of the package the field
10filter-out objects only by its ids, and looks like:
11
12<pre>
13  index.html
14  index_html
15</pre>
16
17So all objects with "index.html" or "index_html" ids excluded
18from the sitemap.
19
20In the new versions of GoogleSitemaps filtering was remaked
21to pluggable architecture. Now filters are named mutli adapters.
22By default there are only two most useful filters - "id" and
23"path".
24
25Because of different filters can be used - new syntax applied
26to the "Blackout entries" field. Every record in the field
27should follow the spec:
28 
29  [<filter name>:]<filter arguments>
30
31By default (if no <filter name> specified) - "id" filter will
32be used. If <filter name> specified - system looking for
33<filter name> name  multiadapter to IBlackoutFilter interface.
34If such multiadapter was not found - it's ignored silently.
35
36
37Setup
38=====
39
40First, we must perform some setup. We use the testbrowser that is shipped
41with Five, as this provides proper Zope 2 integration. Most of the
42documentation, though, is in the underlying zope.testbrower package.
43
44    >>> from Products.Five.testbrowser import Browser
45    >>> browser = Browser()
46    >>> portal_url = self.portal.absolute_url()
47
48The following is useful when writing and debugging testbrowser tests. It lets
49us see all error messages in the error_log.
50
51    >>> self.portal.error_log._ignored_exceptions = ()
52
53With that in place, we can go to the portal front page and log in. We will
54do this using the default user from PloneTestCase:
55
56    >>> from Products.PloneTestCase.setup import portal_owner, default_password
57    >>> browser.open(portal_url)
58
59We have the login portlet, so let's use that.
60
61    >>> browser.open('http://nohost/plone/login_form')
62    >>> browser.getLink('Log in').click()
63    >>> browser.url
64    'http://nohost/plone/login_form'
65    >>> browser.getControl('Login Name').value = portal_owner
66    >>> browser.getControl('Password').value = default_password
67    >>> browser.getControl('Log in').click()
68    >>> "You are now logged in" in browser.contents
69    True
70    >>> "Login failed" in browser.contents
71    False
72    >>> browser.url
73    'http://nohost/plone/login_form'
74
75
76
77Functionality
78=============
79
80First create several documents for demonstrations.
81
82In the root of the portal
83
84    >>> self.addDocument(self.portal, "doc1", "Document 1 text")
85    >>> self.addDocument(self.portal, "doc2", "Document 2 text")
86
87And in the memeber's folder
88
89    >>> self.addDocument(self.folder, "doc1", "Member Document 1 text")
90    >>> self.addDocument(self.folder, "doc2", "Member Document 2 text")
91
92We need add sitemap, of corse, for demonstration.
93
94    >>> browser.open(portal_url + "/prefs_gsm_settings")
95    >>> browser.getControl('Add Content Sitemap').click()
96   
97Now we bring-up to edit form of the newly created content sitemap.
98We interested in two things: "Blackout entries" field must present
99in the form and it should be empty by default.
100   
101   
102    >>> file("/tmp/browser.0.html","wb").write(browser.contents)
103    >>> blackout_list = browser.getControl("Blackout entries")
104    >>> blackout_list
105    <Control name='blackout_list:lines' type='textarea'>
106    >>> blackout_list.value == ""
107    True
108    >>> save_button = browser.getControl("Save")
109    >>> save_button
110    <SubmitControl name='form.button.save' type='submit'>
111    >>> save_button.click()
112
113
114Click on "Save" button lead us to result sitemap view.
115
116    >>> print browser.contents
117    <?xml version="1.0" encoding=...
118
119
120After adding "Content Sitemap", "sitemap.xml" link will appear
121on "Settings" tab page of Plone Google Sitemap configlet.
122
123    >>> browser.open(portal_url + "/prefs_gsm_settings")
124    >>> smedit_link = browser.getLink('sitemap.xml')
125    >>> smedit_url = smedit_link.url
126
127This link lead to edit form of the newly created sitemap.xml.
128Also prepare view link to simplifier following demonstrations.
129
130    >>> smedit_url.endswith("sitemap.xml/edit")
131    True
132    >>> smview_url = smedit_url[:-5]
133
134
135No filters
136==========
137
138Resulted sitemap has no filters - all document should present in it.
139
140    >>> browser.open(smview_url)
141    >>> file("/tmp/browser.1.html","wb").write(browser.contents)
142    >>> no_filters_content = browser.contents
143
144Check if resulted page is real sitemap...
145
146    >>> print browser.contents
147    <?xml version="1.0" encoding=...
148
149
150To check urls, which pass filters - create regular expression...
151
152    >>> reloc = re.compile("<loc>%s([^\<]*)</loc>" % self.portal.absolute_url(), re.S)
153
154With help of reloc regular expression - check if all 4 documents + default
155front-page present in the sitemap without filters.
156
157    >>> no_filters_res = reloc.findall(no_filters_content)
158    >>> len(no_filters_res) == 5
159    True
160    >>> no_filters_res.sort()
161    >>> print "\n".join(no_filters_res)
162    /Members/test_user_1_/doc1
163    /Members/test_user_1_/doc2
164    /doc1
165    /doc2
166    /front-page
167
168
169Check "id" filter
170=================
171
172Go to the edit form of the sitemap and add "doc1"
173and "front-page" lines with "id:" prefix to the
174"Blackout entries" field.
175
176    >>> browser.open(smedit_url)
177    >>> filtercontrol = browser.getControl("Blackout entries")
178    >>> filtercontrol.value = "id:doc1\nid:front-page"
179    >>> browser.getControl("Save").click()
180    >>> id_filter_content = browser.contents
181
182As result - all "doc1" and "front-page" documents must be
183filtered-out from the sitemap.
184
185    >>> id_filter_res = reloc.findall(id_filter_content)
186    >>> len(id_filter_res) == 2
187    True
188    >>> id_filter_res.sort()
189    >>> print "\n".join(id_filter_res)
190    /Members/test_user_1_/doc2
191    /doc2
192
193
194Check "path" filter
195===================
196
197Suppouse we wont to filter-out doc2 of the test_user_1_'s (but
198not from the portal root) and the front-page from the portal root.
199
200    >>> browser.open(smedit_url)
201    >>> filtercontrol = browser.getControl("Blackout entries")
202    >>> filtercontrol.value = "path:/Members/test_user_1_/doc2\npath:/front-page"
203    >>> browser.getControl("Save").click()
204    >>> path_filter_content = browser.contents
205
206As result - "doc2" of the pointed member and "front-page" documents
207must be filtered-out from the sitemap.
208
209    >>> path_filter_res = reloc.findall(path_filter_content)
210    >>> len(path_filter_res) == 3
211    True
212    >>> path_filter_res.sort()
213    >>> print "\n".join(path_filter_res)
214    /Members/test_user_1_/doc1
215    /doc1
216    /doc2
217
218
219Check default filter
220====================
221
222Lets check what filter should be used for old-feshion filters
223(without any filter name prefixes)?
224
225Go to the edit form of the sitemap and add "doc1" and front-page
226lines without any filter name prefix to the "Blackout entries"
227field.
228
229    >>> browser.open(portal_url + "/sitemap.xml/edit")
230    >>> filtercontrol = browser.getControl("Blackout entries")
231    >>> filtercontrol.value = "doc1\nfront-page"
232    >>> browser.getControl("Save").click()
233    >>> default_filter_content = browser.contents
234
235By default "id" filter must be used, so all "doc1" and "front-page"
236objects must be filtered-out from the sitemap.
237
238    >>> default_filter_res = reloc.findall(default_filter_content)
239    >>> len(default_filter_res) == 2
240    True
241    >>> default_filter_res.sort()
242    >>> print "\n".join(default_filter_res)
243    /Members/test_user_1_/doc2
244    /doc2
245
246
Note: See TracBrowser for help on using the repository browser.