Source

django-cms-mycmsproject-toporojo / cms / tests / nested_plugins.py

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# -*- coding: utf-8 -*-
from __future__ import with_statement

from cms.api import create_page, add_plugin
from cms.models import Page
from cms.models.placeholdermodel import Placeholder
from cms.models.pluginmodel import CMSPlugin
from cms.tests.plugins import PluginsTestBaseCase
from cms.test_utils.util.context_managers import SettingsOverride


URL_CMS_MOVE_PLUGIN = u'/admin/cms/page/%d/move-plugin/'    


class NestedPluginsTestCase(PluginsTestBaseCase):
    
    def test_nested_plugin_on_page(self):
        """
        Validate a textplugin with a nested link plugin
        mptt values are correctly showing a parent child relationship
        of a nested plugin
        """
        with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
            # setup page 1
            page_one = create_page(u"Three Placeholder", u"col_three.html", u"en",
                               position=u"last-child", published=True, in_navigation=True)
            page_one_ph_two = page_one.placeholders.get(slot=u"col_left")
            
            ###
            # add a plugin
            ###
            pre_nesting_body = u"<p>the nested text plugin with a link inside</p>"
            text_plugin = add_plugin(page_one_ph_two, u"TextPlugin", u"en", body=pre_nesting_body)
            # prepare nestin plugin
            page_one_ph_two = self.reload(page_one_ph_two)
            text_plugin = self.reload(text_plugin)
            link_plugin = add_plugin(page_one_ph_two, u"LinkPlugin", u"en", target=text_plugin)
            link_plugin.name = u"django-cms Link"
            link_plugin.url = u"https://www.django-cms.org" 
            
            # as for some reason mptt does not 
            # update the parent child relationship 
            # in the add_plugin method when a target present
            # but this is not the topic of the test
            link_plugin.parent = text_plugin
            link_plugin.save()
            # reloading needs to be done after every save
            link_plugin = self.reload(link_plugin)
            text_plugin = self.reload(text_plugin)
            
            # mptt related insertion correct?
            msg = u"parent plugin right is not updated, child not inserted correctly"
            self.assertTrue(text_plugin.rght > link_plugin.rght, msg=msg)
            msg = u"link has no parent"
            self.assertFalse(link_plugin.parent == None, msg=msg)
            msg = u"parent plugin left is not updated, child not inserted correctly"
            self.assertTrue(text_plugin.lft < link_plugin.lft, msg=msg)
            msg = u"child level is not bigger than parent level"
            self.assertTrue(text_plugin.level < link_plugin.level , msg=msg)
            
            # add the link plugin to the body
            # emulate the editor in admin that adds some txt for the nested plugin
            in_txt = u"""<img id="plugin_obj_%s" title="Link" alt="Link" src="/static/cms/images/plugins/link.png">"""
            nesting_body = u"%s<p>%s</p>" % (text_plugin.body, (in_txt % (link_plugin.id)))
            text_plugin.body = nesting_body
            text_plugin.save()
            
            text_plugin = self.reload(text_plugin)
            # none of the descendants should have a placeholder other then my own one
            self.assertEquals(text_plugin.get_descendants().exclude(placeholder=text_plugin.placeholder).count(), 0)
            post_add_plugin_count = CMSPlugin.objects.count()
            self.assertEqual(post_add_plugin_count, 2)
            
    
    
    def test_copy_page_nested_plugin(self):
        """
        Test to verify that page copy with a nested plugin works
        page one - 3 placeholder 
                    col_sidebar: 
                        1 text plugin
                    col_left: 1 text plugin with nested link plugin
                    col_right: no plugin
        page two (copy target)
        Verify copied page, placeholders, plugins and body text
        """
        with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
            templates = []
            # setup page 1
            page_one = create_page(u"Three Placeholder", u"col_three.html", u"en",
                               position=u"last-child", published=True, in_navigation=True)
            page_one_ph_one = page_one.placeholders.get(slot=u"col_sidebar")
            page_one_ph_two = page_one.placeholders.get(slot=u"col_left")
            page_one_ph_three = page_one.placeholders.get(slot=u"col_right")
            # add the text plugin to placeholder one
            text_plugin_en = add_plugin(page_one_ph_one, u"TextPlugin", u"en", body="Hello World")
            self.assertEquals(text_plugin_en.id, CMSPlugin.objects.all()[0].id)
            self.assertEquals(text_plugin_en.get_children().count(), 0)
            pre_add_plugin_count = CMSPlugin.objects.count()
            self.assertEqual(pre_add_plugin_count, 1)
            ###
            # add a plugin to placeholder two
            ###
            pre_nesting_body = u"<p>the nested text plugin with a link inside</p>"
            text_plugin_two = add_plugin(page_one_ph_two, u"TextPlugin", u"en", body=pre_nesting_body)
            text_plugin_two = self.reload(text_plugin_two)
            # prepare nesting plugin
            page_one_ph_two = self.reload(page_one_ph_two)
            text_plugin_two = self.reload(text_plugin_two)
            link_plugin = add_plugin(page_one_ph_two, u"LinkPlugin", u"en", target=text_plugin_two)
            link_plugin.name = u"django-cms Link"
            link_plugin.url = u"https://www.django-cms.org" 
            link_plugin.parent = text_plugin_two
            link_plugin.save()
            
            link_plugin = self.reload(link_plugin)
            text_plugin_two = self.reload(text_plugin_two)
            in_txt = """<img id="plugin_obj_%s" title="Link" alt="Link" src="/static/cms/images/plugins/link.png">"""
            nesting_body = "%s<p>%s</p>" % (text_plugin_two.body, (in_txt % (link_plugin.id)))
            # emulate the editor in admin that adds some txt for the nested plugin
            text_plugin_two.body = nesting_body
            text_plugin_two.save()
            text_plugin_two = self.reload(text_plugin_two)
            # the link is attached as a child?
            self.assertEquals(text_plugin_two.get_children().count(), 1)
            post_add_plugin_count = CMSPlugin.objects.count()
            self.assertEqual(post_add_plugin_count, 3)
            page_one.save()
            # get the plugins from the original page
            page_one = self.reload(page_one)
            page_one_ph_one = page_one.placeholders.get(slot = u"col_sidebar")
            page_one_ph_two = page_one.placeholders.get(slot = u"col_left")
            page_one_ph_three = page_one.placeholders.get(slot = u"col_right")
            # verifiy the plugins got created
            org_placeholder_one_plugins = page_one_ph_one.get_plugins()
            self.assertEquals(len(org_placeholder_one_plugins), 1)
            org_placeholder_two_plugins = page_one_ph_two.get_plugins()
            self.assertEquals(len(org_placeholder_two_plugins), 2)
            org_placeholder_three_plugins = page_one_ph_three.get_plugins()
            self.assertEquals(len(org_placeholder_three_plugins), 0)
            self.assertEquals(page_one.placeholders.count(), 3)
            placeholder_count = Placeholder.objects.count()
            self.assertEquals(placeholder_count, 3)
            self.assertEquals(CMSPlugin.objects.count(), 3)
            page_one_plugins = CMSPlugin.objects.all()
            ##
            # setup page_copy_target page
            ##
            page_copy_target = create_page("Three Placeholder - page copy target", "col_three.html", "en",
                               position="last-child", published=True, in_navigation=True)
            all_page_count = Page.objects.all().count()
            pre_copy_placeholder_count = Placeholder.objects.count()
            self.assertEquals(pre_copy_placeholder_count, 6)
            # copy the page
            superuser = self.get_superuser()
            with self.login_user_context(superuser):
                page_two = self.copy_page(page_one, page_copy_target)
            # validate the expected pages,placeholders,plugins,pluginbodies
            after_copy_page_plugin_count = CMSPlugin.objects.count()
            self.assertEquals(after_copy_page_plugin_count, 6)
            # check the amount of copied stuff
            after_copy_page_count = Page.objects.all().count()
            after_copy_placeholder_count = Placeholder.objects.count()
            self.assertTrue((after_copy_page_count > all_page_count), msg = u"no new page after copy")
            self.assertTrue((after_copy_page_plugin_count > post_add_plugin_count), msg = u"plugin count is not grown")
            self.assertTrue((after_copy_placeholder_count > pre_copy_placeholder_count), msg = u"placeholder count is not grown")    
            self.assertTrue((after_copy_page_count == 3), msg = u"no new page after copy")
            # orginal placeholder
            page_one = self.reload(page_one)
            page_one_ph_one = page_one.placeholders.get(slot = u"col_sidebar")
            page_one_ph_two = page_one.placeholders.get(slot = u"col_left")
            page_one_ph_three = page_one.placeholders.get(slot = u"col_right")
            # check if there are multiple pages assigned to this placeholders
            found_page = page_one_ph_one.page if page_one_ph_one else None
            self.assertEqual(found_page, page_one)
            found_page = page_one_ph_two.page if page_one_ph_two else None
            self.assertEqual(found_page, page_one)
            found_page = page_one_ph_three.page if page_one_ph_three else None
            self.assertEqual(found_page, page_one)
            
            page_two = self.reload(page_two)
            page_two_ph_one = page_two.placeholders.get(slot = u"col_sidebar")
            page_two_ph_two = page_two.placeholders.get(slot = u"col_left")
            page_two_ph_three = page_two.placeholders.get(slot = u"col_right")
            # check if there are multiple pages assigned to this placeholders
            found_page = page_two_ph_one.page if page_two_ph_one else None
            self.assertEqual(found_page, page_two)
            found_page = page_two_ph_two.page if page_two_ph_two else None
            self.assertEqual(found_page, page_two)
            found_page = page_two_ph_three.page if page_two_ph_three else None
            self.assertEqual(found_page, page_two)
            # check the stored placeholders org vs copy
            msg = 'placehoder ids copy:%s org:%s copied page %s are identical - tree broken' % (page_two_ph_one.pk, page_one_ph_one.pk, page_two.pk)
            self.assertNotEquals(page_two_ph_one.pk, page_one_ph_one.pk, msg)
            msg = 'placehoder ids copy:%s org:%s copied page %s are identical - tree broken' % (page_two_ph_two.pk, page_one_ph_two.pk, page_two.pk)
            self.assertNotEquals(page_two_ph_two.pk, page_one_ph_two.pk, msg)
            msg = 'placehoder ids copy:%s org:%s copied page %s are identical - tree broken' % (page_two_ph_three.pk, page_one_ph_three.pk, page_two.pk)
            self.assertNotEquals(page_two_ph_three.pk, page_one_ph_three.pk, msg)
            # get the plugins from the original page
            org_placeholder_one_plugins = page_one_ph_one.get_plugins()
            self.assertEquals(len(org_placeholder_one_plugins), 1)
            org_placeholder_two_plugins = page_one_ph_two.get_plugins()
            self.assertEquals(len(org_placeholder_two_plugins), 2)
            org_placeholder_three_plugins = page_one_ph_three.get_plugins()
            self.assertEquals(len(org_placeholder_three_plugins), 0)
            # get the plugins from the copied page
            copied_placeholder_one_plugins = page_two_ph_one.get_plugins()
            self.assertEquals(len(copied_placeholder_one_plugins), 1)
            copied_placeholder_two_plugins = page_two_ph_two.get_plugins()
            self.assertEquals(len(copied_placeholder_two_plugins), 2)
            copied_placeholder_three_plugins = page_two_ph_three.get_plugins()
            self.assertEquals(len(copied_placeholder_three_plugins), 0)
            # verify the plugins got copied
            # placeholder 1
            count_plugins_copied = len(copied_placeholder_one_plugins)
            count_plugins_org = len(org_placeholder_one_plugins)
            msg = u"plugin count %s %s for placeholder one not equal" % (count_plugins_copied, count_plugins_org)
            self.assertEquals(count_plugins_copied, count_plugins_org, msg)        
            # placeholder 2
            count_plugins_copied = len(copied_placeholder_two_plugins)
            count_plugins_org = len(org_placeholder_two_plugins)
            msg = u"plugin count %s %s for placeholder two not equal" % (count_plugins_copied, count_plugins_org)
            self.assertEquals(count_plugins_copied, count_plugins_org, msg)        
            # placeholder 3
            count_plugins_copied = len(copied_placeholder_three_plugins)
            count_plugins_org = len(org_placeholder_three_plugins)
            msg = u"plugin count %s %s for placeholder three not equal" % (count_plugins_copied, count_plugins_org)
            self.assertEquals(count_plugins_copied, count_plugins_org, msg)
            # verify the body of text plugin with nested link plugin
            # org to copied  
            org_nested_text_plugin = None
            # do this iteration to find the real text plugin with the attached link
            # the inheritance mechanism for the cmsplugins works through 
            # (tuple)get_plugin_instance()
            for x in org_placeholder_two_plugins:     
                if x.plugin_type == u"TextPlugin":
                    instance = x.get_plugin_instance()[0]
                    if instance.body.startswith(pre_nesting_body):
                        org_nested_text_plugin = instance
                        break
            copied_nested_text_plugin = None
            for x in copied_placeholder_two_plugins:        
                if x.plugin_type == u"TextPlugin":
                    instance = x.get_plugin_instance()[0]
                    if instance.body.startswith(pre_nesting_body):
                        copied_nested_text_plugin = instance
                        break
            msg = u"orginal nested text plugin not found"
            self.assertNotEquals(org_nested_text_plugin, None, msg=msg)
            msg = u"copied nested text plugin not found"
            self.assertNotEquals(copied_nested_text_plugin, None, msg=msg)
            # get the children ids of the texplugin with a nested link
            # to check if the body of the text is genrated correctly
            org_link_child_plugin = org_nested_text_plugin.get_children()[0]
            copied_link_child_plugin = copied_nested_text_plugin.get_children()[0]
            # validate the textplugin body texts
            msg = u"org plugin and copied plugin are the same"
            self.assertTrue(org_link_child_plugin.id != copied_link_child_plugin.id, msg)
            needle = u"plugin_obj_%s"
            msg = u"child plugin id differs to parent in body plugin_obj_id"
            # linked child is in body
            self.assertTrue(org_nested_text_plugin.body.find(needle % (org_link_child_plugin.id)) != -1, msg)
            msg = u"copy: child plugin id differs to parent in body plugin_obj_id"
            self.assertTrue(copied_nested_text_plugin.body.find(needle % (copied_link_child_plugin.id)) != -1, msg)
            # really nothing else
            msg = u"child link plugin id differs to parent body plugin_obj_id"
            self.assertTrue(org_nested_text_plugin.body.find(needle % (copied_link_child_plugin.id)) == -1, msg)
            msg = u"copy: child link plugin id differs to parent body plugin_obj_id"
            self.assertTrue(copied_nested_text_plugin.body.find(needle % (org_link_child_plugin.id)) == -1, msg)
            # now reverse lookup the placeholders from the plugins
            org_placeholder = org_link_child_plugin.placeholder
            copied_placeholder = copied_link_child_plugin.placeholder
            msg = u"placeholder of the orginal plugin and copied plugin are the same"
            ok = ((org_placeholder.id != copied_placeholder.id))
            self.assertTrue(ok, msg)

     
    def test_copy_page_nested_plugin_moved_parent_plugin(self):
        """
        Test to verify that page copy with a nested plugin works
        when a plugin with child got moved to another placeholder
        page one - 3 placeholder 
                    col_sidebar: 
                        1 text plugin
                    col_left: 1 text plugin with nested link plugin
                    col_right: no plugin
        page two (copy target)
        step2: move the col_left text plugin to col_right
                    col_sidebar: 
                        1 text plugin
                    col_left: no plugin
                    col_right: 1 text plugin with nested link plugin
        verify the copied page structure
        """
        with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
            templates = []
            # setup page 1
            page_one = create_page(u"Three Placeholder", u"col_three.html", u"en",
                               position=u"last-child", published=True, in_navigation=True)
            page_one_ph_one = page_one.placeholders.get(slot=u"col_sidebar")
            page_one_ph_two = page_one.placeholders.get(slot=u"col_left")
            page_one_ph_three = page_one.placeholders.get(slot=u"col_right")
            # add the text plugin to placeholder one
            text_plugin_en = add_plugin(page_one_ph_one, u"TextPlugin", u"en", body=u"Hello World")
            self.assertEquals(text_plugin_en.id, CMSPlugin.objects.all()[0].id)
            self.assertEquals(text_plugin_en.get_children().count(), 0)
            pre_add_plugin_count = CMSPlugin.objects.count()
            self.assertEqual(pre_add_plugin_count, 1)
            # add a plugin to placeholder twho
            pre_nesting_body = u"<p>the nested text plugin with a link inside</p>"
            text_plugin_two = add_plugin(page_one_ph_two, u"TextPlugin", u"en", body=pre_nesting_body)
            text_plugin_two = self.reload(text_plugin_two)
            # prepare nestin plugin
            page_one_ph_two = self.reload(page_one_ph_two)
            text_plugin_two = self.reload(text_plugin_two)
            link_plugin = add_plugin(page_one_ph_two, u"LinkPlugin", u"en", target=text_plugin_two)
            link_plugin.name = u"django-cms Link"
            link_plugin.url = u"https://www.django-cms.org" 
            link_plugin.parent = text_plugin_two
            link_plugin.save()
            # reload after every save
            link_plugin = self.reload(link_plugin)
            text_plugin_two = self.reload(text_plugin_two)
            in_txt = u"""<img id="plugin_obj_%s" title="Link" alt="Link" src="/static/cms/images/plugins/link.png">"""
            nesting_body = "%s<p>%s</p>" % (text_plugin_two.body, (in_txt % (link_plugin.id)))
            # emulate the editor in admin that adds some txt for the nested plugin
            text_plugin_two.body = nesting_body
            text_plugin_two.save()
            text_plugin_two = self.reload(text_plugin_two)
            # the link is attached as a child?
            self.assertEquals(text_plugin_two.get_children().count(), 1)
            post_add_plugin_count = CMSPlugin.objects.count()
            self.assertEqual(post_add_plugin_count, 3)
            page_one.save()
            # get the plugins from the original page
            page_one = self.reload(page_one)
            page_one_ph_one = page_one.placeholders.get(slot = u"col_sidebar")
            page_one_ph_two = page_one.placeholders.get(slot = u"col_left")
            page_one_ph_three = page_one.placeholders.get(slot = u"col_right")
            # verify the plugins got created
            org_placeholder_one_plugins = page_one_ph_one.get_plugins()
            self.assertEquals(len(org_placeholder_one_plugins), 1)
            org_placeholder_two_plugins = page_one_ph_two.get_plugins()
            self.assertEquals(len(org_placeholder_two_plugins), 2)
            org_placeholder_three_plugins = page_one_ph_three.get_plugins()
            self.assertEquals(len(org_placeholder_three_plugins), 0)
            self.assertEquals(page_one.placeholders.count(), 3)
            
            placeholder_count = Placeholder.objects.count()
            self.assertEquals(placeholder_count, 3)
            self.assertEquals(CMSPlugin.objects.count(), 3)
            page_one_plugins = CMSPlugin.objects.all()
            # setup page_copy_target
            page_copy_target = create_page("Three Placeholder - page copy target", "col_three.html", "en",
                               position="last-child", published=True, in_navigation=True)
            all_page_count = Page.objects.all().count()
            pre_copy_placeholder_count = Placeholder.objects.count()
            self.assertEquals(pre_copy_placeholder_count, 6)
            superuser = self.get_superuser()
            with self.login_user_context(superuser):
                # now move the parent text plugin to another placeholder
                post_data = {
                             u'placeholder': u"col_right",
                             u'placeholder_id': u"%s" % (page_one_ph_three.id),
                             u'ids': u"%s" % (text_plugin_two.id),
                             u'plugin_id': u"%s" % (text_plugin_two.id),
                }
                edit_url = URL_CMS_MOVE_PLUGIN % (page_one.id)
                response = self.client.post(edit_url, post_data)
                self.assertEqual(response.status_code, 200)
                self.assertEqual(response.content, u'ok')
                # check if the plugin got moved
                page_one = self.reload(page_one)
                text_plugin_two = self.reload(text_plugin_two)
                page_one_ph_one = page_one.placeholders.get(slot = u"col_sidebar")
                page_one_ph_two = page_one.placeholders.get(slot = u"col_left")
                page_one_ph_three = page_one.placeholders.get(slot = u"col_right")
                
                org_placeholder_one_plugins = page_one_ph_one.get_plugins()
                self.assertEquals(len(org_placeholder_one_plugins), 1)
                org_placeholder_two_plugins = page_one_ph_two.get_plugins()
                # the plugin got moved and child got moved
                self.assertEquals(len(org_placeholder_two_plugins), 0)
                org_placeholder_three_plugins = page_one_ph_three.get_plugins()
                self.assertEquals(len(org_placeholder_three_plugins), 2)
                # copy the page
                page_two = self.copy_page(page_one, page_copy_target)
            # validate the expected pages,placeholders,plugins,pluginbodies
            after_copy_page_plugin_count = CMSPlugin.objects.count()
            self.assertEquals(after_copy_page_plugin_count, 6)
            after_copy_page_count = Page.objects.all().count()
            after_copy_placeholder_count = Placeholder.objects.count()
            self.assertTrue((after_copy_page_count > all_page_count), msg = u"no new page after copy")
            self.assertTrue((after_copy_page_plugin_count > post_add_plugin_count), msg = u"plugin count is not grown")
            self.assertTrue((after_copy_placeholder_count > pre_copy_placeholder_count), msg = u"placeholder count is not grown")    
            self.assertTrue((after_copy_page_count == 3), msg = u"no new page after copy")
            # validate the structure
            # orginal placeholder
            page_one = self.reload(page_one)
            page_one_ph_one = page_one.placeholders.get(slot=u"col_sidebar")
            page_one_ph_two = page_one.placeholders.get(slot=u"col_left")
            page_one_ph_three = page_one.placeholders.get(slot=u"col_right")
            # check if there are multiple pages assigned to this placeholders
            found_page = page_one_ph_one.page if page_one_ph_one else None
            self.assertEqual(found_page, page_one)
            found_page = page_one_ph_two.page if page_one_ph_two else None
            self.assertEqual(found_page, page_one)
            found_page = page_one_ph_three.page if page_one_ph_three else None
            self.assertEqual(found_page, page_one)
            page_two = self.reload(page_two)
            page_two_ph_one = page_two.placeholders.get(slot = u"col_sidebar")
            page_two_ph_two = page_two.placeholders.get(slot = u"col_left")
            page_two_ph_three = page_two.placeholders.get(slot = u"col_right")
            # check if there are multiple pages assigned to this placeholders
            found_page = page_two_ph_one.page if page_two_ph_one else None
            self.assertEqual(found_page, page_two)
            found_page = page_two_ph_two.page if page_two_ph_two else None
            self.assertEqual(found_page, page_two)
            found_page = page_two_ph_three.page if page_two_ph_three else None
            self.assertEqual(found_page, page_two)
            # check the stored placeholders org vs copy
            msg = u'placehoder ids copy:%s org:%s copied page %s are identical - tree broken' % (page_two_ph_one.pk, page_one_ph_one.pk, page_two.pk)
            self.assertNotEquals(page_two_ph_one.pk, page_one_ph_one.pk, msg)
            msg = u'placehoder ids copy:%s org:%s copied page %s are identical - tree broken' % (page_two_ph_two.pk, page_one_ph_two.pk, page_two.pk)
            self.assertNotEquals(page_two_ph_two.pk, page_one_ph_two.pk, msg)
            msg = u'placehoder ids copy:%s org:%s copied page %s are identical - tree broken' % (page_two_ph_three.pk, page_one_ph_three.pk, page_two.pk)
            self.assertNotEquals(page_two_ph_three.pk, page_one_ph_three.pk, msg)
            # get the plugins from the original page
            org_placeholder_one_plugins = page_one_ph_one.get_plugins()
            self.assertEquals(len(org_placeholder_one_plugins), 1)
            org_placeholder_two_plugins = page_one_ph_two.get_plugins()
            self.assertEquals(len(org_placeholder_two_plugins), 0)
            org_placeholder_three_plugins = page_one_ph_three.get_plugins()
            self.assertEquals(len(org_placeholder_three_plugins), 2)
            # get the plugins from the copied page
            copied_placeholder_one_plugins = page_two_ph_one.get_plugins()
            self.assertEquals(len(copied_placeholder_one_plugins), 1)
            copied_placeholder_two_plugins = page_two_ph_two.get_plugins()
            self.assertEquals(len(copied_placeholder_two_plugins), 0)
            copied_placeholder_three_plugins = page_two_ph_three.get_plugins()
            self.assertEquals(len(copied_placeholder_three_plugins), 2)
            # verify the plugins got copied
            # placeholder 1
            count_plugins_copied = len(copied_placeholder_one_plugins)
            count_plugins_org = len(org_placeholder_one_plugins)
            msg = u"plugin count %s %s for placeholder one not equal" % (count_plugins_copied, count_plugins_org)
            self.assertEquals(count_plugins_copied, count_plugins_org, msg)        
            # placeholder 2
            count_plugins_copied = len(copied_placeholder_two_plugins)
            count_plugins_org = len(org_placeholder_two_plugins)
            msg = u"plugin count %s %s for placeholder two not equal" % (count_plugins_copied, count_plugins_org)
            self.assertEquals(count_plugins_copied, count_plugins_org, msg)        
            # placeholder 3
            count_plugins_copied = len(copied_placeholder_three_plugins)
            count_plugins_org = len(org_placeholder_three_plugins)
            msg = u"plugin count %s %s for placeholder three not equal" % (count_plugins_copied, count_plugins_org)
            self.assertEquals(count_plugins_copied, count_plugins_org, msg)
            # verify the body of text plugin with nested link plugin
            # org to copied  
            org_nested_text_plugin = None
            # do this iteration to find the real text plugin with the attached link
            # the inheritance mechanism for the cmsplugins works through 
            # (tuple)get_plugin_instance()
            for x in org_placeholder_three_plugins:     
                if x.plugin_type == u"TextPlugin":
                    instance = x.get_plugin_instance()[0]
                    if instance.body.startswith(pre_nesting_body):
                        org_nested_text_plugin = instance
                        break
            copied_nested_text_plugin = None
            for x in copied_placeholder_three_plugins:        
                if x.plugin_type == u"TextPlugin":
                    instance = x.get_plugin_instance()[0]
                    if instance.body.startswith(pre_nesting_body):
                        copied_nested_text_plugin = instance
                        break
            msg = u"orginal nested text plugin not found"
            self.assertNotEquals(org_nested_text_plugin, None, msg=msg)
            msg = u"copied nested text plugin not found"
            self.assertNotEquals(copied_nested_text_plugin, None, msg=msg)
            # get the children ids of the texplugin with a nested link
            # to check if the body of the text is generated correctly
            org_link_child_plugin = org_nested_text_plugin.get_children()[0]
            copied_link_child_plugin = copied_nested_text_plugin.get_children()[0]
            # validate the textplugin body texts
            msg = u"org plugin and copied plugin are the same"
            self.assertTrue(org_link_child_plugin.id != copied_link_child_plugin.id, msg)
            needle = u"plugin_obj_%s"
            msg = u"child plugin id differs to parent in body plugin_obj_id"
            # linked child is in body
            self.assertTrue(org_nested_text_plugin.body.find(needle % (org_link_child_plugin.id)) != -1, msg)
            msg = u"copy: child plugin id differs to parent in body plugin_obj_id"
            self.assertTrue(copied_nested_text_plugin.body.find(needle % (copied_link_child_plugin.id)) != -1, msg)
            # really nothing else
            msg = u"child link plugin id differs to parent body plugin_obj_id"
            self.assertTrue(org_nested_text_plugin.body.find(needle % (copied_link_child_plugin.id)) == -1, msg)
            msg = u"copy: child link plugin id differs to parent body plugin_obj_id"
            self.assertTrue(copied_nested_text_plugin.body.find(needle % (org_link_child_plugin.id)) == -1, msg)
            # now reverse lookup the placeholders from the plugins
            org_placeholder = org_link_child_plugin.placeholder
            copied_placeholder = copied_link_child_plugin.placeholder
            msg = u"placeholder of the orginal plugin and copied plugin are the same"
            ok = ((org_placeholder.id != copied_placeholder.id))
            self.assertTrue(ok, msg)       
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.