summaryrefslogtreecommitdiffstats
path: root/tests/test_pages.py
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2015-01-17 13:01:57 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2015-01-17 13:01:57 (GMT)
commita584bd720cc61f8e90594f4404c7dc82df0fd337 (patch)
tree2cef2a9020f73b3d541221e1e147ac323f2748ae /tests/test_pages.py
parent3600e857cc2f556cbc55ca54883eafce887ab9d2 (diff)
downloadcombo-a584bd720cc61f8e90594f4404c7dc82df0fd337.zip
combo-a584bd720cc61f8e90594f4404c7dc82df0fd337.tar.gz
combo-a584bd720cc61f8e90594f4404c7dc82df0fd337.tar.bz2
add initial tests on pages and cellswip/start
Diffstat (limited to 'tests/test_pages.py')
-rw-r--r--tests/test_pages.py114
1 files changed, 114 insertions, 0 deletions
diff --git a/tests/test_pages.py b/tests/test_pages.py
new file mode 100644
index 0000000..074dd65
--- /dev/null
+++ b/tests/test_pages.py
@@ -0,0 +1,114 @@
+import pytest
+
+from django.contrib.auth.models import User, Group
+from combo.data.models import Page
+
+pytestmark = pytest.mark.django_db
+
+def test_page_order():
+ page = Page()
+ page.title = 'foo'
+ page.save()
+ page2 = Page()
+ page2.title = 'bar'
+ page2.save()
+
+ assert Page.objects.get(id=page.id).order < Page.objects.get(id=page2.id)
+
+def test_page_url():
+ page = Page()
+ page.slug = 'foo'
+ page.save()
+ assert page.get_online_url() == '/foo'
+ page2 = Page()
+ page2.slug = 'bar'
+ page2.parent = page
+ assert page2.get_online_url() == '/foo/bar'
+
+def test_page_of_level():
+ parent_page = None
+ for i in range(10):
+ page = Page()
+ page.slug = 'level%d' % i
+ if parent_page:
+ page.parent = parent_page
+ page.save()
+ parent_page = page
+
+ assert page.get_page_of_level(2).slug == 'level2'
+ assert page.get_page_of_level(4).slug == 'level4'
+ assert page.get_page_of_level(14) is None
+
+def test_page_siblings():
+ Page.objects.all().delete()
+ page = Page()
+ page.slug = 'foo'
+ page.save()
+ page2 = Page()
+ page2.slug = 'bar'
+ page2.parent = page
+ page2.save()
+ page3 = Page()
+ page3.slug = 'baz'
+ page3.parent = page
+ page3.save()
+ assert [x.slug for x in page3.get_siblings()] == ['bar', 'baz']
+
+ assert page.has_children()
+ assert not page2.has_children()
+
+def test_flat_hierarchy():
+ Page.objects.all().delete()
+ page = Page()
+ page.slug = 'foo'
+ page.save()
+ page2 = Page()
+ page2.slug = 'bar'
+ page2.parent = page
+ page2.save()
+ page3 = Page()
+ page3.slug = 'baz'
+ page3.parent = page
+ page3.save()
+
+ pages = Page.get_as_reordered_flat_hierarchy(Page.objects.all())
+ assert [x.slug for x in pages] == ['foo', 'bar', 'baz']
+
+ page.order = 17
+ page.save()
+ pages = Page.get_as_reordered_flat_hierarchy(Page.objects.all())
+ assert [x.slug for x in pages] == ['foo', 'bar', 'baz']
+
+ page2.parent = None
+ page2.save()
+ pages = Page.get_as_reordered_flat_hierarchy(Page.objects.all())
+ assert [x.slug for x in pages] == ['bar', 'foo', 'baz']
+
+ page.parent = page2
+ page.save()
+ pages = Page.get_as_reordered_flat_hierarchy(Page.objects.all())
+ assert [x.slug for x in pages] == ['bar', 'foo', 'baz']
+
+def test_page_visibility():
+ page = Page()
+ assert page.is_visible()
+
+ page.public = False
+ page.save()
+ assert not page.is_visible()
+
+ group = Group(name='foobar')
+ group.save()
+ user1 = User(username='foo')
+ user1.save()
+ user1.groups = [group]
+ user2 = User(username='bar')
+ user2.save()
+
+ assert page.is_visible(user1)
+ assert page.is_visible(user2)
+
+ page.groups = [group]
+ assert not page.is_visible()
+ assert page.is_visible(user1)
+ assert not page.is_visible(user2)