def test_does_not_scrobble_if_played_less_than_half(self, pylast_mock):
        track = models.Track(length=180432, artists=self.artists)
        tl_track = models.TlTrack(track=track, tlid=17)

        self.frontend.track_playback_ended(tl_track, 60432)

        self.assertEqual(self.frontend.lastfm.scrobble.call_count, 0)
    def test_does_scrobble_if_played_not_half_but_240_sec(self, pylast_mock):
        track = models.Track(length=880432, artists=self.artists)
        tl_track = models.TlTrack(track=track, tlid=17)

        self.frontend.track_playback_ended(tl_track, 241432)

        self.assertEqual(self.frontend.lastfm.scrobble.call_count, 1)
def test_track_playback_ended_scrobbles_played_track(pylast_mock, frontend):
    frontend.last_start_time = 123
    frontend.lastfm = mock.Mock(spec=pylast.LastFMNetwork)
    artists = [models.Artist(name="ABC"), models.Artist(name="XYZ")]
    album = models.Album(name="The Collection")
    track = models.Track(
        name="One Two Three",
        artists=artists,
        album=album,
        track_no=3,
        length=180432,
        musicbrainz_id="123-456",
    )
    tl_track = models.TlTrack(track=track, tlid=17)

    frontend.track_playback_ended(tl_track, 150000)

    frontend.lastfm.scrobble.assert_called_with(
        "ABC, XYZ",
        "One Two Three",
        "123",
        duration="180",
        album="The Collection",
        track_number="3",
        mbid="123-456",
    )
    def test_track_playback_started_catches_pylast_error(self, pylast_mock):
        pylast_mock.ScrobblingError = pylast.ScrobblingError
        self.frontend.lastfm.update_now_playing.side_effect = (
            pylast.ScrobblingError('foo'))
        tl_track = models.TlTrack(track=self.track, tlid=17)

        self.frontend.track_playback_started(tl_track)
    def test_track_playback_started_fails_on_missing_artists(
            self, pylast_mock):
        track = models.Track()
        tl_track = models.TlTrack(track=track, tlid=17)

        self.assertRaises(ValueError, self.frontend.track_playback_started,
                          tl_track)
    def test_does_not_scrobble_tracks_shorter_than_30_sec(self, pylast_mock):
        track = models.Track(length=20432, artists=self.artists)
        tl_track = models.TlTrack(track=track, tlid=17)

        self.frontend.track_playback_ended(tl_track, 20432)

        self.assertEqual(self.frontend.lastfm.scrobble.call_count, 0)
Exemple #7
0
def test_aborts_if_less_than_half_is_played(frontend, send_mock):
    track = models.Track(uri="gmusic:track:foo", length=60000)
    tl_track = models.TlTrack(tlid=17, track=track)

    frontend.track_playback_ended(tl_track, 20000)

    assert send_mock.call_count == 0
def test_track_playback_ended_catches_pylast_error(pylast_mock, frontend):
    frontend.lastfm = mock.Mock(spec=pylast.LastFMNetwork)
    pylast_mock.NetworkError = pylast.NetworkError
    frontend.lastfm.scrobble.side_effect = pylast.NetworkError(None, "foo")
    track = models.Track(length=180432)
    tl_track = models.TlTrack(track=track, tlid=17)

    frontend.track_playback_ended(tl_track, 150000)
def test_does_not_scrobble_if_played_less_than_half(pylast_mock, frontend):
    frontend.lastfm = mock.Mock(spec=pylast.LastFMNetwork)
    track = models.Track(length=180432)
    tl_track = models.TlTrack(track=track, tlid=17)

    frontend.track_playback_ended(tl_track, 60432)

    assert frontend.lastfm.scrobble.call_count == 0
def test_does_not_scrobble_tracks_shorter_than_30_sec(pylast_mock, frontend):
    frontend.lastfm = mock.Mock(spec=pylast.LastFMNetwork)
    track = models.Track(length=20432)
    tl_track = models.TlTrack(track=track, tlid=17)

    frontend.track_playback_ended(tl_track, 20432)

    assert frontend.lastfm.scrobble.call_count == 0
    def test_track_playback_ended_catches_pylast_error(self, pylast_mock):
        pylast_mock.ScrobblingError = pylast.ScrobblingError
        self.frontend.lastfm.scrobble.side_effect = (
            pylast.ScrobblingError('foo'))
        track = models.Track(length=180432, artists=self.artists)
        tl_track = models.TlTrack(track=track, tlid=17)

        self.frontend.track_playback_ended(tl_track, 150000)
    def test_does_not_scrobble_if_played_less_than_half(self, pylast_mock):
        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, 60432)

        self.assertEqual(self.frontend.lastfm.scrobble.call_count, 0)
def test_scrobbles_if_more_than_half_is_played(frontend, send_mock):
    track = models.Track(uri='gmusic:track:foo', length=60000)
    tl_track = models.TlTrack(tlid=17, track=track)

    frontend.track_playback_ended(tl_track, 40000)

    send_mock.assert_called_once_with(
        mock.ANY, 'increment_song_playcount', track_id='foo')
    def test_does_scrobble_if_played_not_half_but_240_sec(self, pylast_mock):
        self.frontend.lastfm = mock.Mock(spec=pylast.LastFMNetwork)
        track = models.Track(length=880432)
        tl_track = models.TlTrack(track=track, tlid=17)

        self.frontend.track_playback_ended(tl_track, 241432)

        self.assertEqual(self.frontend.lastfm.scrobble.call_count, 1)
    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)
        tl_track = models.TlTrack(track=track, tlid=17)

        self.frontend.track_playback_ended(tl_track, 20432)

        self.assertEqual(self.frontend.lastfm.scrobble.call_count, 0)
    def test_track_playback_ended_catches_pylast_error(self, pylast_mock):
        self.frontend.lastfm = mock.Mock(spec=pylast.LastFMNetwork)
        pylast_mock.ScrobblingError = pylast.ScrobblingError
        self.frontend.lastfm.scrobble.side_effect = (
            pylast.ScrobblingError('foo'))
        track = models.Track(length=180432)
        tl_track = models.TlTrack(track=track, tlid=17)

        self.frontend.track_playback_ended(tl_track, 150000)
    def test_track_playback_started_catches_pylast_error(self, pylast_mock):
        self.frontend.lastfm = mock.Mock(spec=pylast.LastFMNetwork)
        pylast_mock.NetworkError = pylast.NetworkError
        self.frontend.lastfm.update_now_playing.side_effect = (
            pylast.NetworkError(None, 'foo'))
        track = models.Track()
        tl_track = models.TlTrack(track=track, tlid=17)

        self.frontend.track_playback_started(tl_track)
def test_track_playback_started_catches_pylast_error(pylast_mock, frontend):
    frontend.lastfm = mock.Mock(spec=pylast.LastFMNetwork)
    pylast_mock.NetworkError = pylast.NetworkError
    frontend.lastfm.update_now_playing.side_effect = pylast.NetworkError(
        None, "foo")
    track = models.Track()
    tl_track = models.TlTrack(track=track, tlid=17)

    frontend.track_playback_started(tl_track)
def test_track_playback_started_has_default_values(pylast_mock, frontend):
    frontend.lastfm = mock.Mock(spec=pylast.LastFMNetwork)
    track = models.Track()
    tl_track = models.TlTrack(track=track, tlid=17)

    frontend.track_playback_started(tl_track)

    frontend.lastfm.update_now_playing.assert_called_with("",
                                                          "",
                                                          duration="0",
                                                          album="",
                                                          track_number="0",
                                                          mbid="")
    def test_track_playback_started_has_default_values(self, pylast_mock):
        self.frontend.lastfm = mock.Mock(spec=pylast.LastFMNetwork)
        track = models.Track()
        tl_track = models.TlTrack(track=track, tlid=17)

        self.frontend.track_playback_started(tl_track)

        self.frontend.lastfm.update_now_playing.assert_called_with(
            '',
            '',
            duration='0',
            album='',
            track_number='0',
            mbid='')
    def test_track_playback_ended_scrobbles_played_track(self, pylast_mock):
        self.frontend.last_start_time = 123
        tl_track = models.TlTrack(track=self.track, tlid=17)

        self.frontend.track_playback_ended(tl_track, 150000)

        self.frontend.lastfm.scrobble.assert_called_with(
            artist='ABC',
            title='One Two Three',
            timestamp='123',
            duration='180',
            album='The Collection',
            track_number='3',
            mbid='123-456')
    def test_track_playback_started_updates_now_playing(self, pylast_mock):
        tl_track = models.TlTrack(track=self.track, tlid=17)

        self.frontend.track_playback_started(tl_track)

        # get_artists() returns the primary artist and thus, we expect 'ABC'
        # instead of 'ABC, XYZ'
        self.frontend.lastfm.update_now_playing.assert_called_with(
            artist='ABC',
            title='One Two Three',
            duration='180',
            album='The Collection',
            track_number='3',
            mbid='123-456')
    def test_track_playback_ended_has_default_values(self, pylast_mock):
        self.frontend.last_start_time = 123
        track = models.Track(length=180432, artists=self.artists)
        tl_track = models.TlTrack(track=track, tlid=17)

        self.frontend.track_playback_ended(tl_track, 150000)

        self.frontend.lastfm.scrobble.assert_called_with(artist='ABC',
                                                         title='',
                                                         timestamp='123',
                                                         duration='180',
                                                         album='',
                                                         track_number='0',
                                                         mbid='')
def test_track_playback_ended_has_default_values(pylast_mock, frontend):
    frontend.last_start_time = 123
    frontend.lastfm = mock.Mock(spec=pylast.LastFMNetwork)
    track = models.Track(length=180432)
    tl_track = models.TlTrack(track=track, tlid=17)

    frontend.track_playback_ended(tl_track, 150000)

    frontend.lastfm.scrobble.assert_called_with("",
                                                "",
                                                "123",
                                                duration="180",
                                                album="",
                                                track_number="0",
                                                mbid="")
    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_track_playback_started_updates_now_playing(self, pylast_mock):
        self.frontend.lastfm = mock.Mock(spec=pylast.LastFMNetwork)
        artists = [models.Artist(name='ABC'), models.Artist(name='XYZ')]
        album = models.Album(name='The Collection')
        track = models.Track(
            name='One Two Three',
            artists=artists,
            album=album,
            track_no=3,
            length=180432,
            musicbrainz_id='123-456')
        tl_track = models.TlTrack(track=track, tlid=17)

        self.frontend.track_playback_started(tl_track)

        self.frontend.lastfm.update_now_playing.assert_called_with(
            'ABC, XYZ',
            'One Two Three',
            duration='180',
            album='The Collection',
            track_number='3',
            mbid='123-456')