From a1497360b10b8dc46730b3985bafdbb3b4d46c4c Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sat, 26 Sep 2015 10:38:57 +0200 Subject: [PATCH] Code cleanup --- djangocms_blog/admin.py | 4 +- djangocms_blog/cms_plugins.py | 1 - .../migrations/0010_auto_20150923_1151.py | 6 +- djangocms_blog/models.py | 5 +- tests/__init__.py | 15 +---- tests/test_models.py | 2 +- tests/test_views.py | 59 ++++++++----------- tox.ini | 2 +- 8 files changed, 38 insertions(+), 56 deletions(-) diff --git a/djangocms_blog/admin.py b/djangocms_blog/admin.py index db966e1..1d50b13 100755 --- a/djangocms_blog/admin.py +++ b/djangocms_blog/admin.py @@ -125,8 +125,8 @@ class BlogConfigAdmin(BaseAppHookConfig, TranslatableAdmin): def get_config_fields(self): return ( - 'app_title', 'paginate_by', 'set_author', 'config.default_published', - 'config.use_placeholder' + 'app_title', 'config.paginate_by', 'config.set_author', 'config.default_published', + 'config.use_placeholder', 'config.use_abstract', ) admin.site.register(BlogCategory, BlogCategoryAdmin) diff --git a/djangocms_blog/cms_plugins.py b/djangocms_blog/cms_plugins.py index ea8b522..d115b78 100644 --- a/djangocms_blog/cms_plugins.py +++ b/djangocms_blog/cms_plugins.py @@ -56,7 +56,6 @@ class BlogAuthorPostsPlugin(BlogPlugin): module = _('Blog') name = _('Author Blog Articles') model = AuthorEntriesPlugin - form = LatestEntriesForm render_template = 'djangocms_blog/plugins/authors.html' filter_horizontal = ['authors'] diff --git a/djangocms_blog/migrations/0010_auto_20150923_1151.py b/djangocms_blog/migrations/0010_auto_20150923_1151.py index 25db956..96d3e67 100644 --- a/djangocms_blog/migrations/0010_auto_20150923_1151.py +++ b/djangocms_blog/migrations/0010_auto_20150923_1151.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals import aldryn_apphooks_config.fields import app_data.fields import djangocms_text_ckeditor.fields - from cms.models import Page from cms.utils.conf import get_languages from django.db import models, migrations @@ -114,5 +113,10 @@ class Migration(migrations.Migration): name='blogconfigtranslation', unique_together=set([('language_code', 'master')]), ), + migrations.AlterField( + model_name='post', + name='sites', + field=models.ManyToManyField(to='sites.Site', help_text='Select sites in which to show the post. If none is set it will be visible in all the configured sites.', blank=True, verbose_name='Site(s)'), + ), migrations.RunPython(forwards, backwards) ] diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index af0ee36..54aa6cf 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -113,10 +113,9 @@ class Post(ModelMeta, TranslatableModel): enable_comments = models.BooleanField(verbose_name=_('enable comments on post'), default=get_setting('ENABLE_COMMENTS')) sites = models.ManyToManyField('sites.Site', verbose_name=_('Site(s)'), blank=True, - null=True, help_text=_('Select sites in which to show the post. ' - u'If none is set it will be ' - u'visible in all the configured sites.')) + 'If none is set it will be ' + 'visible in all the configured sites.')) app_config = AppHookConfigField(BlogConfig, verbose_name=_('app. config')) translations = TranslatedFields( diff --git a/tests/__init__.py b/tests/__init__.py index 229cea7..fe9cbfe 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -127,19 +127,6 @@ class BaseTest(BaseTestCase): cls.category_1.save() cls.site_2 = Site.objects.create(domain='http://example2.com', name='example 2') - def setUp(self): - super(BaseTest, self).setUp() - self.img = self.create_filer_image_object() - - def tearDown(self): - Post.objects.all().delete() - super(BaseTest, self).tearDown() - - @classmethod - def tearDownClass(cls): - BlogConfig.objects.all().delete() - super(BaseTest, cls).tearDownClass() - def _get_category(self, data, category=None, lang='en'): data = deepcopy(data) for k, v in data.items(): @@ -188,7 +175,7 @@ class BaseTest(BaseTestCase): post1 = self._get_post(post['en'], sites=sites) post1 = self._get_post(post['it'], post=post1, lang='it') post1.publish = post['en']['publish'] - post1.main_image = self.img + post1.main_image = self.create_filer_image_object() post1.save() posts.append(post1) return posts diff --git a/tests/test_models.py b/tests/test_models.py index db01203..3004bbb 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -147,7 +147,7 @@ class ModelsTest(BaseTest): def test_model_attributes(self): post = self._get_post(self._post_data[0]['en']) post = self._get_post(self._post_data[0]['it'], post, 'it') - post.main_image = self.img + post.main_image = self.create_filer_image_object() post.save() post.set_current_language('en') meta_en = post.as_meta() diff --git a/tests/test_views.py b/tests/test_views.py index c257472..adc716b 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, print_function, unicode_literals +from aldryn_apphooks_config.utils import get_app_instance from django.contrib.auth.models import AnonymousUser from django.http import Http404 @@ -24,24 +25,25 @@ class ViewTest(BaseTest): posts = self.get_posts() pages = self.get_pages() - request = self.get_page_request(pages[0], AnonymousUser(), r'/en/blog/', edit=False) + request = self.get_request(pages[1], 'en', AnonymousUser()) with smart_override('en'): view_obj = PostListView() view_obj.request = request - view_obj.namespace = self.app_config_1.namespace - view_obj.config = self.app_config_1 + view_obj.namespace, view_obj.config = get_app_instance(request) self.assertEqual(list(view_obj.get_queryset()), [posts[0]]) - request = self.get_page_request(pages[1], self.user, edit=False) + request = self.get_page_request(pages[1], self.user, lang='en', edit=False) + view_obj.namespace, view_obj.config = get_app_instance(request) view_obj.request = request view_obj.kwargs = {} qs = view_obj.get_queryset() self.assertEqual(qs.count(), 1) self.assertEqual(set(qs), set([posts[0]])) - request = self.get_page_request(pages[1], self.user, edit=True) + request = self.get_page_request(pages[1], self.user, lang='en', edit=True) + view_obj.namespace, view_obj.config = get_app_instance(request) view_obj.request = request self.assertEqual(set(view_obj.get_queryset()), set([posts[0], posts[1], posts[2]])) @@ -58,6 +60,7 @@ class ViewTest(BaseTest): with smart_override('it'): request = self.get_page_request(pages[1], self.user, lang='it', edit=True) + view_obj.namespace, view_obj.config = get_app_instance(request) view_obj.request = request view_obj.object_list = view_obj.get_queryset() context = view_obj.get_context_data(object_list=view_obj.object_list) @@ -83,10 +86,9 @@ class ViewTest(BaseTest): with smart_override('fr'): view_obj = PostListView() - request = self.get_page_request(pages[0], self.user, r'/fr/blog/', lang='fr', edit=True) + request = self.get_page_request(pages[1], self.user, lang='fr', edit=True) view_obj.request = request - view_obj.namespace = self.app_config_1.namespace - view_obj.config = self.app_config_1 + view_obj.namespace, view_obj.config = get_app_instance(request) view_obj.kwargs = {} view_obj.object_list = view_obj.get_queryset() view_obj.get_context_data(object_list=view_obj.object_list) @@ -96,10 +98,9 @@ class ViewTest(BaseTest): with override_parler_settings(PARLER_LANGUAGES=PARLER_FALLBACK): view_obj = PostListView() - request = self.get_page_request(pages[0], self.user, r'/fr/blog/', lang='fr', edit=True) + request = self.get_page_request(pages[1], self.user, lang='fr', edit=True) view_obj.request = request - view_obj.namespace = self.app_config_1.namespace - view_obj.config = self.app_config_1 + view_obj.namespace, view_obj.config = get_app_instance(request) view_obj.kwargs = {} view_obj.object_list = view_obj.get_queryset() view_obj.get_context_data(object_list=view_obj.object_list) @@ -111,11 +112,10 @@ class ViewTest(BaseTest): with smart_override('en'): with switch_language(posts[0], 'en'): - request = self.get_page_request(pages[0], AnonymousUser(), r'/en/blog/', edit=False) + request = self.get_page_request(pages[1], AnonymousUser(), lang='en', edit=False) view_obj = PostDetailView() view_obj.request = request - view_obj.namespace = self.app_config_1.namespace - view_obj.config = self.app_config_1 + view_obj.namespace, view_obj.config = get_app_instance(request) with self.assertRaises(Http404): view_obj.kwargs = {'slug': 'not-existing'} @@ -128,11 +128,10 @@ class ViewTest(BaseTest): with smart_override('it'): with switch_language(posts[0], 'it'): - request = self.get_page_request(pages[0], AnonymousUser(), r'/it/blog/', lang='it', edit=False) + request = self.get_page_request(pages[1], AnonymousUser(), lang='it', edit=False) view_obj = PostDetailView() view_obj.request = request - view_obj.namespace = self.app_config_1.namespace - view_obj.config = self.app_config_1 + view_obj.namespace, view_obj.config = get_app_instance(request) view_obj.kwargs = {'slug': posts[0].slug} post_obj = view_obj.get_object() @@ -150,11 +149,10 @@ class ViewTest(BaseTest): pages = self.get_pages() with smart_override('en'): - request = self.get_page_request(pages[0], AnonymousUser(), r'/en/blog/', edit=False) + request = self.get_page_request(pages[1], AnonymousUser(), lang='en', edit=False) view_obj = PostArchiveView() view_obj.request = request - view_obj.namespace = self.app_config_1.namespace - view_obj.config = self.app_config_1 + view_obj.namespace, view_obj.config = get_app_instance(request) view_obj.kwargs = {'year': now().year, 'month': now().month} # One post only, anonymous request @@ -171,11 +169,10 @@ class ViewTest(BaseTest): pages = self.get_pages() with smart_override('en'): - request = self.get_page_request(pages[0], self.user, r'/en/blog/', edit=True) + request = self.get_page_request(pages[1], self.user, lang='en', edit=True) view_obj = CategoryEntriesView() view_obj.request = request - view_obj.namespace = self.app_config_1.namespace - view_obj.config = self.app_config_1 + view_obj.namespace, view_obj.config = get_app_instance(request) view_obj.kwargs = {'category': 'category-1'} qs = view_obj.get_queryset() self.assertEqual(qs.count(), 3) @@ -201,10 +198,9 @@ class ViewTest(BaseTest): pages = self.get_pages() with smart_override('en'): - request = self.get_page_request(pages[1], self.user, edit=True) + request = self.get_page_request(pages[1], self.user, lang='en', edit=True) view_obj = AuthorEntriesView() - view_obj.namespace = self.app_config_1.namespace - view_obj.config = self.app_config_1 + view_obj.namespace, view_obj.config = get_app_instance(request) view_obj.request = request view_obj.kwargs = {'username': self.user.get_username()} qs = view_obj.get_queryset() @@ -235,11 +231,10 @@ class ViewTest(BaseTest): posts[1].save() with smart_override('en'): - request = self.get_page_request(pages[1], self.user, edit=True) + request = self.get_page_request(pages[1], self.user, lang='en', edit=True) view_obj = TaggedListView() view_obj.request = request - view_obj.namespace = self.app_config_1.namespace - view_obj.config = self.app_config_1 + view_obj.namespace, view_obj.config = get_app_instance(request) view_obj.kwargs = {'tag': 'tag-2'} qs = view_obj.get_queryset() self.assertEqual(qs.count(), 2) @@ -269,8 +264,7 @@ class ViewTest(BaseTest): request = self.get_page_request(pages[1], self.user, path=posts[0].get_absolute_url()) feed = LatestEntriesFeed() - feed.namespace = self.app_config_1.namespace - feed.config = self.app_config_1 + feed.namespace, feed.config = get_app_instance(request) self.assertEqual(list(feed.items()), [posts[0]]) self.reload_urlconf() xml = feed(request) @@ -280,8 +274,7 @@ class ViewTest(BaseTest): with smart_override('it'): with switch_language(posts[0], 'it'): feed = LatestEntriesFeed() - feed.namespace = self.app_config_1.namespace - feed.config = self.app_config_1 + feed.namespace, feed.config = get_app_instance(request) self.assertEqual(list(feed.items()), [posts[0]]) request = self.get_page_request(pages[1], self.user, path=posts[0].get_absolute_url()) xml = feed(request) diff --git a/tox.ini b/tox.ini index 34b82dd..2dbc0d7 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ envlist = py{26}-django16-cms{30,31},py{27,33,34}-django{16,17}-cms{30,31,32},py{27,33,34}-django{18,19}-cms{31,32},pep8,isort [testenv] -commands = {env:COMMAND:python} setup.py test +commands = {env:COMMAND:python} cms_helper.py test djangocms_blog --no-migrate deps = django16: Django>=1.6,<1.7 django17: Django>=1.7,<1.8