Skip to content

Commit

Permalink
Work with None as default track_no in Mopidy 0.20
Browse files Browse the repository at this point in the history
  • Loading branch information
jodal committed Oct 2, 2014
1 parent 042707a commit 528ecdd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ Project resources
Changelog
=========

v1.1.1 (UNRELEASED)
-------------------

- Updated to work with ``None`` as the default value of ``track_no`` in
Mopidy's ``Track`` model. This was changed in Mopidy 0.20.

v1.1.0 (2014-01-20)
-------------------

Expand Down
4 changes: 2 additions & 2 deletions mopidy_scrobbler/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def track_playback_started(self, tl_track):
(track.name or ''),
album=(track.album and track.album.name or ''),
duration=str(duration),
track_number=str(track.track_no),
track_number=str(track.track_no or 0),
mbid=(track.musicbrainz_id or ''))
except (pylast.ScrobblingError, pylast.NetworkError,
pylast.MalformedResponseError, pylast.WSError) as e:
Expand All @@ -73,7 +73,7 @@ def track_playback_ended(self, tl_track, time_position):
(track.name or ''),
str(self.last_start_time),
album=(track.album and track.album.name or ''),
track_number=str(track.track_no),
track_number=str(track.track_no or 0),
duration=str(duration),
mbid=(track.musicbrainz_id or ''))
except (pylast.ScrobblingError, pylast.NetworkError,
Expand Down
17 changes: 17 additions & 0 deletions tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ def test_track_playback_ended_scrobbles_played_track(self, pylast_mock):
track_number='3',
mbid='123-456')

def test_track_playback_ended_has_default_values(self, pylast_mock):
self.frontend.last_start_time = 123
self.frontend.lastfm = mock.Mock(spec=pylast.LastFMNetwork)
track = models.Track(length=180432)
tl_track = models.TlTrack(track=track, tlid=17)

self.frontend.track_playback_ended(tl_track, 150000)

self.frontend.lastfm.scrobble.assert_called_with(
'',
'',
'123',
duration='180',
album='',
track_number='0',
mbid='')

def test_does_not_scrobble_tracks_shorter_than_30_sec(self, pylast_mock):
self.frontend.lastfm = mock.Mock(spec=pylast.LastFMNetwork)
track = models.Track(length=20432)
Expand Down

0 comments on commit 528ecdd

Please sign in to comment.