'Create a deeply-nested plugin structure, tests its properties, and tests
that it is copied accurately when the placeholder containing them is
copied.
The structure below isn\'t arbitrary, but has been designed to test
various conditions, including:
* nodes four levels deep
* multiple successive level increases
* multiple successive level decreases
* successive nodes on the same level followed by level changes
* multiple level decreases between successive nodes
* siblings with and without children
* nodes and branches added to the tree out of sequence
First we create the structure:
11
1
2
12
4
10
8
3
9
5
6
7
13
14
and then we move it all around.'

def test_plugin_deep_nesting_and_copying(self):

    placeholder = Placeholder(slot=u'some_slot')
    placeholder.save()
    plugin_1 = add_plugin(placeholder, u'TextPlugin', u'en', body=u'01')
    plugin_1 = self.reload(plugin_1)
    plugin_2 = add_plugin(placeholder, u'TextPlugin', u'en', body=u'02', target=plugin_1)
    self.assertSequenceEqual(CMSPlugin.objects.get(id=plugin_1.pk).get_children(), [CMSPlugin.objects.get(id=plugin_2.pk)])
    plugin_1 = self.reload(plugin_1)
    plugin_3 = add_plugin(placeholder, u'TextPlugin', u'en', body=u'03', target=plugin_1)
    self.assertSequenceEqual(CMSPlugin.objects.get(id=plugin_1.pk).get_children(), [CMSPlugin.objects.get(id=plugin_2.pk), CMSPlugin.objects.get(id=plugin_3.pk)])
    plugin_2 = self.reload(plugin_2)
    plugin_4 = add_plugin(placeholder, u'TextPlugin', u'en', body=u'04', target=plugin_2)
    self.assertSequenceEqual(CMSPlugin.objects.get(id=plugin_2.pk).get_children(), [CMSPlugin.objects.get(id=plugin_4.pk)])
    self.assertSequenceEqual(CMSPlugin.objects.get(id=plugin_1.pk).get_descendants(), [CMSPlugin.objects.get(id=plugin_2.pk), CMSPlugin.objects.get(id=plugin_4.pk), CMSPlugin.objects.get(id=plugin_3.pk)])
    plugin_1 = self.reload(plugin_1)
    plugin_5 = add_plugin(placeholder, u'TextPlugin', u'en', body=u'05')
    left = CMSPlugin.objects.filter(parent__isnull=True).order_by('path')[0]
    plugin_5 = self.reload(plugin_5)
    plugin_5 = plugin_5.move(left, pos='right')
    self.reorder_positions(plugin_5)
    self.reorder_positions(plugin_2)
    plugin_5 = self.reload(plugin_5)
    plugin_6 = add_plugin(placeholder, u'TextPlugin', u'en', body=u'06', target=plugin_5)
    self.assertSequenceEqual(CMSPlugin.objects.get(id=plugin_5.pk).get_children(), [CMSPlugin.objects.get(id=plugin_6.pk)])
    plugin_5 = self.reload(plugin_5)
    plugin_7 = add_plugin(placeholder, u'TextPlugin', u'en', body=u'07', target=plugin_5)
    self.assertSequenceEqual(CMSPlugin.objects.get(id=plugin_5.pk).get_children(), [CMSPlugin.objects.get(id=plugin_6.pk), CMSPlugin.objects.get(id=plugin_7.pk)])
    self.assertSequenceEqual(CMSPlugin.objects.get(id=plugin_5.pk).get_descendants(), [CMSPlugin.objects.get(id=plugin_6.pk), CMSPlugin.objects.get(id=plugin_7.pk)])
    plugin_2 = self.reload(plugin_2)
    plugin_8 = add_plugin(placeholder, u'TextPlugin', u'en', body=u'08', target=plugin_2)
    self.assertSequenceEqual(CMSPlugin.objects.get(id=plugin_2.pk).get_children(), [CMSPlugin.objects.get(id=plugin_4.pk), CMSPlugin.objects.get(id=plugin_8.pk)])
    plugin_3 = self.reload(plugin_3)
    plugin_9 = add_plugin(placeholder, u'TextPlugin', u'en', body=u'09', target=plugin_3)
    self.assertSequenceEqual(CMSPlugin.objects.get(id=plugin_3.pk).get_children(), [CMSPlugin.objects.get(id=plugin_9.pk)])
    plugin_4 = self.reload(plugin_4)
    plugin_10 = add_plugin(placeholder, u'TextPlugin', u'en', body=u'10', target=plugin_4)
    self.assertSequenceEqual(CMSPlugin.objects.get(id=plugin_4.pk).get_children(), [CMSPlugin.objects.get(id=plugin_10.pk)])
    original_plugins = placeholder.get_plugins()
    self.assertEqual(original_plugins.count(), 10)
    plugin_1 = self.reload(plugin_1)
    plugin_11 = add_plugin(placeholder, u'TextPlugin', u'en', body=u'11', target=plugin_1, position='left')
    self.assertSequenceEqual(CMSPlugin.objects.get(id=plugin_1.pk).get_children(), [CMSPlugin.objects.get(id=plugin_2.pk), CMSPlugin.objects.get(id=plugin_3.pk)])
    plugin_4 = self.reload(plugin_4)
    plugin_12 = add_plugin(placeholder, u'TextPlugin', u'en', body=u'12', target=plugin_4, position='left')
    self.assertSequenceEqual(CMSPlugin.objects.get(id=plugin_2.pk).get_children(), [CMSPlugin.objects.get(id=plugin_12.pk), CMSPlugin.objects.get(id=plugin_4.pk), CMSPlugin.objects.get(id=plugin_8.pk)])
    plugin_7 = self.reload(plugin_7)
    plugin_13 = add_plugin(placeholder, u'TextPlugin', u'en', body=u'13', target=plugin_7, position='right')
    self.assertSequenceEqual(CMSPlugin.objects.get(id=plugin_5.pk).get_children(), [CMSPlugin.objects.get(id=plugin_6.pk), CMSPlugin.objects.get(id=plugin_7.pk), CMSPlugin.objects.get(id=plugin_13.pk)])
    plugin_5 = self.reload(plugin_5)
    plugin_14 = add_plugin(placeholder, u'TextPlugin', u'en', body=u'14')
    self.assertSequenceEqual(CMSPlugin.objects.filter(depth=1).order_by('path'), [CMSPlugin.objects.get(id=plugin_11.pk), CMSPlugin.objects.get(id=plugin_1.pk), CMSPlugin.objects.get(id=plugin_5.pk), CMSPlugin.objects.get(id=plugin_14.pk)])
    self.copy_placeholders_and_check_results([placeholder])
    plugin_2 = self.reload(plugin_2)
    plugin_1 = self.reload(plugin_1)
    old_parent = plugin_2.parent
    plugin_2.parent_id = plugin_1.parent_id
    plugin_2.save()
    plugin_2 = plugin_2.move(target=plugin_1, pos='left')
    self.reorder_positions(parent=old_parent)
    self.reorder_positions(plugin_2)
    self.copy_placeholders_and_check_results([placeholder])
    plugin_6 = self.reload(plugin_6)
    plugin_7 = self.reload(plugin_7)
    old_parent = plugin_6.parent
    plugin_6.parent_id = plugin_7.parent_id
    plugin_6.save()
    plugin_6 = plugin_6.move(target=plugin_7, pos='right')
    self.reorder_positions(parent=old_parent)
    self.reorder_positions(plugin_6)
    self.copy_placeholders_and_check_results([placeholder])
    plugin_2 = self.reload(plugin_2)
    plugin_3 = self.reload(plugin_3)
    old_parent = plugin_3.parent
    plugin_3.parent_id = plugin_2.parent_id
    plugin_3.save()
    plugin_3 = plugin_3.move(target=plugin_2, pos='left')
    self.reorder_positions(parent=old_parent)
    self.reorder_positions(plugin_3)
    self.copy_placeholders_and_check_results([placeholder])
    plugin_2 = self.reload(plugin_2)
    plugin_3 = self.reload(plugin_3)
    old_parent = plugin_3.parent
    plugin_3.parent_id = plugin_2.pk
    plugin_3.save()
    plugin_3 = plugin_3.move(target=plugin_2, pos='first-child')
    self.reorder_positions(CMSPlugin.objects.filter(placeholder_id=plugin_3.placeholder_id, language=plugin_3.language, depth=1)[0])
    self.reorder_positions(plugin_3)
    self.copy_placeholders_and_check_results([placeholder])
    plugin_3 = self.reload(plugin_3)
    plugin_7 = self.reload(plugin_7)
    old_parent = plugin_7.parent
    plugin_7.parent_id = plugin_3.parent_id
    plugin_7.save()
    plugin_7 = plugin_7.move(target=plugin_3, pos='right')
    self.reorder_positions(parent=old_parent)
    self.reorder_positions(plugin_7)
    self.copy_placeholders_and_check_results([placeholder])
