summaryrefslogtreecommitdiffstats
path: root/tests/test_pages.py
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2016-10-11 08:36:33 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2016-10-23 14:41:48 (GMT)
commitf3391a6279b57abcea8ab0c1708a0883221c695a (patch)
tree740d21c083c4742830746b82c27462fd50816630 /tests/test_pages.py
parentd107771bba60fa41a9b1a23f136e64cfef13bb34 (diff)
downloadcombo-f3391a6279b57abcea8ab0c1708a0883221c695a.zip
combo-f3391a6279b57abcea8ab0c1708a0883221c695a.tar.gz
combo-f3391a6279b57abcea8ab0c1708a0883221c695a.tar.bz2
general: add new export_site management command (#13540)
Diffstat (limited to 'tests/test_pages.py')
-rw-r--r--tests/test_pages.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test_pages.py b/tests/test_pages.py
index 5914ab2..7c71acd 100644
--- a/tests/test_pages.py
+++ b/tests/test_pages.py
@@ -1,7 +1,13 @@
+from StringIO import StringIO
+import os
import pytest
+import sys
+from django.conf import settings
from django.contrib.auth.models import User, Group
from combo.data.models import Page, 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
pytestmark = pytest.mark.django_db
@@ -197,3 +203,45 @@ def test_next_previous():
page3.public = False
page3.save()
assert page.get_next_page(None) is None
+
+def test_import_export_management_commands():
+ page = Page(title=u'foo', slug='foo', order=0)
+ page.save()
+
+ cell = TextCell(page=page, text='foo', order=0)
+ cell.save()
+
+ page2 = Page(title=u'bar', slug='bar', order=1, parent=page)
+ page2.save()
+
+ cell = TextCell(page=page2, text='bar', order=0)
+ cell.save()
+
+ export_filename = os.path.join(settings.MEDIA_ROOT, 'site-export.json')
+ if os.path.exists(export_filename):
+ os.unlink(export_filename)
+
+ cmd = ExportSiteCommand()
+ cmd.handle(export_filename)
+ assert os.path.exists(export_filename)
+
+ stdout = sys.stdout
+ try:
+ sys.stdout = StringIO()
+ cmd.handle('-')
+ assert sys.stdout.getvalue() == open(export_filename).read()
+ finally:
+ sys.stdout = stdout
+
+ Page.objects.all().delete()
+
+ cmd = ImportSiteCommand()
+ cmd.handle(export_filename)
+
+ new_page_1 = Page.objects.all().order_by('order')[0]
+ new_page_2 = Page.objects.all().order_by('order')[1]
+ assert new_page_1.title == 'foo'
+ assert new_page_2.title == 'bar'
+ assert len(CellBase.get_cells(page_id=new_page_1.id)) == 1
+ assert isinstance(CellBase.get_cells(page_id=new_page_1.id)[0], TextCell)
+ assert CellBase.get_cells(page_id=new_page_1.id)[0].text == 'foo'