summaryrefslogtreecommitdiffstats
path: root/tests/test_pages.py
diff options
context:
space:
mode:
authorLauréline Guérin <zebuline@entrouvert.com>2019-10-22 12:58:02 (GMT)
committerLauréline Guérin <zebuline@entrouvert.com>2019-11-04 07:40:01 (GMT)
commit6be400fcfc55dc972268cfbcc72d64da2d477fac (patch)
treea2282825ad68814c54aea2a8ee479b87fdb4458b /tests/test_pages.py
parent09507f8988ea1c6a14f91d1eb7570c06ad435e38 (diff)
downloadcombo-6be400fcfc55dc972268cfbcc72d64da2d477fac.zip
combo-6be400fcfc55dc972268cfbcc72d64da2d477fac.tar.gz
combo-6be400fcfc55dc972268cfbcc72d64da2d477fac.tar.bz2
page: add a duplicate action (#24526)wip/24526-page-copy
Diffstat (limited to 'tests/test_pages.py')
-rw-r--r--tests/test_pages.py48
1 files changed, 47 insertions, 1 deletions
diff --git a/tests/test_pages.py b/tests/test_pages.py
index aa701bd..77020e4 100644
--- a/tests/test_pages.py
+++ b/tests/test_pages.py
@@ -9,7 +9,7 @@ from django.test import override_settings
from django.test.client import RequestFactory
from django.utils.six import StringIO
from django.utils.timezone import now
-from combo.data.models import Page, CellBase, TextCell, LinkCell
+from combo.data.models import Page, PageSnapshot, CellBase, TextCell, LinkCell
from combo.data.management.commands.import_site import Command as ImportSiteCommand
from combo.data.management.commands.export_site import Command as ExportSiteCommand
from combo.manager.forms import PageVisibilityForm
@@ -192,6 +192,52 @@ def test_import_export_pages_with_links():
assert CellBase.get_cells(page_id=new_page_1.id)[0].link_page_id == new_page_2.id
assert CellBase.get_cells(page_id=new_page_2.id)[0].link_page_id == new_page_1.id
+
+def test_duplicate_page():
+ group1 = Group.objects.create(name='foobar')
+ group2 = Group.objects.create(name='fooblah')
+
+ page = Page.objects.create(
+ title='foo',
+ slug='foo',
+ description="Foo's page")
+ page.groups.set([group1, group2])
+ snapshot = PageSnapshot.objects.create(page=page)
+ page.snapshot = snapshot
+ page.save()
+
+ cell1 = TextCell.objects.create(page=page, text='foo1', order=0, placeholder='content')
+ cell1.groups.set([group1, group2])
+ cell2 = TextCell.objects.create(page=page, text='foo2', order=1, placeholder='content')
+
+ new_page = page.duplicate()
+ assert new_page.pk != page.pk
+ assert new_page.title == 'Copy of foo'
+ assert new_page.slug == page.slug
+ assert new_page.description == page.description
+ assert new_page.parent is None
+ assert new_page.snapshot is None
+ assert list(new_page.groups.all()) == [group1, group2]
+ assert len(new_page.get_cells()) == 2
+
+ new_cell1 = TextCell.objects.get(page=new_page, text='foo1')
+ new_cell2 = TextCell.objects.get(page=new_page, text='foo2')
+ assert new_cell1.pk != cell1.pk
+ assert new_cell1.text == cell1.text
+ assert new_cell1.placeholder == cell1.placeholder
+ assert list(new_cell1.groups.all()) == [group1, group2]
+ assert new_cell2.pk != cell2.pk
+ assert new_cell2.text == cell2.text
+ assert new_cell2.placeholder == cell2.placeholder
+ assert list(new_cell2.groups.all()) == []
+
+ parent = Page.objects.create()
+ page.parent = parent
+ page.save()
+ new_page = page.duplicate()
+ assert new_page.parent == parent
+
+
def test_next_previous():
Page.objects.all().delete()
page = Page()