first line
') > -1) self.assertTrue(rendered.find('first line
') > -1) self.assertTrue(rendered.find('second post first line
') > -1) self.assertTrue(rendered.find('second post first line
') > -1) posts[1].sites.remove(self.site_2) context = self.get_plugin_context(pages[0], 'en', plugin, edit=True) rendered = plugin.render_plugin(context, ph) self.assertTrue(rendered.find('second post first line
') > -1) def test_plugin_tags(self): pages = self.get_pages() posts = self.get_posts() posts[0].tags.add('tag 1', 'tag 2', 'test tag') posts[0].publish = True posts[0].save() posts[1].tags.add('test tag', 'another tag') posts[1].publish = True posts[1].save() ph = pages[0].placeholders.get(slot='content') plugin = add_plugin(ph, 'BlogTagsPlugin', language='en', app_config=self.app_config_1) context = self.get_plugin_context(pages[0], 'en', plugin, edit=True) rendered = plugin.render_plugin(context, ph) for tag in Tag.objects.all(): self.assertTrue(rendered.find( reverse('djangocms_blog:posts-tagged', kwargs={'tag': tag.slug}) ) > -1) if tag.slug == 'test-tag': rf = '\s+%s\s+\(\s+%s articles' % (tag.name, 2) else: rf = '\s+%s\s+\(\s+%s article' % (tag.name, 1) rx = re.compile(rf) self.assertEqual(len(rx.findall(rendered)), 1) def test_blog_archive_plugin(self): pages = self.get_pages() posts = self.get_posts() posts[0].publish = True posts[0].save() posts[1].publish = True posts[1].save() ph = pages[0].placeholders.get(slot='content') plugin = add_plugin(ph, 'BlogArchivePlugin', language='en', app_config=self.app_config_1) plugin_class = plugin.get_plugin_class_instance() context = self.get_plugin_context(pages[0], 'en', plugin, edit=True) context = plugin_class.render(context, plugin, ph) self.assertEqual(context['dates'][0]['date'].date(), now().replace(year=now().year, month=now().month, day=1).date()) self.assertEqual(context['dates'][0]['count'], 2) posts[1].publish = False posts[1].save() context = plugin_class.render(context, plugin, ph) self.assertEqual(context['dates'][0]['date'].date(), now().replace(year=now().year, month=now().month, day=1).date()) self.assertEqual(context['dates'][0]['count'], 1) def test_templates(self): posts = self.get_posts() pages = self.get_pages() ph = pages[0].placeholders.get(slot='content') plugin = add_plugin(ph, 'BlogLatestEntriesPlugin', language='en', app_config=self.app_config_1) context = self.get_plugin_context(pages[0], 'en', plugin) plugin_class = plugin.get_plugin_class_instance() self.assertEqual(plugin_class.get_render_template(context, plugin, ph), os.path.join('djangocms_blog', plugin.template_folder, plugin_class.base_render_template)) self.app_config_1.app_data.config.template_prefix = 'whatever' self.app_config_1.save() tmp = plugin.template_folder plugin.template_folder = 'whereever' plugin.save() self.assertEqual(plugin_class.get_render_template(context, plugin, ph), os.path.join('whatever', 'whereever', plugin_class.base_render_template)) plugin.template_folder = tmp plugin.save() self.app_config_1.app_data.config.template_prefix = '' self.app_config_1.save() class PluginTest2(BaseTest): def test_plugin_authors(self): pages = self.get_pages() posts = self.get_posts() posts[0].publish = True posts[0].save() posts[1].publish = True posts[1].save() ph = pages[0].placeholders.get(slot='content') plugin = add_plugin(ph, 'BlogAuthorPostsPlugin', language='en', app_config=self.app_config_1) context = self.get_plugin_context(pages[0], 'en', plugin, edit=True) 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_blog_category_plugin(self): pages = self.get_pages() posts = self.get_posts() self.category_1.set_current_language('en') posts[0].publish = True posts[0].save() posts[1].publish = True posts[1].save() posts[1].sites.add(self.site_2) new_category = BlogCategory.objects.create( name='category 2', app_config=self.app_config_1 ) posts[1].categories.add(new_category) ph = pages[0].placeholders.get(slot='content') plugin = add_plugin( ph, 'BlogCategoryPlugin', language='en', app_config=self.app_config_1 ) plugin_class = plugin.get_plugin_class_instance() context = self.get_plugin_context(pages[0], 'en', plugin, edit=True) context = plugin_class.render(context, plugin, ph) self.assertTrue(context['categories']) self.assertEqual(list(context['categories']), [self.category_1]) plugin.current_site = False plugin.save() context = plugin_class.render(context, plugin, ph) self.assertEqual(list(context['categories']), [self.category_1, new_category]) plugin.current_site = True plugin.save() with self.settings(SITE_ID=2): context = plugin_class.render(context, plugin, ph) self.assertEqual(list(context['categories']), [self.category_1, new_category]) plugin.current_site = False plugin.save() with self.settings(SITE_ID=2): context = plugin_class.render(context, plugin, ph) self.assertEqual(list(context['categories']), [self.category_1, new_category])