2015-10-18 09:45:00 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from cms.api import create_page, create_title
|
|
|
|
from cms.models import Page
|
|
|
|
from cms.utils import get_language_list
|
|
|
|
from django.utils.translation import override
|
|
|
|
|
|
|
|
from djangocms_blog.cms_appconfig import BlogConfig
|
|
|
|
|
2015-10-18 11:16:43 +00:00
|
|
|
from .base import BaseTest
|
2015-10-18 09:45:00 +00:00
|
|
|
|
2016-09-03 20:23:16 +00:00
|
|
|
try:
|
|
|
|
from django.test import override_settings
|
|
|
|
except ImportError:
|
|
|
|
from django.test.utils import override_settings
|
2015-10-18 09:45:00 +00:00
|
|
|
|
2016-09-03 20:23:16 +00:00
|
|
|
|
|
|
|
@override_settings(BLOG_AUTO_SETUP=True)
|
2015-10-18 09:45:00 +00:00
|
|
|
class SetupTest(BaseTest):
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2015-10-25 16:02:05 +00:00
|
|
|
# Skipping initialization to start with clean database
|
2015-10-18 09:45:00 +00:00
|
|
|
super(BaseTest, cls).setUpClass()
|
|
|
|
|
2015-10-25 16:02:05 +00:00
|
|
|
def setUp(self):
|
|
|
|
super(SetupTest, self).setUp()
|
|
|
|
from cms.apphook_pool import apphook_pool
|
|
|
|
|
|
|
|
delete = [
|
|
|
|
'djangocms_blog',
|
|
|
|
'djangocms_blog.cms_app',
|
|
|
|
'djangocms_blog.cms_apps',
|
|
|
|
]
|
|
|
|
for module in delete:
|
|
|
|
if module in sys.modules:
|
|
|
|
del sys.modules[module]
|
|
|
|
BlogConfig.cmsapp = None
|
|
|
|
apphook_pool.clear()
|
|
|
|
|
2015-10-18 09:45:00 +00:00
|
|
|
def test_setup_from_url(self):
|
|
|
|
|
|
|
|
# Tests starts with no page and no config
|
|
|
|
self.assertFalse(Page.objects.exists())
|
|
|
|
self.assertFalse(BlogConfig.objects.exists())
|
|
|
|
|
2015-10-25 16:02:05 +00:00
|
|
|
# importing cms_app triggers the auto setup
|
2016-08-26 06:56:27 +00:00
|
|
|
from djangocms_blog import cms_apps # NOQA
|
2015-10-18 09:45:00 +00:00
|
|
|
|
|
|
|
# Home and blog, published and draft
|
|
|
|
self.assertEqual(Page.objects.count(), 4)
|
|
|
|
self.assertEqual(BlogConfig.objects.count(), 1)
|
|
|
|
|
|
|
|
def test_setup_filled(self):
|
|
|
|
|
|
|
|
# Tests starts with no page and no config
|
|
|
|
self.assertFalse(Page.objects.exists())
|
|
|
|
self.assertFalse(BlogConfig.objects.exists())
|
2018-01-14 11:54:44 +00:00
|
|
|
set_home = hasattr(Page, 'set_as_homepage')
|
2015-10-18 09:45:00 +00:00
|
|
|
|
|
|
|
langs = get_language_list()
|
|
|
|
home = None
|
|
|
|
for lang in langs:
|
|
|
|
with override(lang):
|
|
|
|
if not home:
|
|
|
|
home = create_page(
|
|
|
|
'a new home', language=lang,
|
2015-10-18 10:46:50 +00:00
|
|
|
template='blog.html', in_navigation=True, published=True
|
2015-10-18 09:45:00 +00:00
|
|
|
)
|
2018-01-14 11:54:44 +00:00
|
|
|
if set_home:
|
|
|
|
home.set_as_homepage()
|
2015-10-18 09:45:00 +00:00
|
|
|
else:
|
|
|
|
create_title(
|
|
|
|
language=lang, title='a new home', page=home
|
|
|
|
)
|
|
|
|
home.publish(lang)
|
|
|
|
|
2015-10-25 16:02:05 +00:00
|
|
|
# importing cms_app triggers the auto setup
|
2016-08-26 06:56:27 +00:00
|
|
|
from djangocms_blog import cms_apps # NOQA
|
2015-10-18 09:45:00 +00:00
|
|
|
|
|
|
|
# Home and blog, published and draft
|
|
|
|
self.assertEqual(Page.objects.count(), 4)
|
|
|
|
self.assertEqual(BlogConfig.objects.count(), 1)
|
|
|
|
|
|
|
|
home = Page.objects.get_home()
|
|
|
|
for lang in langs:
|
|
|
|
self.assertEqual(home.get_title(lang), 'a new home')
|