1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
"""Django page CMS command tests suite module.""" |
3
|
|
|
from pages.models import Page, Content, PageAlias |
4
|
|
|
from pages.tests.testcase import TestCase |
5
|
|
|
from django.core.management import call_command |
6
|
|
|
from django.test import LiveServerTestCase |
7
|
|
|
import json |
8
|
|
|
|
9
|
|
|
class CommandTestCase(TestCase, LiveServerTestCase): |
10
|
|
|
"""Django page CMS command tests suite class.""" |
11
|
|
|
|
12
|
|
|
def test_pull(self): |
13
|
|
|
"""Pull command get the correct data""" |
14
|
|
|
self.new_page(content={'title': 'pull-page', 'slug': 'pull-slug'}) |
15
|
|
|
url = self.live_server_url + '/pages/api/' |
16
|
|
|
filename = '/tmp/test' |
17
|
|
|
call_command('pages_pull', 'admin:b', filename=filename, host=url, verbosity=0) |
18
|
|
|
with open(filename, "r") as f: |
19
|
|
|
data = f.read() |
20
|
|
|
pages = json.loads(data) |
21
|
|
|
for content in pages[0]['content_set']: |
22
|
|
|
self.assertTrue(content['body'] in ['pull-page', 'pull-slug']) |
23
|
|
|
|
24
|
|
|
def test_push(self): |
25
|
|
|
"""Push command put back the content properly""" |
26
|
|
|
url = self.live_server_url + '/pages/api/' |
27
|
|
|
page1 = self.new_page(content={'title': 'pull-page', 'slug': 'pull-slug'}) |
28
|
|
|
page2 = self.new_page(content={'title': 'pull-page-2', 'slug': 'pull-slug-2'}) |
29
|
|
|
call_command('pages_pull', 'admin:b', filename='/tmp/test', host=url, verbosity=0) |
30
|
|
|
page1.delete() |
31
|
|
|
self.assertEqual(Page.objects.all().count(), 1) |
32
|
|
|
call_command('pages_push', 'admin:b', filename='/tmp/test', host=url, verbosity=0) |
33
|
|
|
self.assertEqual(Page.objects.all().count(), 2) |
34
|
|
|
|
35
|
|
|
def test_tree(self): |
36
|
|
|
"""Push command" restore the tree properly""" |
37
|
|
|
url = self.live_server_url + '/pages/api/' |
38
|
|
|
filename = '/tmp/test' |
39
|
|
|
page1 = self.new_page(content={'title': 'pull-page-1', 'slug': 'pull-slug-1'}) |
40
|
|
|
page2 = self.new_page(content={'title': 'pull-page-2', 'slug': 'pull-slug-2'}, parent=page1) |
41
|
|
|
page3 = self.new_page(content={'title': 'pull-page-3', 'slug': 'pull-slug-3'}, parent=page2) |
42
|
|
|
|
43
|
|
|
self.assertSequenceEqual(page1.get_children(), [page2]) |
44
|
|
|
self.assertSequenceEqual(page2.get_children(), [page3]) |
45
|
|
|
|
46
|
|
|
call_command('pages_pull', 'admin:b', filename=filename, host=url, verbosity=0) |
47
|
|
|
page2.move_to(page1, 'left') |
48
|
|
|
|
49
|
|
|
self.assertSequenceEqual(page1.get_children(), []) |
50
|
|
|
self.assertSequenceEqual(page2.get_children(), [page3]) |
51
|
|
|
|
52
|
|
|
call_command('pages_push', 'admin:b', filename='/tmp/test', host=url, verbosity=0) |
53
|
|
|
|
54
|
|
|
self.assertSequenceEqual(page1.get_children(), [page2]) |
55
|
|
|
self.assertSequenceEqual(page2.get_children(), [page3]) |
56
|
|
|
|
57
|
|
|
def test_tree_delete(self): |
58
|
|
|
"""Push command tree delete""" |
59
|
|
|
url = self.live_server_url + '/pages/api/' |
60
|
|
|
filename = '/tmp/test' |
61
|
|
|
page1 = self.new_page(content={'title': 'pull-page-1', 'slug': 'pull-slug-1'}) |
62
|
|
|
page2 = self.new_page(content={'title': 'pull-page-2', 'slug': 'pull-slug-2'}, parent=page1) |
63
|
|
|
page3 = self.new_page(content={'title': 'pull-page-3', 'slug': 'pull-slug-3'}, parent=page2) |
64
|
|
|
|
65
|
|
|
self.assertSequenceEqual(page1.get_children(), [page2]) |
66
|
|
|
self.assertSequenceEqual(page2.get_children(), [page3]) |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
call_command('pages_pull', 'admin:b', filename=filename, host=url, verbosity=0) |
70
|
|
|
|
71
|
|
|
page4 = self.new_page(content={'title': 'pull-page-4', 'slug': 'pull-slug-4'}, parent=page1) |
72
|
|
|
self.assertSequenceEqual(page1.get_children(), [page2, page4]) |
73
|
|
|
page2.delete() |
74
|
|
|
self.assertSequenceEqual(page1.get_children(), [page4]) |
75
|
|
|
|
76
|
|
|
call_command('pages_push', 'admin:b', filename='/tmp/test', host=url, verbosity=0) |
77
|
|
|
|
78
|
|
|
page2 = Page.objects.from_slug('pull-slug-2') |
79
|
|
|
self.assertSequenceEqual(page1.get_children(), [page4, page2]) |
80
|
|
|
|
81
|
|
|
|