source: products/quintagroup.transmogrifier/trunk/quintagroup/transmogrifier/portlets.txt @ 1589

Last change on this file since 1589 was 1589, checked in by mylan, 11 years ago

Added tests of 'purge' option for portelts exporting section

File size: 6.7 KB
Line 
1Portlets exporter and importer sections
2=======================================
3
4Portlets exporter and importer sections are used to migrate Plone 3 contextual
5portlet assignments and blacklist settings.
6The portlets exporter section blueprint name is
7``quintagroup.transmogrifier.portletsexporter`` and importer section blueprint
8name is ``quintagroup.transmogrifier.portletsimporter``.
9
10Portlet assignments and blacklists are stored in XML format. Both sections need
11relative path to the object with portlets assigned and importer also needs XML
12data for updating them.
13
14Both sections has ``path-key`` option which specifies key in item where path to
15object is stored (``_path`` is default) and ``files-key`` option that gives
16key where XML data will be or is stored.
17
18>>> import pprint
19>>> portlets = """
20... [transmogrifier]
21... pipeline =
22...     portletssource
23...     portletsexporter
24...     printer
25...     dataprinter
26...     portletsimporter
27...     
28... [portletssource]
29... blueprint = quintagroup.transmogrifier.tests.portletssource
30...
31... [portletsexporter]
32... blueprint = quintagroup.transmogrifier.portletsexporter
33...
34... [printer]
35... blueprint = collective.transmogrifier.sections.tests.pprinter
36...
37... [dataprinter]
38... blueprint = quintagroup.transmogrifier.tests.dataprinter
39... print =
40...     _files
41...     portlets
42...     data
43...
44... [portletsimporter]
45... blueprint = quintagroup.transmogrifier.portletsimporter
46... files-key = files
47... """
48>>> registerConfig(u'quintagroup.transmogrifier.tests.portlets', portlets)
49>>> transmogrifier(u'quintagroup.transmogrifier.tests.portlets') # doctest: +ELLIPSIS, +REPORT_NDIFF
50{}
51{'_path': 'not/existing/bar'}
52{'_path': 'spam/eggs/notassignable'}
53{'_files': {'portlets': {'data': ...
54                         'name': '.portlets.xml'}},
55 '_path': 'assignable'}
56<?xml version="1.0" encoding="utf-8"?>
57<portlets>
58  <assignment category="context" key="/assignable" manager="plone.leftcolumn" name="rss" type="portlets.rss">
59    <property name="count">
60      10
61    </property>
62    <property name="url">
63      http://sumno.com/feeds/main-page/
64    </property>
65    <property name="portlet_title">
66      RSS feed
67    </property>
68    <property name="timeout">
69      60
70    </property>
71  </assignment>
72  <blacklist category="user" manager="plone.leftcolumn" status="block"/>
73  <blacklist category="group" manager="plone.leftcolumn" status="acquire"/>
74  <blacklist category="content_type" manager="plone.leftcolumn" status="acquire"/>
75  <blacklist category="context" manager="plone.leftcolumn" status="acquire"/>
76</portlets>
77<BLANKLINE>
78{'_files': {'portlets': {'data': ...
79                         'name': '.portlets.xml'}},
80 '_path': 'other-assignable',
81 'files': {'portlets': {'data': ...
82                        'name': '.portlets.xml'}}}
83<?xml version="1.0" encoding="utf-8"?>
84<portlets>
85  <assignment category="context" key="/other-assignable" manager="plone.leftcolumn" name="rss" type="portlets.rss">
86    <property name="count">
87      10
88    </property>
89    <property name="url">
90      http://sumno.com/feeds/main-page/
91    </property>
92    <property name="portlet_title">
93      RSS feed
94    </property>
95    <property name="timeout">
96      60
97    </property>
98  </assignment>
99  <blacklist category="user" manager="plone.leftcolumn" status="block"/>
100  <blacklist category="group" manager="plone.leftcolumn" status="acquire"/>
101  <blacklist category="content_type" manager="plone.leftcolumn" status="acquire"/>
102  <blacklist category="context" manager="plone.leftcolumn" status="acquire"/>
103</portlets>
104<BLANKLINE>
105
106
107New portlet must be added to existent ones.
108
109>>> 'habra-rss' in mapping
110True
111>>> mapping['habra-rss'].count
11220
113>>> mapping['habra-rss'].url
114u'http://habrahabr.ru/rss/'
115>>> mapping['habra-rss'].portlet_title
116u'Habrahabr RSS feed'
117>>> mapping['habra-rss'].timeout
118120
119>>> 'rss' in mapping
120True
121>>> mapping['rss'].count
12210
123>>> mapping['rss'].url
124u'http://sumno.com/feeds/main-page/'
125>>> mapping['rss'].portlet_title
126u'RSS feed'
127>>> mapping['rss'].timeout
12860
129
130
131Export sections has also ``purge`` option which specifies if portlets must
132be purged before exporting. The ``purge`` option set to ``False`` by default
133and not purge existent portlets. To force purging - it must be set to ``True``.
134
135>>> portlets2 = """
136... [transmogrifier]
137... pipeline =
138...     portletssource
139...     portletsexporter
140...     printer
141...     dataprinter
142...     portletsimporter
143...     
144... [portletssource]
145... blueprint = quintagroup.transmogrifier.tests.portletssource2
146...
147... [portletsexporter]
148... blueprint = quintagroup.transmogrifier.portletsexporter
149...
150... [printer]
151... blueprint = collective.transmogrifier.sections.tests.pprinter
152...
153... [dataprinter]
154... blueprint = quintagroup.transmogrifier.tests.dataprinter
155... print =
156...     _files
157...     portlets
158...     data
159...
160... [portletsimporter]
161... blueprint = quintagroup.transmogrifier.portletsimporter
162... files-key = files
163... purge = True
164... """
165>>> registerConfig(u'quintagroup.transmogrifier.tests.portlets2', portlets2)
166>>> transmogrifier(u'quintagroup.transmogrifier.tests.portlets2') # doctest: +ELLIPSIS, +REPORT_NDIFF
167{}
168{'_files': {'portlets': {'data': ...
169                         'name': '.portlets.xml'}},
170 '_path': 'other-assignable',
171 'files': {'portlets': {'data': ...
172                        'name': '.portlets.xml'}}}
173<?xml version="1.0" encoding="utf-8"?>
174<portlets>
175  <assignment category="context" key="/other-assignable" manager="plone.leftcolumn" name="rss" type="portlets.rss">
176    <property name="count">
177      10
178    </property>
179    <property name="url">
180      http://sumno.com/feeds/main-page/
181    </property>
182    <property name="portlet_title">
183      RSS feed
184    </property>
185    <property name="timeout">
186      60
187    </property>
188  </assignment>
189  <assignment category="context" key="/other-assignable" manager="plone.leftcolumn" name="habra-rss" type="portlets.rss">
190    <property name="count">
191      20
192    </property>
193    <property name="url">
194      http://habrahabr.ru/rss/
195    </property>
196    <property name="portlet_title">
197      Habrahabr RSS feed
198    </property>
199    <property name="timeout">
200      120
201    </property>
202  </assignment>
203  <blacklist category="user" manager="plone.leftcolumn" status="block"/>
204  <blacklist category="group" manager="plone.leftcolumn" status="acquire"/>
205  <blacklist category="content_type" manager="plone.leftcolumn" status="acquire"/>
206  <blacklist category="context" manager="plone.leftcolumn" status="acquire"/>
207</portlets>
208<BLANKLINE>
209
210Now only 'sumno-rss-2' portlet must be present in mapping after portlets purging.
211
212>>> 'habra-rss' in mapping
213False
214>>> 'rss' in mapping
215False
216>>> 'sumno-rss-2' in mapping
217True
218>>> mapping['sumno-rss-2'].count
21930
220>>> mapping['sumno-rss-2'].url
221u'http://sumno.com/rss'
222>>> mapping['sumno-rss-2'].portlet_title
223u'Sumno RSS feed'
224>>> mapping['sumno-rss-2'].timeout
225360
226
Note: See TracBrowser for help on using the repository browser.