Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhanced async client usage #187

Merged
merged 2 commits into from
Sep 4, 2024
Merged

Conversation

TeKrop
Copy link
Owner

@TeKrop TeKrop commented Sep 4, 2024

Summary by Sourcery

Enhance the codebase by adopting httpx.AsyncClient for asynchronous HTTP requests across parsers, handlers, and tests. Refactor tests to utilize a shared TestClient fixture for FastAPI route testing, and improve dependency management in the players.py router.

Enhancements:

  • Refactor tests to use httpx.AsyncClient instead of overfast_client for HTTP requests.
  • Update the NamecardParser, PlayerParser, PlayerCareerParser, PlayerStatsSummaryParser, and HeroParser to accept an httpx.AsyncClient instance for making HTTP requests.
  • Modify the check_new_hero.py script to use asynchronous HTTP requests with httpx.AsyncClient.
  • Refactor the APIParser and APIRequestHandler classes to use a shared httpx.AsyncClient instance for HTTP requests.
  • Introduce dependency injection for common player parameters in the players.py router using Annotated and Depends.

Tests:

  • Add a new conftest.py file to provide a TestClient fixture for testing FastAPI routes.
  • Update test cases across multiple test files to use the client fixture for making HTTP requests.

@TeKrop TeKrop added the enhancement New feature or request label Sep 4, 2024
@TeKrop TeKrop self-assigned this Sep 4, 2024
Copy link
Contributor

sourcery-ai bot commented Sep 4, 2024

Reviewer's Guide by Sourcery

This pull request enhances the usage of async clients in the project by introducing a shared httpx.AsyncClient instance and updating the codebase to use it consistently. The changes improve the efficiency of HTTP requests and ensure proper resource management.

File-Level Changes

Change Details Files
Introduced a shared httpx.AsyncClient instance
  • Added an overfast_client attribute to the FastAPI app
  • Created the client in the app's lifespan context manager
  • Updated request handlers to use the shared client
  • Modified parsers to accept the client as a parameter
app/main.py
app/handlers/api_request_handler.py
app/parsers/generics/api_parser.py
app/common/helpers.py
Updated test suite to use the shared client
  • Created a client fixture in tests/views/conftest.py
  • Modified test cases to use the client fixture
  • Updated mocking of HTTP requests in tests
tests/views/conftest.py
tests/views/test_player_career_route.py
tests/views/test_search_players_route.py
tests/parsers/test_player_parser.py
Refactored overfast_request function
  • Modified overfast_request to accept a client parameter
  • Removed global overfast_client instance
  • Updated all calls to overfast_request to pass the client
app/common/helpers.py
app/parsers/search_data_parser.py
app/handlers/search_players_request_handler.py
Updated command scripts to use AsyncClient
  • Modified check_and_update_cache.py to create and use AsyncClient
  • Updated check_new_hero.py to use AsyncClient
  • Ensured proper closing of AsyncClient in command scripts
app/commands/check_and_update_cache.py
app/commands/check_new_hero.py

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

sonarcloud bot commented Sep 4, 2024

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 @TeKrop - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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 to tell me if it was helpful.

app/routers/players.py Show resolved Hide resolved
app/common/helpers.py Show resolved Hide resolved
tests/parsers/test_gamemodes_parser.py Show resolved Hide resolved
tests/views/test_player_stats_route.py Show resolved Hide resolved
@TeKrop TeKrop merged commit 94a0299 into main Sep 4, 2024
3 checks passed
@TeKrop TeKrop deleted the feat/optimize-async-client-usage branch September 4, 2024 20:17
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.

1 participant