@@ -2366,3 +2366,124 @@ async def test_check_too_many_saved_shows(
23662366 with pytest .raises (ValueError , match = "Maximum of 50 shows can be checked at once" ):
23672367 await authenticated_client .are_shows_saved (["abc" ] * 51 )
23682368 responses .assert_not_called () # type: ignore[no-untyped-call]
2369+
2370+
2371+ async def test_save_tracks (
2372+ responses : aioresponses ,
2373+ authenticated_client : SpotifyClient ,
2374+ ) -> None :
2375+ """Test saving tracks."""
2376+ responses .put (
2377+ f"{ SPOTIFY_URL } /v1/me/tracks?ids=0TnOYISbd1XYRBk9myaseg" ,
2378+ status = 200 ,
2379+ body = "" ,
2380+ )
2381+ await authenticated_client .save_tracks (["0TnOYISbd1XYRBk9myaseg" ])
2382+ responses .assert_called_once_with (
2383+ f"{ SPOTIFY_URL } /v1/me/tracks" ,
2384+ METH_PUT ,
2385+ headers = HEADERS ,
2386+ params = {"ids" : "0TnOYISbd1XYRBk9myaseg" },
2387+ json = None ,
2388+ )
2389+
2390+
2391+ async def test_save_no_tracks (
2392+ responses : aioresponses ,
2393+ authenticated_client : SpotifyClient ,
2394+ ) -> None :
2395+ """Test saving no tracks."""
2396+ await authenticated_client .save_tracks ([])
2397+ responses .assert_not_called () # type: ignore[no-untyped-call]
2398+
2399+
2400+ async def test_save_too_many_tracks (
2401+ responses : aioresponses ,
2402+ authenticated_client : SpotifyClient ,
2403+ ) -> None :
2404+ """Test saving too many tracks."""
2405+ with pytest .raises (ValueError , match = "Maximum of 50 tracks can be saved at once" ):
2406+ await authenticated_client .save_tracks (["abc" ] * 51 )
2407+ responses .assert_not_called () # type: ignore[no-untyped-call]
2408+
2409+
2410+ async def test_remove_tracks (
2411+ responses : aioresponses ,
2412+ authenticated_client : SpotifyClient ,
2413+ ) -> None :
2414+ """Test removing tracks."""
2415+ responses .delete (
2416+ f"{ SPOTIFY_URL } /v1/me/tracks?ids=0TnOYISbd1XYRBk9myaseg" ,
2417+ status = 200 ,
2418+ body = "" ,
2419+ )
2420+ await authenticated_client .remove_saved_tracks (["0TnOYISbd1XYRBk9myaseg" ])
2421+ responses .assert_called_once_with (
2422+ f"{ SPOTIFY_URL } /v1/me/tracks" ,
2423+ METH_DELETE ,
2424+ headers = HEADERS ,
2425+ params = {"ids" : "0TnOYISbd1XYRBk9myaseg" },
2426+ json = None ,
2427+ )
2428+
2429+
2430+ async def test_remove_no_tracks (
2431+ responses : aioresponses ,
2432+ authenticated_client : SpotifyClient ,
2433+ ) -> None :
2434+ """Test removing no tracks."""
2435+ await authenticated_client .remove_saved_tracks ([])
2436+ responses .assert_not_called () # type: ignore[no-untyped-call]
2437+
2438+
2439+ async def test_remove_too_many_tracks (
2440+ responses : aioresponses ,
2441+ authenticated_client : SpotifyClient ,
2442+ ) -> None :
2443+ """Test removing too many tracks."""
2444+ with pytest .raises (ValueError , match = "Maximum of 50 tracks can be removed at once" ):
2445+ await authenticated_client .remove_saved_tracks (["abc" ] * 51 )
2446+ responses .assert_not_called () # type: ignore[no-untyped-call]
2447+
2448+
2449+ async def test_check_saved_tracks (
2450+ responses : aioresponses ,
2451+ snapshot : SnapshotAssertion ,
2452+ authenticated_client : SpotifyClient ,
2453+ ) -> None :
2454+ """Test checking saved tracks."""
2455+ responses .get (
2456+ f"{ SPOTIFY_URL } /v1/me/tracks/contains?ids=18yVqkdbdRvS24c0Ilj2ci%2C1HGw3J3NxZO1TP1BTtVhpZ" ,
2457+ status = 200 ,
2458+ body = load_fixture ("tracks_saved.json" ),
2459+ )
2460+ response = await authenticated_client .are_tracks_saved (
2461+ ["18yVqkdbdRvS24c0Ilj2ci" , "1HGw3J3NxZO1TP1BTtVhpZ" ]
2462+ )
2463+ assert response == snapshot
2464+ responses .assert_called_once_with (
2465+ f"{ SPOTIFY_URL } /v1/me/tracks/contains" ,
2466+ METH_GET ,
2467+ headers = HEADERS ,
2468+ params = {"ids" : "18yVqkdbdRvS24c0Ilj2ci,1HGw3J3NxZO1TP1BTtVhpZ" },
2469+ json = None ,
2470+ )
2471+
2472+
2473+ async def test_check_no_saved_tracks (
2474+ responses : aioresponses ,
2475+ authenticated_client : SpotifyClient ,
2476+ ) -> None :
2477+ """Test checking no saved tracks."""
2478+ assert await authenticated_client .are_tracks_saved ([]) == {}
2479+ responses .assert_not_called () # type: ignore[no-untyped-call]
2480+
2481+
2482+ async def test_check_too_many_saved_tracks (
2483+ responses : aioresponses ,
2484+ authenticated_client : SpotifyClient ,
2485+ ) -> None :
2486+ """Test checking too many saved tracks."""
2487+ with pytest .raises (ValueError , match = "Maximum of 50 tracks can be checked at once" ):
2488+ await authenticated_client .are_tracks_saved (["abc" ] * 51 )
2489+ responses .assert_not_called () # type: ignore[no-untyped-call]
0 commit comments