Skip to content

Commit

Permalink
Initial commit to make tests fail
Browse files Browse the repository at this point in the history
  • Loading branch information
protoroto committed Dec 22, 2023
1 parent d95802c commit 25c6d74
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions changes/781.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix FeaturedPostsPlugin get_posts method rendering all posts instead of selected ones
8 changes: 6 additions & 2 deletions djangocms_blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,9 @@ def optimize(self, qs):
"translations", "categories", "categories__translations", "categories__app_config"
)

def post_queryset(self, request=None, published_only=True):
def post_queryset(self, request=None, published_only=True, selected_posts=None):
language = get_language()
posts = Post.objects
posts = Post.objects if not selected_posts else selected_posts
if self.app_config:
posts = posts.namespace(self.app_config.namespace)
if self.current_site:
Expand Down Expand Up @@ -611,6 +611,10 @@ def copy_relations(self, oldinstance):
self.posts.set(oldinstance.posts.all())

def get_posts(self, request, published_only=True):
# if self.posts.exists():
# posts = self.post_queryset(request, published_only, selected_posts=self.posts.all())
# else:
# posts = self.post_queryset(request, published_only)
posts = self.post_queryset(request, published_only)
return posts

Expand Down
3 changes: 2 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1364,10 +1364,11 @@ def test_plugin_featured_posts(self):
plugin = add_plugin(post1.content, "BlogFeaturedPostsPlugin", language="en", app_config=self.app_config_1)
plugin.posts.add(post1, post2)
self.assertEqual(len(plugin.get_posts(request)), 1)

post2.publish = True
post2.save()
self.assertEqual(len(plugin.get_posts(request)), 2)
plugin.posts.remove(post2)
self.assertEqual(len(plugin.get_posts(request)), 1)

def test_copy_plugin_featured_post(self):
post1 = self._get_post(self._post_data[0]["en"])
Expand Down
11 changes: 8 additions & 3 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ def test_plugin_featured_cached(self):
plugin_nocache = add_plugin(ph, "BlogFeaturedPostsPlugin", language="en", app_config=self.app_config_1)
plugin_nocache.posts.add(posts[0])
# FIXME: Investigate the correct number of queries expected here
with self.assertNumQueries(FuzzyInt(14, 15)):
with self.assertNumQueries(FuzzyInt(16, 17)):
self.render_plugin(pages[0], "en", plugin_nocache)

with self.assertNumQueries(FuzzyInt(14, 15)):
with self.assertNumQueries(FuzzyInt(16, 17)):
self.render_plugin(pages[0], "en", plugin)

with self.assertNumQueries(FuzzyInt(14, 15)):
with self.assertNumQueries(FuzzyInt(16, 17)):
rendered = self.render_plugin(pages[0], "en", plugin)

self.assertTrue(rendered.find("<p>first line</p>") > -1)
Expand Down Expand Up @@ -181,6 +181,11 @@ def test_plugin_featured(self):
self.assertTrue(rendered.find('<article id="post-second-post"') > -1)
self.assertTrue(rendered.find(posts[0].get_absolute_url()) > -1)
self.assertTrue(rendered.find(posts[1].get_absolute_url()) > -1)
plugin.posts.remove(posts[1])

rendered = self.render_plugin(pages[0], "en", plugin, edit=True)
self.assertTrue(rendered.find(posts[0].get_absolute_url()) > -1)
self.assertFalse(rendered.find(posts[1].get_absolute_url()) > -1)

def test_plugin_tags(self):
pages = self.get_pages()
Expand Down

0 comments on commit 25c6d74

Please sign in to comment.