Skip to content

Commit

Permalink
update for aiorequestful v0.6.0 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
geo-martino committed Jul 11, 2024
1 parent da25e13 commit f86c260
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
10 changes: 5 additions & 5 deletions musify/libraries/remote/spotify/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion musify/libraries/remote/spotify/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()})
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/libraries/remote/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions tests/libraries/remote/core/processors/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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

Expand Down
10 changes: 5 additions & 5 deletions tests/libraries/remote/spotify/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()}",
Expand Down
4 changes: 2 additions & 2 deletions tests/libraries/remote/spotify/test_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit f86c260

Please sign in to comment.