history: Raise TypeError if non-Tracks are added

This commit is contained in:
Stein Magnus Jodal 2014-09-23 18:42:26 +02:00
parent ded43039bf
commit d30cf68efd
2 changed files with 7 additions and 9 deletions

View File

@ -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)

View File

@ -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]