Skip to content

LCORE-740: type hints in authorization/test_middleware.py#729

Merged
tisnik merged 1 commit intolightspeed-core:mainfrom
tisnik:lcore-740-type-hints-in-authorization-test-middleware
Oct 30, 2025
Merged

LCORE-740: type hints in authorization/test_middleware.py#729
tisnik merged 1 commit intolightspeed-core:mainfrom
tisnik:lcore-740-type-hints-in-authorization-test-middleware

Conversation

@tisnik
Copy link
Contributor

@tisnik tisnik commented Oct 30, 2025

Description

LCORE-740: type hints in authorization/test_middleware.py

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement

Related Tickets & Documents

  • Related Issue #LCORE-740

Summary by CodeRabbit

  • Tests
    • Enhanced type safety and explicit type annotations across the unit test suite to improve code reliability and maintainability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 30, 2025

Walkthrough

The test file received comprehensive type annotation enhancements across fixtures and test methods, explicitly declaring parameter and return types for better code clarity. The underlying test logic and assertions remain unchanged, with only typing infrastructure and argument structure updated.

Changes

Cohort / File(s) Change Summary
Type Annotation Enhancement
tests/unit/authorization/test_middleware.py
Added comprehensive type annotations to fixtures and test methods using imports (AuthTuple, MockerFixture, MockType, AccessRule, JwtRoleRule, AccessResolver). Updated fixture return types and test parameter types. Replaced empty tuple args = () with empty list args = [] in test invocations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Type consistency verification: Ensure all added type hints (AuthTuple, MockType, JwtRoleRule, etc.) are correctly imported and align with their actual usage in fixtures and tests.
  • Fixture return types: Verify that fixture return type annotations match the values they actually return.
  • Empty tuple to list conversion: Confirm the args = [] change doesn't alter test behavior or expectations in request argument construction.
  • AccessResolver import: Verify the new import is properly used and necessary.

Poem

🐰 With types now dancing in the test file's lines,
Each fixture and method gets alignment signs,
From empty tuples to lists, the logic stays true,
Type safety whispers: "I'm coming for you!"

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "LCORE-740: type hints in authorization/test_middleware.py" is fully related to the main change in the changeset. The title clearly and specifically describes that type hints are being added to the test_middleware.py file, which directly matches the changeset's primary objective of introducing explicit type annotations across the unit test file. The title is concise, readable, and includes a ticket reference for tracking, making it clear to teammates scanning history what the change accomplishes.
Docstring Coverage ✅ Passed Docstring coverage is 88.24% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8aca35f and bd94b04.

📒 Files selected for processing (1)
  • tests/unit/authorization/test_middleware.py (13 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.py: All modules start with descriptive module-level docstrings explaining purpose
Use logger = logging.getLogger(name) for module logging after import logging
Define type aliases at module level for clarity
All functions require docstrings with brief descriptions
Provide complete type annotations for all function parameters and return types
Use typing_extensions.Self in model validators where appropriate
Use modern union syntax (str | int) and Optional[T] or T | None consistently
Function names use snake_case with descriptive, action-oriented prefixes (get_, validate_, check_)
Avoid in-place parameter modification; return new data structures instead of mutating arguments
Use appropriate logging levels: debug, info, warning, error with clear messages
All classes require descriptive docstrings explaining purpose
Class names use PascalCase with conventional suffixes (Configuration, Error/Exception, Resolver, Interface)
Abstract base classes should use abc.ABC and @AbstractMethod for interfaces
Provide complete type annotations for all class attributes
Follow Google Python docstring style for modules, classes, and functions, including Args, Returns, Raises, Attributes sections as needed

Files:

  • tests/unit/authorization/test_middleware.py
tests/{unit,integration}/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

tests/{unit,integration}/**/*.py: Use pytest for all unit and integration tests
Do not use unittest in tests; pytest is the standard

Files:

  • tests/unit/authorization/test_middleware.py
tests/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

tests/**/*.py: Use pytest-mock to create AsyncMock objects for async interactions in tests
Use the shared auth mock constant: MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token") in tests

Files:

  • tests/unit/authorization/test_middleware.py
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
PR: lightspeed-core/lightspeed-stack#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to src/{models/**/*.py,configuration.py} : Use precise type hints in configuration (e.g., Optional[FilePath], PositiveInt, SecretStr)
Learnt from: CR
PR: lightspeed-core/lightspeed-stack#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to **/*.py : Provide complete type annotations for all function parameters and return types
Learnt from: CR
PR: lightspeed-core/lightspeed-stack#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to **/*.py : Provide complete type annotations for all class attributes
📚 Learning: 2025-09-18T16:46:33.353Z
Learnt from: CR
PR: lightspeed-core/lightspeed-stack#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to tests/**/*.py : Use the shared auth mock constant: MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token") in tests

Applied to files:

  • tests/unit/authorization/test_middleware.py
📚 Learning: 2025-09-02T11:09:40.404Z
Learnt from: radofuchs
PR: lightspeed-core/lightspeed-stack#485
File: tests/e2e/features/environment.py:87-95
Timestamp: 2025-09-02T11:09:40.404Z
Learning: In the lightspeed-stack e2e tests, noop authentication tests use the default lightspeed-stack.yaml configuration, while noop-with-token tests use the Authorized tag to trigger a config swap to the specialized noop-with-token configuration file.

Applied to files:

  • tests/unit/authorization/test_middleware.py
🧬 Code graph analysis (1)
tests/unit/authorization/test_middleware.py (3)
src/models/config.py (5)
  • config (140-146)
  • Action (329-375)
  • JwtRoleRule (268-326)
  • AccessRule (378-382)
  • JsonPathOperator (259-265)
src/authorization/middleware.py (3)
  • get_authorization_resolvers (25-65)
  • _perform_authorization_check (68-108)
  • authorize (111-122)
src/authorization/resolvers.py (5)
  • AccessResolver (119-128)
  • NoopRolesResolver (33-39)
  • NoopAccessResolver (131-143)
  • JwtRolesResolver (53-116)
  • GenericAccessResolver (146-202)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build-pr
  • GitHub Check: e2e_tests (azure)
  • GitHub Check: e2e_tests (ci)
🔇 Additional comments (7)
tests/unit/authorization/test_middleware.py (7)

3-26: LGTM! Type imports are well-organized.

The additional imports for type hints are correctly placed and necessary for the annotations throughout the file.


29-61: LGTM! Fixture type hints are accurate.

All fixture return types correctly match the actual values being returned.


93-167: LGTM! Test method type hints are correct.

All parameter and return type annotations correctly match the actual values and usage.


174-182: LGTM! Fixture type hints are accurate.

The mock_resolvers fixture correctly returns a tuple of two mocks.


183-214: LGTM! Test method type hints are correct.

All parameter and return type annotations for test_missing_auth_kwarg and test_access_denied are accurate.


247-266: LGTM! Test method type hints are correct.

All parameter and return type annotations for test_everyone_role_added are accurate.


268-306: LGTM! Test decorator type hints are well-implemented.

All type annotations are correct, and the use of **_: Any for the mock endpoint is a good pattern for accepting arbitrary kwargs.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@tisnik tisnik merged commit 5a27dcc into lightspeed-core:main Oct 30, 2025
18 of 20 checks passed
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.

1 participant