Fix tests for issues discovered when testing with knocker

This commit is contained in:
Iacopo Spalletti 2016-04-08 16:17:47 +02:00
parent 0e07f9a850
commit 4503a14b4f
5 changed files with 30 additions and 21 deletions

View file

@ -90,7 +90,7 @@ HELPER_SETTINGS = dict(
FILE_UPLOAD_TEMP_DIR=mkdtemp(), FILE_UPLOAD_TEMP_DIR=mkdtemp(),
SITE_ID=1, SITE_ID=1,
HAYSTACK_CONNECTIONS={ HAYSTACK_CONNECTIONS={
"default": {} 'default': {}
} }
) )
@ -133,5 +133,5 @@ def run():
from djangocms_helper import runner from djangocms_helper import runner
runner.cms('djangocms_blog') runner.cms('djangocms_blog')
if __name__ == "__main__": if __name__ == '__main__':
run() run()

View file

@ -36,8 +36,7 @@ setup(
'django-taggit-autosuggest', 'django-taggit-autosuggest',
'djangocms-text-ckeditor', 'djangocms-text-ckeditor',
'cmsplugin-filer', 'cmsplugin-filer',
'django-meta>=0.2', 'django-meta>=1.1',
'django-meta-mixin>=0.2.1',
'aldryn-apphooks-config>=0.2.6', 'aldryn-apphooks-config>=0.2.6',
'djangocms-apphook-setup', 'djangocms-apphook-setup',
'aldryn-search' 'aldryn-search'

View file

@ -40,8 +40,8 @@ class MenuTest(BaseTest):
""" """
Tests if all categories are present in the menu Tests if all categories are present in the menu
""" """
posts = self.get_posts()
pages = self.get_pages() pages = self.get_pages()
posts = self.get_posts()
self.reload_urlconf() self.reload_urlconf()
for lang in ('en', 'it'): for lang in ('en', 'it'):
@ -66,8 +66,8 @@ class MenuTest(BaseTest):
""" """
Tests menu structure based on menu_structure configuration Tests menu structure based on menu_structure configuration
""" """
posts = self.get_posts()
self.get_pages() self.get_pages()
posts = self.get_posts()
cats_url = {} cats_url = {}
posts_url = {} posts_url = {}
@ -77,7 +77,7 @@ class MenuTest(BaseTest):
for lang in languages: for lang in languages:
with smart_override(lang): with smart_override(lang):
cats_url[lang] = set([cat.get_absolute_url() for cat in self.cats if cat.has_translation(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 # No item in the menu
self.app_config_1.app_data.config.menu_structure = MENU_TYPE_NONE 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 Tests if correct category is selected in the menu
according to context (view object) according to context (view object)
""" """
posts = self.get_posts()
pages = self.get_pages() pages = self.get_pages()
posts = self.get_posts()
tests = ( tests = (
# view class, view kwarg, view object, category # view class, view kwarg, view object, category

View file

@ -2,6 +2,7 @@
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
import re import re
from contextlib import contextmanager
from copy import deepcopy from copy import deepcopy
from datetime import timedelta from datetime import timedelta
@ -33,6 +34,13 @@ try:
except ImportError: except ImportError:
from django.utils.unittest import SkipTest from django.utils.unittest import SkipTest
try:
from knocker.signals import pause_knocks
except ImportError:
@contextmanager
def pause_knocks(obj):
yield
class AdminTest(BaseTest): class AdminTest(BaseTest):
@ -242,17 +250,18 @@ class AdminTest(BaseTest):
pages = self.get_pages() pages = self.get_pages()
post = self._get_post(self._post_data[0]['en']) post = self._get_post(self._post_data[0]['en'])
with self.login_user_context(self.user): with pause_knocks(post):
with self.settings(BLOG_USE_PLACEHOLDER=False): with self.login_user_context(self.user):
data = {'post_text': 'ehi text', 'title': 'some title'} with self.settings(BLOG_USE_PLACEHOLDER=False):
request = self.post_request(pages[0], 'en', user=self.user, data=data, path='/en/?edit_fields=post_text') data = {'post_text': 'ehi text', 'title': 'some title'}
msg_mid = MessageMiddleware() request = self.post_request(pages[0], 'en', user=self.user, data=data, path='/en/?edit_fields=post_text')
msg_mid.process_request(request) msg_mid = MessageMiddleware()
post_admin = admin.site._registry[Post] msg_mid.process_request(request)
response = post_admin.edit_field(request, post.pk, 'en') post_admin = admin.site._registry[Post]
self.assertEqual(response.status_code, 200) response = post_admin.edit_field(request, post.pk, 'en')
modified_post = Post.objects.language('en').get(pk=post.pk) self.assertEqual(response.status_code, 200)
self.assertEqual(modified_post.safe_translation_getter('post_text'), data['post_text']) 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): class ModelsTest(BaseTest):
@ -422,6 +431,7 @@ class ModelsTest(BaseTest):
self.assertTrue(re.match(r'.*/%s/$' % post.slug, post.get_absolute_url())) self.assertTrue(re.match(r'.*/%s/$' % post.slug, post.get_absolute_url()))
def test_manager(self): def test_manager(self):
self.get_pages()
post1 = self._get_post(self._post_data[0]['en']) post1 = self._get_post(self._post_data[0]['en'])
post2 = self._get_post(self._post_data[1]['en']) post2 = self._get_post(self._post_data[1]['en'])
@ -601,6 +611,7 @@ class ModelsTest(BaseTest):
self.assertEqual(set(list(Post.objects.all().on_site())), set([post2, post3])) self.assertEqual(set(list(Post.objects.all().on_site())), set([post2, post3]))
def test_str_repr(self): def test_str_repr(self):
self.get_pages()
post1 = self._get_post(self._post_data[0]['en']) post1 = self._get_post(self._post_data[0]['en'])
post1.meta_description = '' post1.meta_description = ''
post1.main_image = None post1.main_image = None

View file

@ -19,8 +19,7 @@ deps =
cms31: https://github.com/divio/django-cms/archive/support/3.1.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 cms32: https://github.com/divio/django-cms/archive/release/3.2.x.zip
knocker: https://github.com/divio/django-cms/archive/release/3.2.x.zip knocker: https://github.com/divio/django-cms/archive/release/3.2.x.zip
knocker: https://github.com/nephila/django-knocker/archive/master.zip knocker: https://github.com/nephila/django-knocker/archive/master.zip?0.1.1
https://github.com/nephila/django-meta-mixin/archive/develop.zip
django-meta>=1.0b3 django-meta>=1.0b3
https://github.com/nephila/djangocms-helper/archive/develop.zip https://github.com/nephila/djangocms-helper/archive/develop.zip
py26: unittest2 py26: unittest2