Merge pull request #212 from nephila/feature/test_copy_relations

Fix copy relations
This commit is contained in:
Iacopo Spalletti 2016-02-27 07:18:36 +01:00
commit d2b2995bbf
4 changed files with 53 additions and 2 deletions

View file

@ -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)
++++++++++++++++++

View file

@ -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)

View file

@ -59,6 +59,24 @@ class PluginTest(BaseTest):
self.assertTrue(rendered.find('<article id="post-second-post"') > -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()

View file

@ -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)