mopidy/tests/core/test_history.py
Stein Magnus Jodal 5317834baf history: Change size property to get_length() method
For consistency with tracklist.get_length() and our goal of aligning Python
and JS APIs by using less properties in the core API.
2014-09-23 18:47:54 +02:00

48 lines
1.4 KiB
Python

from __future__ import unicode_literals
import unittest
from mopidy.core import HistoryController
from mopidy.models import Artist, Track
class PlaybackHistoryTest(unittest.TestCase):
def setUp(self):
self.tracks = [
Track(uri='dummy1:a', name='foo',
artists=[Artist(name='foober'), Artist(name='barber')]),
Track(uri='dummy2:a', name='foo'),
Track(uri='dummy3:a', name='bar')
]
self.history = HistoryController()
def test_add_track(self):
self.history.add(self.tracks[0])
self.assertEqual(self.history.get_length(), 1)
self.history.add(self.tracks[1])
self.assertEqual(self.history.get_length(), 2)
self.history.add(self.tracks[2])
self.assertEqual(self.history.get_length(), 3)
def test_non_tracks_are_rejected(self):
with self.assertRaises(TypeError):
self.history.add(object())
self.assertEqual(self.history.get_length(), 0)
def test_history_entry_contents(self):
track = self.tracks[0]
self.history.add(track)
result = self.history.get_history()
(timestamp, ref) = result[0]
self.assertIsInstance(timestamp, int)
self.assertEqual(track.uri, ref.uri)
self.assertIn(track.name, ref.name)
for artist in track.artists:
self.assertIn(artist.name, ref.name)