From f86c260305b27408616fb0e1d4a07e8f6ba6b89f Mon Sep 17 00:00:00 2001 From: geo-martino Date: Thu, 11 Jul 2024 01:24:51 -0400 Subject: [PATCH] update for aiorequestful v0.6.0 changes --- musify/libraries/remote/spotify/api/api.py | 10 +++++----- musify/libraries/remote/spotify/api/base.py | 2 +- tests/conftest.py | 6 +++--- tests/libraries/remote/core/api.py | 2 +- tests/libraries/remote/core/processors/check.py | 12 ++++++------ tests/libraries/remote/spotify/api/test_api.py | 10 +++++----- tests/libraries/remote/spotify/test_processors.py | 4 ++-- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/musify/libraries/remote/spotify/api/api.py b/musify/libraries/remote/spotify/api/api.py index acf1d0b0..7ea913c8 100644 --- a/musify/libraries/remote/spotify/api/api.py +++ b/musify/libraries/remote/spotify/api/api.py @@ -86,16 +86,16 @@ def __init__( authoriser.refresh_request.headers["content-type"] = "application/x-www-form-urlencoded" if token_file_path: - authoriser.response_handler.file_path = Path(token_file_path) - authoriser.response_handler.additional_headers = { + authoriser.response.file_path = Path(token_file_path) + authoriser.response.additional_headers = { "Accept": "application/json", "Content-Type": "application/json" } - authoriser.response_tester.request = AuthRequest( + authoriser.tester.request = AuthRequest( method=HTTPMethod.GET, url=wrangler.url_api.joinpath("me") ) - authoriser.response_tester.response_test = self._response_test - authoriser.response_tester.max_expiry = 600 + authoriser.tester.response_test = self._response_test + authoriser.tester.max_expiry = 600 super().__init__(authoriser=authoriser, wrangler=wrangler, cache=cache) diff --git a/musify/libraries/remote/spotify/api/base.py b/musify/libraries/remote/spotify/api/base.py index 490acde2..0fc4b8f1 100644 --- a/musify/libraries/remote/spotify/api/base.py +++ b/musify/libraries/remote/spotify/api/base.py @@ -142,6 +142,6 @@ async def _cache_responses(self, method: str, responses: Iterable[dict[str, Any] self.handler.log( method="CACHE", url=url, - message=f"Caching {len(results_mapped)} to {repository.settings.name!r} repository", + message=f"Caching {len(results_mapped)} responses to {repository.settings.name!r} repository", ) await repository.save_responses({k: await repository.serialize(v) for k, v in results_mapped.items()}) diff --git a/tests/conftest.py b/tests/conftest.py index 3e5f4ca0..d2c77e09 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -377,9 +377,9 @@ async def spotify_api(spotify_mock: SpotifyMock) -> SpotifyAPI: token = {"access_token": "fake access token", "token_type": "Bearer", "scope": "test-read"} # disable any token tests by settings test_* kwargs as appropriate api = SpotifyAPI() - api.handler.authoriser.response_handler.response = token - api.handler.authoriser.response_tester.response_test = None - api.handler.authoriser.response_tester.max_expiry = 0 + api.handler.authoriser.response.replace(token) + api.handler.authoriser.tester.response_test = None + api.handler.authoriser.tester.max_expiry = 0 # force no backoff/wait settings api.handler.wait_timer = None diff --git a/tests/libraries/remote/core/api.py b/tests/libraries/remote/core/api.py index 5ecfd967..19b09b96 100644 --- a/tests/libraries/remote/core/api.py +++ b/tests/libraries/remote/core/api.py @@ -44,7 +44,7 @@ def object_factory(self) -> RemoteObjectFactory: async def api_cache(self, api: RemoteAPI, cache: ResponseCache, api_mock: RemoteMock) -> RemoteAPI: """Yield an authorised :py:class:`RemoteAPI` object with a :py:class:`ResponseCache` configured.""" api_cache = api.__class__(cache=cache) - api_cache.handler.authoriser.response_handler = api.handler.authoriser.response_handler + api_cache.handler.authoriser.response = api.handler.authoriser.response async with api_cache as a: # entering context sometimes makes HTTP calls, reset to avoid issues asserting request counts diff --git a/tests/libraries/remote/core/processors/check.py b/tests/libraries/remote/core/processors/check.py index 6d664330..a1df6999 100644 --- a/tests/libraries/remote/core/processors/check.py +++ b/tests/libraries/remote/core/processors/check.py @@ -79,8 +79,8 @@ def token_file_path(self, path: Path) -> Path: @staticmethod async def test_make_temp_playlist(checker: RemoteItemChecker, api_mock: RemoteMock, token_file_path: Path): # force auth test to fail and reload from token - checker.api.handler.authoriser.response_handler.response = None - checker.api.handler.authoriser.response_handler.file_path = token_file_path + checker.api.handler.authoriser.response.replace({}) + checker.api.handler.authoriser.response.file_path = token_file_path collection = BasicCollection(name=random_str(30, 50), items=random_tracks()) for item in collection: @@ -96,7 +96,7 @@ async def test_make_temp_playlist(checker: RemoteItemChecker, api_mock: RemoteMo item.uri = random_uri() await checker._create_playlist(collection=collection) - assert checker.api.handler.authoriser.response_handler.response is not None + assert checker.api.handler.authoriser.response assert collection.name in checker._playlist_originals assert checker._playlist_check_collections[collection.name] == collection assert api_mock.total_requests >= 2 @@ -110,8 +110,8 @@ async def test_delete_temp_playlists( token_file_path: Path ): # force auth test to fail and reload from token - checker.api.handler.authoriser.response_handler.response = None - checker.api.handler.authoriser.response_handler.file_path = token_file_path + checker.api.handler.authoriser.response.replace({}) + checker.api.handler.authoriser.response.file_path = token_file_path for pl in sample(playlists, k=len(playlists) // 2): pl.clear() @@ -125,7 +125,7 @@ async def test_delete_temp_playlists( checker._playlist_check_collections = {collection.name: collection for collection in collections} await checker._delete_playlists() - assert checker.api.handler.authoriser.response_handler.response is not None # re-authorised + assert checker.api.handler.authoriser.response # re-authorised assert not checker._playlist_originals assert not checker._playlist_check_collections diff --git a/tests/libraries/remote/spotify/api/test_api.py b/tests/libraries/remote/spotify/api/test_api.py index c54bee05..6ecddd64 100644 --- a/tests/libraries/remote/spotify/api/test_api.py +++ b/tests/libraries/remote/spotify/api/test_api.py @@ -39,13 +39,13 @@ def test_init(self, cache: ResponseCache): assert api.handler.authoriser.service_name == api.wrangler.source assert api.handler.authoriser.user_request.params["client_id"] == client_id assert api.handler.authoriser.user_request.params["scope"] == " ".join(scopes) - assert api.handler.authoriser.response_handler.file_path == Path(token_file_path) + assert api.handler.authoriser.response.file_path == Path(token_file_path) async def test_context_management(self, cache: ResponseCache, api_mock: SpotifyMock): api = SpotifyAPI(cache=cache) - api.handler.authoriser.response_handler.response = { + api.handler.authoriser.response.replace({ "access_token": "fake access token", "token_type": "Bearer", "scope": "test-read" - } + }) with pytest.raises(APIError): assert api.user_id @@ -78,9 +78,9 @@ async def test_context_management(self, cache: ResponseCache, api_mock: SpotifyM async def test_cache_repository_getter(self, cache: ResponseCache, api_mock: SpotifyMock): api = SpotifyAPI(cache=cache) - api.handler.authoriser.response_handler.response = { + api.handler.authoriser.response.replace({ "access_token": "fake access token", "token_type": "Bearer", "scope": "test-read" - } + }) async with api as a: name_url_map = { "tracks": f"{a.wrangler.url_api}/tracks/{random_id()}", diff --git a/tests/libraries/remote/spotify/test_processors.py b/tests/libraries/remote/spotify/test_processors.py index 08d925b1..8634b9b7 100644 --- a/tests/libraries/remote/spotify/test_processors.py +++ b/tests/libraries/remote/spotify/test_processors.py @@ -356,8 +356,8 @@ def matcher(self) -> ItemMatcher: @pytest.fixture def checker(self, matcher: ItemMatcher, api: SpotifyAPI, token_file_path: Path) -> RemoteItemChecker: - api.handler.authoriser.response_handler.file_path = token_file_path - api.handler.authoriser.response_tester.max_expiry = 0 + api.handler.authoriser.response.file_path = token_file_path + api.handler.authoriser.tester.max_expiry = 0 return RemoteItemChecker(matcher=matcher, object_factory=SpotifyObjectFactory(api=api))