Skip to content

Extra links: drop the redundant check for a user without a group, and restore the setting in the tests - #1808

Merged
np5 merged 1 commit into
mainfrom
tests-extra-links-no-group
Nov 18, 2026
Merged

np5 merged 1 commit into
mainfrom
tests-extra-links-no-group

Conversation

@np5

@np5 np5 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Problem

extra_links() in zentral/conf/context_processors.py had two checks for a link with authorized_groups and a user that is not a superuser:

  1. If the user has no group, skip the link.
  2. If the groups of the user and authorized_groups have no common name, skip the link.

The first check is redundant: for a user without a group, the intersection is empty, and the second check skips the link. No test targeted the first check.

Two test classes set settings._collection["extra_links"] in setUpTestData and did not restore it:

  • BaseViewsTestCase in tests/server_base/test_index.py
  • NginxAuthRequestViewTestCase in tests/server_accounts/test_nginx_auth_request_view.py

The first check was covered only when a later test, in the same process, rendered a console page for a user without a group. Since the suite runs with --parallel auto, the test classes go to different processes from run to run. Coveralls then reported this line as a coverage regression on unrelated pull requests, for example #1804.

Change

  • Remove the first check. The behaviour does not change.
  • Restore the extra_links setting after each of the two test classes with enterClassContext(patch.dict(...)). When only one class restores the setting, it can restore the links that the other class left.
  • Put the extra links assertions in one helper, _assert_extra_links(). The helper:
    • selects the expected links by anchor text,
    • compares them with the zentral_extra_links context,
    • counts the rendered extra links, so that it also finds a link that is not in the test data,
    • checks the anchor text and the URL of each test link in the page.
  • Add tests:
    • test_index_user_without_group_extra_links: a user without a group gets only the links without authorized_groups.
    • test_index_superuser_without_group_all_extra_links: a superuser without a group gets all the links.

No CHANGELOG entry: the behaviour does not change.

Checks

  • flake8 and ruff: no findings.
  • Full suite with tests_with_coverage on a fresh stack: OK.
  • The tests of BaseViewsTestCase cover all the lines of extra_links(), whatever the order of the test classes.

🤖 Generated with Claude Code

@np5 np5 changed the title Test the extra links of a user without a group, and restore the setting Extra links: drop the redundant check for a user without a group, and test it Nov 18, 2026
@coveralls

coveralls commented Nov 18, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 44411325200

Coverage remained the same at 91.644%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 60939
Covered Lines: 55847
Line Coverage: 91.64%
Coverage Strength: 0.92 hits per line

💛 - Coveralls

@np5 np5 changed the title Extra links: drop the redundant check for a user without a group, and test it Extra links: drop the redundant check for a user without a group, and restore the setting in the tests Nov 18, 2026

@soysauceconspiracy soysauceconspiracy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

… restore the setting in the tests

extra_links() skipped a link with authorized_groups for a user without a
group, then for a user with no group in authorized_groups. The first check is
redundant: for a user without a group, the intersection is empty, and the
second check skips the link. It is removed. The behaviour does not change.

BaseViewsTestCase and NginxAuthRequestViewTestCase set the extra_links setting
and did not restore it. The removed check was covered only when a later test,
in the same process, rendered a console page for a user without a group. With
--parallel auto, the test classes go to different processes from run to run,
and Coveralls reported a coverage regression on unrelated pull requests. Both
classes now restore the setting with enterClassContext(patch.dict(...)).

The extra links assertions are in one helper, _assert_extra_links(). It
compares the expected links with the zentral_extra_links context, counts the
rendered extra links, and checks the anchor text and the URL of each test link
in the page. New tests: a user without a group gets only the links without
authorized_groups, and a superuser without a group gets all the links.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@np5
np5 force-pushed the tests-extra-links-no-group branch from 1284c1e to 1a6a5ea Compare November 18, 2026 22:24

@soysauceconspiracy soysauceconspiracy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@np5
np5 merged commit 1a6a5ea into main Nov 18, 2026
8 checks passed
@np5
np5 deleted the tests-extra-links-no-group branch November 18, 2026 22:31
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.

3 participants