Accept wishlist track_data aliases
- Let the wishlist service accept both track_data and spotify_track_data - Preserve the backward-compatible wrapper while avoiding the keyword argument crash - Add a regression test for the alias path
This commit is contained in:
parent
7a9f074a70
commit
b1a9c1b458
2 changed files with 41 additions and 6 deletions
|
|
@ -94,8 +94,9 @@ class WishlistService:
|
||||||
|
|
||||||
def add_track_to_wishlist(
|
def add_track_to_wishlist(
|
||||||
self,
|
self,
|
||||||
track_data: Dict[str, Any],
|
track_data: Dict[str, Any] = None,
|
||||||
failure_reason: str,
|
spotify_track_data: Dict[str, Any] = None,
|
||||||
|
failure_reason: str = "",
|
||||||
source_type: str = "manual",
|
source_type: str = "manual",
|
||||||
source_context: Dict[str, Any] = None,
|
source_context: Dict[str, Any] = None,
|
||||||
profile_id: int = 1,
|
profile_id: int = 1,
|
||||||
|
|
@ -110,8 +111,15 @@ class WishlistService:
|
||||||
source_context: Additional context information
|
source_context: Additional context information
|
||||||
profile_id: Profile to add to
|
profile_id: Profile to add to
|
||||||
"""
|
"""
|
||||||
|
if track_data is None:
|
||||||
|
track_data = spotify_track_data
|
||||||
|
|
||||||
|
if not track_data:
|
||||||
|
logger.error("No track data provided for wishlist add")
|
||||||
|
return False
|
||||||
|
|
||||||
return self.database.add_to_wishlist(
|
return self.database.add_to_wishlist(
|
||||||
spotify_track_data=track_data,
|
track_data=track_data,
|
||||||
failure_reason=failure_reason,
|
failure_reason=failure_reason,
|
||||||
source_type=source_type,
|
source_type=source_type,
|
||||||
source_info=source_context or {},
|
source_info=source_context or {},
|
||||||
|
|
@ -120,15 +128,19 @@ class WishlistService:
|
||||||
|
|
||||||
def add_spotify_track_to_wishlist(
|
def add_spotify_track_to_wishlist(
|
||||||
self,
|
self,
|
||||||
spotify_track_data: Dict[str, Any],
|
spotify_track_data: Dict[str, Any] = None,
|
||||||
failure_reason: str,
|
track_data: Dict[str, Any] = None,
|
||||||
|
failure_reason: str = "",
|
||||||
source_type: str = "manual",
|
source_type: str = "manual",
|
||||||
source_context: Dict[str, Any] = None,
|
source_context: Dict[str, Any] = None,
|
||||||
profile_id: int = 1,
|
profile_id: int = 1,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Backward-compatible wrapper for `add_track_to_wishlist`."""
|
"""Backward-compatible wrapper for `add_track_to_wishlist`."""
|
||||||
|
if track_data is None:
|
||||||
|
track_data = spotify_track_data
|
||||||
|
|
||||||
return self.add_track_to_wishlist(
|
return self.add_track_to_wishlist(
|
||||||
track_data=spotify_track_data,
|
track_data=track_data,
|
||||||
failure_reason=failure_reason,
|
failure_reason=failure_reason,
|
||||||
source_type=source_type,
|
source_type=source_type,
|
||||||
source_context=source_context,
|
source_context=source_context,
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,29 @@ def test_add_failed_track_from_modal_returns_false_when_no_spotify_track_found()
|
||||||
assert fake_db.add_calls == []
|
assert fake_db.add_calls == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_spotify_track_to_wishlist_accepts_track_data_alias():
|
||||||
|
fake_db = _FakeWishlistDatabase()
|
||||||
|
service = _build_service(fake_db)
|
||||||
|
|
||||||
|
result = service.add_spotify_track_to_wishlist(
|
||||||
|
track_data={
|
||||||
|
"id": "sp-1",
|
||||||
|
"name": "Song One",
|
||||||
|
"artists": [{"name": "Artist One"}],
|
||||||
|
"album": {"name": "Album One"},
|
||||||
|
},
|
||||||
|
failure_reason="Download failed",
|
||||||
|
source_type="manual",
|
||||||
|
profile_id=2,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result is True
|
||||||
|
assert fake_db.add_calls[0]["track_data"]["id"] == "sp-1"
|
||||||
|
assert fake_db.add_calls[0]["failure_reason"] == "Download failed"
|
||||||
|
assert fake_db.add_calls[0]["source_type"] == "manual"
|
||||||
|
assert fake_db.add_calls[0]["profile_id"] == 2
|
||||||
|
|
||||||
|
|
||||||
def test_get_wishlist_tracks_for_download_formats_modal_shape():
|
def test_get_wishlist_tracks_for_download_formats_modal_shape():
|
||||||
fake_db = _FakeWishlistDatabase(
|
fake_db = _FakeWishlistDatabase(
|
||||||
tracks=[
|
tracks=[
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue