Merge pull request #226 from nephila/feature/knocker_tests
Add knocker tests
This commit is contained in:
commit
98a2eeb299
7 changed files with 111 additions and 37 deletions
|
@ -13,7 +13,6 @@ HELPER_SETTINGS = dict(
|
|||
'filer',
|
||||
'parler',
|
||||
'meta',
|
||||
'meta_mixin',
|
||||
'easy_thumbnails',
|
||||
'django.contrib.sitemaps',
|
||||
'djangocms_text_ckeditor',
|
||||
|
@ -91,7 +90,7 @@ HELPER_SETTINGS = dict(
|
|||
FILE_UPLOAD_TEMP_DIR=mkdtemp(),
|
||||
SITE_ID=1,
|
||||
HAYSTACK_CONNECTIONS={
|
||||
"default": {}
|
||||
'default': {}
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -110,10 +109,29 @@ try:
|
|||
except ImportError:
|
||||
pass
|
||||
|
||||
try:
|
||||
import meta_mixin # pragma: no cover # NOQA
|
||||
HELPER_SETTINGS['INSTALLED_APPS'].append('meta_mixin')
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
try:
|
||||
import knocker # pragma: no cover # NOQA
|
||||
HELPER_SETTINGS['INSTALLED_APPS'].append('knocker')
|
||||
HELPER_SETTINGS['CHANNEL_LAYERS'] = {
|
||||
'default': {
|
||||
'BACKEND': 'asgiref.inmemory.ChannelLayer',
|
||||
'ROUTING': 'knocker.routing.channel_routing',
|
||||
},
|
||||
}
|
||||
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def run():
|
||||
from djangocms_helper import runner
|
||||
runner.cms('djangocms_blog')
|
||||
|
||||
if __name__ == "__main__":
|
||||
if __name__ == '__main__':
|
||||
run()
|
||||
|
|
|
@ -17,6 +17,7 @@ from djangocms_text_ckeditor.fields import HTMLField
|
|||
from filer.fields.image import FilerImageField
|
||||
from meta_mixin.models import ModelMeta
|
||||
from parler.models import TranslatableModel, TranslatedFields
|
||||
from parler.utils.context import switch_language
|
||||
from taggit_autosuggest.managers import TaggableManager
|
||||
|
||||
from .cms_appconfig import BlogConfig
|
||||
|
@ -203,22 +204,25 @@ class Post(KnockerModel, ModelMeta, TranslatableModel):
|
|||
super(Post, self).save_translation(translation, *args, **kwargs)
|
||||
|
||||
def get_absolute_url(self, lang=None):
|
||||
if not lang:
|
||||
if not lang or lang not in self.get_available_languages():
|
||||
lang = self.get_current_language()
|
||||
if not lang or lang not in self.get_available_languages():
|
||||
lang = get_language()
|
||||
category = self.categories.first()
|
||||
kwargs = {}
|
||||
urlconf = get_setting('PERMALINK_URLS')[self.app_config.url_patterns]
|
||||
if '<year>' in urlconf:
|
||||
kwargs['year'] = self.date_published.year
|
||||
if '<month>' in urlconf:
|
||||
kwargs['month'] = '%02d' % self.date_published.month
|
||||
if '<day>' in urlconf:
|
||||
kwargs['day'] = '%02d' % self.date_published.day
|
||||
if '<slug>' in urlconf:
|
||||
kwargs['slug'] = self.safe_translation_getter('slug', language_code=lang, any_language=True) # NOQA
|
||||
if '<category>' in urlconf:
|
||||
kwargs['category'] = category.safe_translation_getter('slug', language_code=lang, any_language=True) # NOQA
|
||||
return reverse('%s:post-detail' % self.app_config.namespace, kwargs=kwargs)
|
||||
with switch_language(self, lang):
|
||||
category = self.categories.first()
|
||||
kwargs = {}
|
||||
urlconf = get_setting('PERMALINK_URLS')[self.app_config.url_patterns]
|
||||
if '<year>' in urlconf:
|
||||
kwargs['year'] = self.date_published.year
|
||||
if '<month>' in urlconf:
|
||||
kwargs['month'] = '%02d' % self.date_published.month
|
||||
if '<day>' in urlconf:
|
||||
kwargs['day'] = '%02d' % self.date_published.day
|
||||
if '<slug>' in urlconf:
|
||||
kwargs['slug'] = self.safe_translation_getter('slug', language_code=lang, any_language=True) # NOQA
|
||||
if '<category>' in urlconf:
|
||||
kwargs['category'] = category.safe_translation_getter('slug', language_code=lang, any_language=True) # NOQA
|
||||
return reverse('%s:post-detail' % self.app_config.namespace, kwargs=kwargs)
|
||||
|
||||
def get_meta_attribute(self, param):
|
||||
"""
|
||||
|
|
3
setup.py
3
setup.py
|
@ -36,8 +36,7 @@ setup(
|
|||
'django-taggit-autosuggest',
|
||||
'djangocms-text-ckeditor',
|
||||
'cmsplugin-filer',
|
||||
'django-meta>=0.2',
|
||||
'django-meta-mixin>=0.2.1',
|
||||
'django-meta>=1.1',
|
||||
'aldryn-apphooks-config>=0.2.6',
|
||||
'djangocms-apphook-setup',
|
||||
'aldryn-search'
|
||||
|
|
|
@ -40,8 +40,8 @@ class MenuTest(BaseTest):
|
|||
"""
|
||||
Tests if all categories are present in the menu
|
||||
"""
|
||||
posts = self.get_posts()
|
||||
pages = self.get_pages()
|
||||
posts = self.get_posts()
|
||||
self.reload_urlconf()
|
||||
|
||||
for lang in ('en', 'it'):
|
||||
|
@ -66,8 +66,8 @@ class MenuTest(BaseTest):
|
|||
"""
|
||||
Tests menu structure based on menu_structure configuration
|
||||
"""
|
||||
posts = self.get_posts()
|
||||
self.get_pages()
|
||||
posts = self.get_posts()
|
||||
|
||||
cats_url = {}
|
||||
posts_url = {}
|
||||
|
@ -77,7 +77,7 @@ class MenuTest(BaseTest):
|
|||
for lang in languages:
|
||||
with smart_override(lang):
|
||||
cats_url[lang] = set([cat.get_absolute_url() for cat in self.cats if cat.has_translation(lang)])
|
||||
posts_url[lang] = set([post.get_absolute_url() for post in posts if post.has_translation(lang) and post.app_config == self.app_config_1])
|
||||
posts_url[lang] = set([post.get_absolute_url(lang) for post in posts if post.has_translation(lang) and post.app_config == self.app_config_1])
|
||||
|
||||
# No item in the menu
|
||||
self.app_config_1.app_data.config.menu_structure = MENU_TYPE_NONE
|
||||
|
@ -132,8 +132,8 @@ class MenuTest(BaseTest):
|
|||
Tests if correct category is selected in the menu
|
||||
according to context (view object)
|
||||
"""
|
||||
posts = self.get_posts()
|
||||
pages = self.get_pages()
|
||||
posts = self.get_posts()
|
||||
|
||||
tests = (
|
||||
# view class, view kwarg, view object, category
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import re
|
||||
from contextlib import contextmanager
|
||||
from copy import deepcopy
|
||||
from datetime import timedelta
|
||||
|
||||
|
@ -19,6 +20,7 @@ from django.utils.html import strip_tags
|
|||
from django.utils.timezone import now
|
||||
from django.utils.translation import get_language, override
|
||||
from djangocms_helper.utils import CMS_30
|
||||
from parler.utils.context import smart_override
|
||||
from taggit.models import Tag
|
||||
|
||||
from djangocms_blog.cms_appconfig import BlogConfig, BlogConfigForm
|
||||
|
@ -27,6 +29,18 @@ from djangocms_blog.settings import get_setting
|
|||
|
||||
from .base import BaseTest
|
||||
|
||||
try:
|
||||
from unittest import SkipTest
|
||||
except ImportError:
|
||||
from django.utils.unittest import SkipTest
|
||||
|
||||
try:
|
||||
from knocker.signals import pause_knocks
|
||||
except ImportError:
|
||||
@contextmanager
|
||||
def pause_knocks(obj):
|
||||
yield
|
||||
|
||||
|
||||
class AdminTest(BaseTest):
|
||||
|
||||
|
@ -236,17 +250,18 @@ class AdminTest(BaseTest):
|
|||
pages = self.get_pages()
|
||||
post = self._get_post(self._post_data[0]['en'])
|
||||
|
||||
with self.login_user_context(self.user):
|
||||
with self.settings(BLOG_USE_PLACEHOLDER=False):
|
||||
data = {'post_text': 'ehi text', 'title': 'some title'}
|
||||
request = self.post_request(pages[0], 'en', user=self.user, data=data, path='/en/?edit_fields=post_text')
|
||||
msg_mid = MessageMiddleware()
|
||||
msg_mid.process_request(request)
|
||||
post_admin = admin.site._registry[Post]
|
||||
response = post_admin.edit_field(request, post.pk, 'en')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
modified_post = Post.objects.language('en').get(pk=post.pk)
|
||||
self.assertEqual(modified_post.safe_translation_getter('post_text'), data['post_text'])
|
||||
with pause_knocks(post):
|
||||
with self.login_user_context(self.user):
|
||||
with self.settings(BLOG_USE_PLACEHOLDER=False):
|
||||
data = {'post_text': 'ehi text', 'title': 'some title'}
|
||||
request = self.post_request(pages[0], 'en', user=self.user, data=data, path='/en/?edit_fields=post_text')
|
||||
msg_mid = MessageMiddleware()
|
||||
msg_mid.process_request(request)
|
||||
post_admin = admin.site._registry[Post]
|
||||
response = post_admin.edit_field(request, post.pk, 'en')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
modified_post = Post.objects.language('en').get(pk=post.pk)
|
||||
self.assertEqual(modified_post.safe_translation_getter('post_text'), data['post_text'])
|
||||
|
||||
|
||||
class ModelsTest(BaseTest):
|
||||
|
@ -416,6 +431,7 @@ class ModelsTest(BaseTest):
|
|||
self.assertTrue(re.match(r'.*/%s/$' % post.slug, post.get_absolute_url()))
|
||||
|
||||
def test_manager(self):
|
||||
self.get_pages()
|
||||
post1 = self._get_post(self._post_data[0]['en'])
|
||||
post2 = self._get_post(self._post_data[1]['en'])
|
||||
|
||||
|
@ -595,6 +611,7 @@ class ModelsTest(BaseTest):
|
|||
self.assertEqual(set(list(Post.objects.all().on_site())), set([post2, post3]))
|
||||
|
||||
def test_str_repr(self):
|
||||
self.get_pages()
|
||||
post1 = self._get_post(self._post_data[0]['en'])
|
||||
post1.meta_description = ''
|
||||
post1.main_image = None
|
||||
|
@ -615,3 +632,36 @@ class ModelsTest(BaseTest):
|
|||
|
||||
plugin = add_plugin(post1.content, 'BlogArchivePlugin', language='en', app_config=self.app_config_1)
|
||||
self.assertEqual(force_text(plugin.__str__()), 'generic blog plugin')
|
||||
|
||||
|
||||
class KnockerTest(BaseTest):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
try:
|
||||
import knocker
|
||||
super(KnockerTest, cls).setUpClass()
|
||||
except ImportError:
|
||||
raise SkipTest('django-knocker not installed, skipping tests')
|
||||
|
||||
def test_model_attributes(self):
|
||||
self.get_pages()
|
||||
posts = self.get_posts()
|
||||
|
||||
for language in posts[0].get_available_languages():
|
||||
with smart_override(language):
|
||||
posts[0].set_current_language(language)
|
||||
knock_create = posts[0].as_knock(True)
|
||||
self.assertEqual(knock_create['title'],
|
||||
'new {0}'.format(posts[0]._meta.verbose_name))
|
||||
self.assertEqual(knock_create['message'], posts[0].title)
|
||||
self.assertEqual(knock_create['language'], language)
|
||||
|
||||
for language in posts[0].get_available_languages():
|
||||
with smart_override(language):
|
||||
posts[0].set_current_language(language)
|
||||
knock_create = posts[0].as_knock(False)
|
||||
self.assertEqual(knock_create['title'],
|
||||
'new {0}'.format(posts[0]._meta.verbose_name))
|
||||
self.assertEqual(knock_create['message'], posts[0].title)
|
||||
self.assertEqual(knock_create['language'], language)
|
||||
|
|
|
@ -30,6 +30,7 @@ class WizardTest(BaseTest):
|
|||
except ImportError:
|
||||
# Not in django CMS 3.2+, no cleanup needed
|
||||
pass
|
||||
super(WizardTest, self).setUp()
|
||||
|
||||
@skipIf(LooseVersion(cms.__version__) < LooseVersion('3.2'),
|
||||
reason='Wizards not available for django CMS < 3.2')
|
||||
|
|
6
tox.ini
6
tox.ini
|
@ -1,5 +1,5 @@
|
|||
[tox]
|
||||
envlist = pep8,isort,py{35,34,27}-django{19}-cms{32},py{35,34,33,27}-django{18}-cms{32,31},py{34,33,27}-django{17,16}-cms{32,31,30},py{26}-django16-cms{31,30}
|
||||
envlist = pep8,isort,py{35,34,27}-django{19}-{cms32,knocker},py{35,34,33,27}-django{18}-cms{32,31},py{34,33,27}-django{17,16}-cms{32,31,30},py{26}-django16-cms{31,30}
|
||||
|
||||
[testenv]
|
||||
commands = {env:COMMAND:python} cms_helper.py test djangocms_blog --no-migrate
|
||||
|
@ -18,7 +18,9 @@ deps =
|
|||
cms30: https://github.com/divio/django-cms/archive/support/3.0.x.zip
|
||||
cms31: https://github.com/divio/django-cms/archive/support/3.1.x.zip
|
||||
cms32: https://github.com/divio/django-cms/archive/release/3.2.x.zip
|
||||
https://github.com/nephila/django-meta-mixin/archive/master.zip
|
||||
knocker: https://github.com/divio/django-cms/archive/release/3.2.x.zip
|
||||
knocker: https://github.com/nephila/django-knocker/archive/master.zip?0.1.1
|
||||
django-meta>=1.0b3
|
||||
https://github.com/nephila/djangocms-helper/archive/develop.zip
|
||||
py26: unittest2
|
||||
https://github.com/aldryn/aldryn-apphooks-config/archive/master.zip
|
||||
|
|
Loading…
Reference in a new issue