Add tests for auto setup

This commit is contained in:
Iacopo Spalletti 2015-10-18 11:45:00 +02:00
parent cd4f6553dd
commit ac42d6cb6e
4 changed files with 77 additions and 2 deletions

View file

@ -4,4 +4,3 @@ __email__ = 'i.spalletti@nephila.it'
__version__ = '0.6.0.dev1' __version__ = '0.6.0.dev1'
default_app_config = 'djangocms_blog.apps.BlogAppConfig' default_app_config = 'djangocms_blog.apps.BlogAppConfig'

View file

@ -2,6 +2,7 @@
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
try: try:
from django.apps import AppConfig from django.apps import AppConfig
except ImportError: except ImportError:
@ -46,7 +47,7 @@ class BlogAppConfig(AppConfig):
get_setting('AUTO_HOME_TITLE'), language=lang, get_setting('AUTO_HOME_TITLE'), language=lang,
template=default_template, in_navigation=True, published=True template=default_template, in_navigation=True, published=True
) )
else: elif lang not in home.get_languages():
create_title( create_title(
language=lang, title=get_setting('AUTO_HOME_TITLE'), page=home language=lang, title=get_setting('AUTO_HOME_TITLE'), page=home
) )

View file

@ -2,6 +2,7 @@
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
from django.conf.urls import patterns, url from django.conf.urls import patterns, url
from .apps import BlogAppConfig from .apps import BlogAppConfig
from .feeds import LatestEntriesFeed, TagFeed from .feeds import LatestEntriesFeed, TagFeed
from .settings import get_setting from .settings import get_setting

74
tests/test_setup.py Normal file
View file

@ -0,0 +1,74 @@
# -*- 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
from . import BaseTest
class SetupTest(BaseTest):
@classmethod
def setUpClass(cls):
super(BaseTest, cls).setUpClass()
def test_setup_from_url(self):
# Tests starts with no page and no config
self.assertFalse(Page.objects.exists())
self.assertFalse(BlogConfig.objects.exists())
# importing urls triggers the auto setup
from djangocms_blog import urls # NOQA
# Home and blog, published and draft
self.assertEqual(Page.objects.count(), 4)
self.assertEqual(BlogConfig.objects.count(), 1)
def setUp(self):
self.reload_urlconf()
delete = [
'djangocms_blog',
'djangocms_blog.urls',
]
for module in delete:
del sys.modules[module]
def test_setup_filled(self):
# Tests starts with no page and no config
self.assertFalse(Page.objects.exists())
self.assertFalse(BlogConfig.objects.exists())
langs = get_language_list()
home = None
for lang in langs:
with override(lang):
if not home:
home = create_page(
'a new home', language=lang,
template='page.html', in_navigation=True, published=True
)
else:
create_title(
language=lang, title='a new home', page=home
)
home.publish(lang)
# importing urls triggers the auto setup
from djangocms_blog import urls # NOQA
# 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')