diff --git a/HISTORY.rst b/HISTORY.rst index a2d231d..61780a4 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -15,6 +15,7 @@ History * Fix some issues with haystack indexes * Add support for moved ThumbnailOption * Fix Django 1.9 issues +* Fix copy relations method in plugins 0.6.3 (2015-12-22) ++++++++++++++++++ diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index 8de9272..564c570 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -324,6 +324,8 @@ class LatestPostsPlugin(BasePostPlugin): def copy_relations(self, oldinstance): for tag in oldinstance.tags.all(): self.tags.add(tag) + for category in oldinstance.categories.all(): + self.categories.add(category) def get_posts(self, request): posts = self.post_queryset(request) diff --git a/tests/test_plugins.py b/tests/test_plugins.py index cb209f2..8a241d9 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -59,6 +59,24 @@ class PluginTest(BaseTest): self.assertTrue(rendered.find('
-1) self.assertTrue(rendered.find(posts[1].get_absolute_url()) > -1) + # Checking copy relations + ph = pages[0].placeholders.get(slot='content') + original = ph.get_plugins('en') + pages[0].publish('en') + published = pages[0].get_public_object() + ph = published.placeholders.get(slot='content') + new = ph.get_plugins('en') + self.assertNotEqual(original, new) + + casted_tags, __ = new[0].get_plugin_instance() + casted_categories, __ = new[1].get_plugin_instance() + + self.assertEqual(casted_tags.tags.count(), 1) + self.assertEqual(casted_tags.categories.count(), 0) + + self.assertEqual(casted_categories.tags.count(), 0) + self.assertEqual(casted_categories.categories.count(), 1) + def test_plugin_authors(self): pages = self.get_pages() posts = self.get_posts() @@ -73,6 +91,36 @@ class PluginTest(BaseTest): rendered = plugin.render_plugin(context, ph) self.assertTrue(rendered.find('No article found') > -1) + plugin.authors.add(self.user) + context = self.get_plugin_context(pages[0], 'en', plugin, edit=True) + rendered = plugin.render_plugin(context, ph) + self.assertTrue(rendered.find('/en/blog/author/admin/') > -1) + self.assertTrue(rendered.find('2 articles') > -1) + + plugin.authors.add(self.user_staff) + context = self.get_plugin_context(pages[0], 'en', plugin, edit=True) + rendered = plugin.render_plugin(context, ph) + self.assertTrue(rendered.find('/en/blog/author/staff/') > -1) + self.assertTrue(rendered.find('0 articles') > -1) + + plugin.authors.add(self.user_normal) + context = self.get_plugin_context(pages[0], 'en', plugin, edit=True) + rendered = plugin.render_plugin(context, ph) + self.assertTrue(rendered.find('/en/blog/author/normal/') > -1) + self.assertTrue(rendered.find('0 articles') > -1) + + # Checking copy relations + ph = pages[0].placeholders.get(slot='content') + original = ph.get_plugins('en') + pages[0].publish('en') + published = pages[0].get_public_object() + ph = published.placeholders.get(slot='content') + new = ph.get_plugins('en') + self.assertNotEqual(original, new) + + casted_authors, __ = new[0].get_plugin_instance() + self.assertEqual(casted_authors.authors.count(), 3) + def test_plugin_tags(self): pages = self.get_pages() posts = self.get_posts() diff --git a/tests/test_wizards.py b/tests/test_wizards.py index 56fe2a2..b3da377 100644 --- a/tests/test_wizards.py +++ b/tests/test_wizards.py @@ -67,7 +67,7 @@ class WizardTest(BaseTest): }, prefix=1) self.assertEqual(form.default_appconfig, app_config) self.assertTrue(form.is_valid()) - self.assertTrue(form.cleaned_data['app_config'], app_config) + self.assertEqual(form.cleaned_data['app_config'].pk, app_config) instance = form.save() self.assertEqual(instance.author, self.user_staff) @@ -81,7 +81,7 @@ class WizardTest(BaseTest): }, prefix=1) self.assertEqual(form.default_appconfig, app_config) self.assertTrue(form.is_valid()) - self.assertTrue(form.cleaned_data['app_config'], app_config) + self.assertEqual(form.cleaned_data['app_config'].pk, app_config) instance = form.save() self.assertEqual(instance.author, self.user_normal)