Skip to content

Conversation

@AkhileshNegi
Copy link
Collaborator

@AkhileshNegi AkhileshNegi commented Jul 24, 2025

Summary

Target issue is #295
Explain the motivation for making this change. What existing problem does the pull request solve?

Checklist

Before submitting a pull request, please ensure that you mark these task.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

Notes

Please add here if any other information is required for the reviewer.

Summary by CodeRabbit

Summary by CodeRabbit

  • Tests
    • Updated test fixtures and parameter names for API key headers to use singular naming for clarity and consistency.
    • Added new fixtures to provide raw API key objects for both superuser and normal user roles.
    • Adjusted test and utility code to use the updated fixtures and parameter names throughout.
    • Modified utility function to return full API key objects instead of just key strings.
    • No changes to test logic or assertions.

@coderabbitai
Copy link

coderabbitai bot commented Jul 24, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This change standardizes the naming of API key-related fixtures, parameters, and variables across multiple test files, renaming normal_user_api_key_headers to user_api_key_header and superuser_api_key_headers to superuser_api_key_header. It also introduces new fixtures for raw API key objects and updates utility functions to return the full API key object instead of just the key string.

Changes

File(s) Change Summary
backend/app/tests/api/routes/collections/test_collection_info.py Renamed test parameters/variables from normal_user_api_key_headers to user_api_key_header in three tests.
backend/app/tests/api/routes/collections/test_create_collections.py Updated test method parameter and variable from normal_user_api_key_headers to user_api_key_header.
backend/app/tests/api/routes/documents/test_route_document_upload.py Changed fixture and internal usage from normal_user_api_key_headers to user_api_key_header.
backend/app/tests/api/routes/test_assistants.py Renamed test parameters from normal_user_api_key_headers to user_api_key_header in all relevant tests.
backend/app/tests/api/routes/test_responses.py Updated test parameters and usage from normal_user_api_key_headers to user_api_key_header.
backend/app/tests/conftest.py Renamed and refactored API key header fixtures; added fixtures for raw API key objects.
backend/app/tests/utils/document.py Renamed dataclass attribute and fixture parameter from normal_user_api_key_headers to user_api_key_header.
backend/app/tests/utils/utils.py Changed get_api_key_by_email to return the full API key object instead of just the key string.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Function
    participant Fixture as Pytest Fixture
    participant DB as Database
    participant Client as HTTP Client

    Test->>Fixture: Request user_api_key_header
    Fixture->>DB: Retrieve API key for user
    Fixture-->>Test: Return {"X-API-KEY": api_key.key}
    Test->>Client: Make HTTP request with user_api_key_header
    Client->>DB: Validate API key
    DB-->>Client: Respond
    Client-->>Test: Return API response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A rabbit hopped through fields of code,
Renaming headers as it strode.
From plural to single, it made things neat,
Fixtures and tests now all complete.
With every hop, the code grew clear—
Reviewers smile from ear to ear! 🐇✨


📜 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 7a6059b and a2a0c60.

📒 Files selected for processing (1)
  • backend/app/tests/utils/utils.py (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch enhancement/api-key-fixture

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
backend/app/tests/utils/utils.py (1)

49-53: Fix the return type annotation to match the actual return value.

The function now returns the full api_key object instead of just the key string, but the return type annotation still indicates str. This creates a mismatch between the annotation and actual behavior.

Update the return type annotation to reflect the actual return value:

-def get_api_key_by_email(db: Session, email: EmailStr) -> str:
+def get_api_key_by_email(db: Session, email: EmailStr) -> APIKeyPublic:

Also add the missing import at the top of the file if not already present:

 from app.models import APIKeyPublic, Project, Assistant
🧹 Nitpick comments (2)
backend/app/tests/api/routes/test_assistants.py (1)

117-147: Consider using the fixture for consistency.

While the manual API key header construction works correctly, consider using the user_api_key_header fixture for consistency with other tests in this file. This would make the test setup more uniform.

You could refactor this test to use the fixture:

 def test_update_assistant_success(
     client: TestClient,
     db: Session,
+    user_api_key_header: dict[str, str],
 ):

Then replace the manual header construction with the fixture parameter. However, this would also require ensuring the fixture uses the same project/user context as the assistant being tested.

backend/app/tests/api/routes/test_responses.py (1)

68-68: Add type annotation for consistency.

The parameter renaming is correct, but consider adding the type annotation for consistency with other test functions.

-    user_api_key_header,
+    user_api_key_header: dict[str, str],

Also applies to: 108-108

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1d651b and ecf7607.

📒 Files selected for processing (8)
  • backend/app/tests/api/routes/collections/test_collection_info.py (3 hunks)
  • backend/app/tests/api/routes/collections/test_create_collections.py (2 hunks)
  • backend/app/tests/api/routes/documents/test_route_document_upload.py (2 hunks)
  • backend/app/tests/api/routes/test_assistants.py (11 hunks)
  • backend/app/tests/api/routes/test_responses.py (4 hunks)
  • backend/app/tests/conftest.py (1 hunks)
  • backend/app/tests/utils/document.py (2 hunks)
  • backend/app/tests/utils/utils.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
backend/app/tests/utils/utils.py (2)
backend/app/tests/crud/test_api_key.py (4)
  • test_get_api_key_by_user_id (103-117)
  • test_get_api_key_by_value (52-66)
  • test_get_api_key (25-32)
  • test_get_api_key_by_project_user (69-81)
backend/app/tests/utils/user.py (1)
  • authentication_token_from_email (30-49)
backend/app/tests/api/routes/test_responses.py (1)
backend/app/tests/conftest.py (3)
  • db (20-37)
  • user_api_key_header (73-75)
  • client (48-51)
backend/app/tests/api/routes/documents/test_route_document_upload.py (1)
backend/app/tests/conftest.py (2)
  • user_api_key_header (73-75)
  • client (48-51)
backend/app/tests/utils/document.py (1)
backend/app/tests/conftest.py (2)
  • user_api_key_header (73-75)
  • client (48-51)
🔇 Additional comments (17)
backend/app/tests/api/routes/collections/test_create_collections.py (1)

49-63: LGTM! Consistent parameter renaming.

The parameter and variable renaming from normal_user_api_key_headers to user_api_key_header is consistent and aligns with the broader standardization effort across the test suite.

backend/app/tests/api/routes/test_assistants.py (7)

29-43: LGTM! Consistent parameter renaming.

The parameter renaming from normal_user_api_key_headers to user_api_key_header is consistent and correctly applied in the test function signature and usage.


51-66: LGTM! Consistent parameter renaming.

The parameter and variable updates are correctly applied and maintain the test logic.


90-110: LGTM! Consistent parameter renaming.

The parameter updates are correctly applied in both the function signature and the HTTP request headers.


176-189: LGTM! Consistent parameter renaming.

The parameter and usage updates are correctly applied.


218-228: LGTM! Consistent parameter renaming.

The parameter and usage updates are correctly applied.


259-283: LGTM! Consistent parameter renaming.

The parameter updates are correctly applied across all the pagination test scenarios.


305-315: LGTM! Consistent parameter renaming.

The parameter and usage updates are correctly applied.

backend/app/tests/utils/document.py (2)

113-128: LGTM! Consistent attribute and usage renaming.

The dataclass attribute renaming from normal_user_api_key_headers to user_api_key_header is correctly applied, including the type annotation and all method usages.


160-162: LGTM! Consistent fixture parameter renaming.

The fixture parameter renaming is consistent with the dataclass changes and properly passes the parameter to the WebCrawler constructor.

backend/app/tests/api/routes/documents/test_route_document_upload.py (2)

22-32: LGTM! Consistent attribute usage update.

The method correctly uses the renamed user_api_key_header attribute, maintaining consistency with the parent WebCrawler class changes.


47-49: LGTM! Consistent fixture parameter renaming.

The fixture parameter renaming is consistent with the broader standardization effort and correctly passes the parameter to the WebUploader constructor.

backend/app/tests/api/routes/test_responses.py (1)

19-19: LGTM! Parameter renaming is consistent with fixture changes.

The renaming from normal_user_api_key_headers to user_api_key_header aligns with the fixture standardization in conftest.py and maintains consistency throughout the function.

Also applies to: 51-51

backend/app/tests/api/routes/collections/test_collection_info.py (1)

40-42: LGTM! Consistent parameter renaming across all test functions.

The renaming from normal_user_api_key_headers to user_api_key_header is applied consistently across all three test functions and aligns with the fixture standardization.

Also applies to: 61-63, 83-84

backend/app/tests/conftest.py (3)

67-69: LGTM! Fixture standardization improves test clarity.

The renaming to singular form and returning a header dictionary instead of the raw API key object makes the fixture usage more explicit and consistent across tests.


73-75: LGTM! Consistent with superuser fixture changes.

The renaming and return value change follow the same standardization pattern as the superuser fixture.


69-69: get_api_key_by_email returns an object with .key, fixtures are correct
The get_api_key_by_user_id function returns an APIKeyPublic model (with a decrypted key field), so get_api_key_by_email indeed returns an object that has a .key attribute. No changes required.

@codecov
Copy link

codecov bot commented Jul 24, 2025

Codecov Report

Attention: Patch coverage is 80.76923% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
backend/app/tests/conftest.py 61.53% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@AkhileshNegi AkhileshNegi self-assigned this Jul 24, 2025
@AkhileshNegi AkhileshNegi added the enhancement New feature or request label Jul 24, 2025
@AkhileshNegi AkhileshNegi merged commit d0c91d3 into main Jul 24, 2025
1 of 2 checks passed
@AkhileshNegi AkhileshNegi deleted the enhancement/api-key-fixture branch July 24, 2025 14:27
@AkhileshNegi AkhileshNegi restored the enhancement/api-key-fixture branch July 25, 2025 05:25
@AkhileshNegi AkhileshNegi linked an issue Jul 28, 2025 that may be closed by this pull request
@coderabbitai coderabbitai bot mentioned this pull request Aug 8, 2025
2 tasks
@AkhileshNegi AkhileshNegi deleted the enhancement/api-key-fixture branch October 13, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fixture: Adding API Key Model

2 participants