history: Raise TypeError if non-Tracks are added
This commit is contained in:
parent
ded43039bf
commit
d30cf68efd
@ -20,9 +20,8 @@ class HistoryController(object):
|
||||
:param track: track to change to
|
||||
:type track: :class:`mopidy.models.Track`
|
||||
"""
|
||||
if type(track) is not models.Track:
|
||||
logger.warning('Cannot add non-Track type object to TrackHistory')
|
||||
return
|
||||
if not isinstance(track, models.Track):
|
||||
raise TypeError('Only Track objects can be added to the history')
|
||||
|
||||
timestamp = int(time.time() * 1000)
|
||||
|
||||
|
||||
@ -23,12 +23,11 @@ class PlaybackHistoryTest(unittest.TestCase):
|
||||
self.history.add(self.tracks[2])
|
||||
self.assertEqual(self.history.size, 3)
|
||||
|
||||
def test_unsuitable_add(self):
|
||||
size = self.history.size
|
||||
self.history.add(self.tracks[0])
|
||||
self.history.add(object())
|
||||
self.history.add(self.tracks[1])
|
||||
self.assertEqual(self.history.size, size + 2)
|
||||
def test_non_tracks_are_rejected(self):
|
||||
with self.assertRaises(TypeError):
|
||||
self.history.add(object())
|
||||
|
||||
self.assertEqual(self.history.size, 0)
|
||||
|
||||
def test_history_sanity(self):
|
||||
track = self.tracks[0]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user