Skip to content

Conversation

@fsbraun
Copy link
Member

@fsbraun fsbraun commented Nov 3, 2025

Summary by Sourcery

Add a suite of tests for djangocms_stories template tags and clean up unused test factory code

Tests:

  • Add comprehensive tests for namespace_url, media_plugins, media_images, and absolute_url template tags covering basic usage, edge cases, edit mode, integration, and loop scenarios

Chores:

  • Remove unused Site import and default_site assignment from tests/factories.py

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 3, 2025

Reviewer's Guide

This PR removes an unused Site import from test factories and introduces a comprehensive suite of tests for the djangocms_stories template tags, validating URL generation, media placeholder handling, edit-mode behavior, integrations, and loop usage.

File-Level Changes

Change Details Files
Removed unused Site dependency in test factories
  • Removed import of Site model
  • Removed default_site fixture initialization
tests/factories.py
Added comprehensive tests for djangocms_stories template tags
  • Tests for namespace_url tag scenarios
  • Tests for media_plugins tag behavior
  • Tests for media_images tag behavior
  • Tests for absolute_url tag in various modes
  • Integration tests covering multiple tags and loop rendering
tests/test_templatetags.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • The test_templatetags.py file is very large and could be split into separate modules per tag (namespace_url, media_plugins, absolute_url) to improve organization and maintainability.
  • A lot of setup code (creating the request, toolbar, and context) is duplicated across tests—consider extracting common fixtures or helper functions to DRY up the tests.
  • Many assertions use loose checks like startswith or in; strengthen these by comparing to expected URLs via Django’s reverse() or using regex to catch regressions more reliably.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The test_templatetags.py file is very large and could be split into separate modules per tag (namespace_url, media_plugins, absolute_url) to improve organization and maintainability.
- A lot of setup code (creating the request, toolbar, and context) is duplicated across tests—consider extracting common fixtures or helper functions to DRY up the tests.
- Many assertions use loose checks like startswith or in; strengthen these by comparing to expected URLs via Django’s reverse() or using regex to catch regressions more reliably.

## Individual Comments

### Comment 1
<location> `tests/test_templatetags.py:103` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Don't import test modules. ([`dont-import-test-modules`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/dont-import-test-modules))

<details><summary>Explanation</summary>Don't import test modules.

Tests should be self-contained and don't depend on each other.

If a helper function is used by multiple tests,
define it in a helper module,
instead of importing one test from the other.
</details>
</issue_to_address>

### Comment 2
<location> `tests/test_templatetags.py:119` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Don't import test modules. ([`dont-import-test-modules`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/dont-import-test-modules))

<details><summary>Explanation</summary>Don't import test modules.

Tests should be self-contained and don't depend on each other.

If a helper function is used by multiple tests,
define it in a helper module,
instead of importing one test from the other.
</details>
</issue_to_address>

### Comment 3
<location> `tests/test_templatetags.py:291-292` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Avoid loops in tests. ([`no-loop-in-tests`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/no-loop-in-tests))

<details><summary>Explanation</summary>Avoid complex code, like loops, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:
* loops
* conditionals

Some ways to fix this:

* Use parametrized tests to get rid of the loop.
* Move the complex logic into helpers.
* Move the complex part into pytest fixtures.

> Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / [Don't Put Logic in Tests](https://abseil.io/resources/swe-book/html/ch12.html#donapostrophet_put_logic_in_tests)
</details>
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Nov 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.57%. Comparing base (65c6401) to head (4ef9ceb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #53      +/-   ##
==========================================
+ Coverage   84.20%   86.57%   +2.36%     
==========================================
  Files          23       23              
  Lines        2070     2070              
  Branches      232      232              
==========================================
+ Hits         1743     1792      +49     
+ Misses        220      186      -34     
+ Partials      107       92      -15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fsbraun fsbraun merged commit 166a805 into main Nov 3, 2025
22 checks passed
@fsbraun fsbraun deleted the chore/test-templatetags branch November 3, 2025 11:40
@fsbraun fsbraun restored the chore/test-templatetags branch November 3, 2025 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants