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

Helper function to get flask.request.patron #2178

Merged
merged 3 commits into from
Nov 20, 2024

Conversation

jonathangreen
Copy link
Member

Description

Similar to #2177 but for flask.request.patron.

Add a helper function get_request_patron() to get flask.request.patron in a type safe way. Update the existing code to use the new helper.

Motivation and Context

Consistency in how we are accessing attributes set on flask.request.

How Has This Been Tested?

  • Running tests

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@jonathangreen jonathangreen requested a review from a team November 20, 2024 17:18
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.01%. Comparing base (30f2547) to head (45d32c3).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/palace/manager/api/controller/loan.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2178      +/-   ##
==========================================
+ Coverage   91.00%   91.01%   +0.01%     
==========================================
  Files         359      360       +1     
  Lines       41136    41183      +47     
  Branches     8842     8845       +3     
==========================================
+ Hits        37436    37483      +47     
  Misses       2424     2424              
  Partials     1276     1276              

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


🚨 Try these New Features:

):
return PatronAuthTokenControllerFixture(db, services_fixture)
def patron_auth_token_fixture(db: DatabaseTransactionFixture):
return PatronAuthTokenControllerFixture(db)


class TestPatronAuthTokenController:
Copy link
Member Author

Choose a reason for hiding this comment

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

All the test changes here are to update these tests to use FlaskAppFixture, so we can set the patron by passing it to flask_app_fixture.test_request_context. The tests should be functionally the same.

def playtime_entries_controller_fixture(
db: DatabaseTransactionFixture,
) -> PlaytimeEntriesControllerFixture:
return PlaytimeEntriesControllerFixture(db)


class TestPlaytimeEntriesController:
Copy link
Member Author

Choose a reason for hiding this comment

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

All the changes to these tests are so we can use flask_app_fixture in the tests, which allows us to pass patron and library to test_request_context. That way we aren't directly manipulating flask.request in the tests.

@@ -18,37 +19,43 @@ def controller(db: DatabaseTransactionFixture) -> DeviceTokensController:
return DeviceTokensController(mock_manager)


@patch("palace.manager.api.controller.device_tokens.flask")
Copy link
Member Author

Choose a reason for hiding this comment

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

The device tokens tests took an unusual approach, and instead of using the test_request_context decorator, it patched the flask object. This stopped working with these updates, since we are not loading the patron directly from flask.request anymore.

These changes just update these tests to be more in line with our other tests using the flask_app_fixture to setup the request context. There should be no functional changes to the tests.

@jonathangreen jonathangreen requested review from a team and removed request for a team November 20, 2024 17:55
Copy link
Contributor

@tdilauro tdilauro left a comment

Choose a reason for hiding this comment

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

Looks good! 🛠️

Base automatically changed from chore/type-hint-request-library to main November 20, 2024 20:15
@jonathangreen jonathangreen force-pushed the chore/type-hint-request-patron branch from 9e872ed to 45d32c3 Compare November 20, 2024 20:17
@jonathangreen jonathangreen merged commit 9a6e727 into main Nov 20, 2024
21 checks passed
@jonathangreen jonathangreen deleted the chore/type-hint-request-patron branch November 20, 2024 20:29
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