def test_starred(self): session = mock_session() self.assertEqual(self.track.starred(session), False) self.track.starred(session, set=True) self.assertEqual(self.track.starred(session), True) self.track.starred(session, set=False) self.assertEqual(self.track.starred(session), False)
class TestAlbumbrowser(unittest.TestCase): session = mock_session() album = mock_album("foo0", mock_artist("bar0", 1), 2006, "01234567890123456789", Album.ALBUM, 1, 1) def callback(self, browser, userdata): global callback_called global callback_userdata callback_called = True callback_userdata = userdata def test_is_loaded(self): browser = mock_albumbrowse(self.session, self.album, 1, self.callback) assert browser.is_loaded() def test_is_not_loaded(self): browser = mock_albumbrowse(self.session, self.album, 0, self.callback) assert not browser.is_loaded() def test_sequence(self): browser = mock_albumbrowse(self.session, self.album, 1, self.callback) assert len(browser) == 3 assert browser[0].name() == 'foo' assert browser[1].name() == 'bar' assert browser[2].name() == 'baz' def test_callback(self): global callback_called global callback_userdata callback_called = False browser = mock_albumbrowse(self.session, self.album, 0, self.callback, self) self.assertTrue(callback_called) self.assertEqual(callback_userdata, self)
class TestArtistbrowser(unittest.TestCase): session = mock_session() artist = mock_artist("foo0", 1) def callback(self, browser, userdata): global callback_called global callback_userdata callback_called = True callback_userdata = userdata def test_is_loaded(self): browser = mock_artistbrowse(self.session, self.artist, 1, self.callback) assert browser.is_loaded() def test_is_not_loaded(self): browser = mock_artistbrowse(self.session, self.artist, 0, self.callback) assert not browser.is_loaded() def test_sequence(self): browser = mock_artistbrowse(self.session, self.artist, 1, self.callback) assert len(browser) == 3 assert browser[0].name() == 'foo' assert browser[1].name() == 'bar' assert browser[2].name() == 'baz' def test_callback(self): global callback_called global callback_userdata callback_called = False browser = mock_artistbrowse(self.session, self.artist, 0, self.callback, self) self.assertTrue(callback_called) self.assertEqual(callback_userdata, self)
import unittest from spotify._mockspotify import mock_session import pdb,time session = mock_session() class TestSearch(unittest.TestCase): def test_search_is_loaded(self): global is_loaded is_loaded = None def _(results, userdata=None): global is_loaded is_loaded = results.is_loaded() session.search("!loaded", _) self.assertEqual(is_loaded, False) session.search("loaded", _) self.assertEqual(is_loaded, True) def test_artists(self): global result artists = None def _(results, userdata=None): global result result = results.artists() session.search("", _) self.assertNotEqual(result, None) self.assertEqual(result[0].name(), "foo") self.assertEqual(result[1].name(), "bar") def test_albums(self):
import unittest from spotify._mockspotify import mock_session import pdb, time session = mock_session() class TestSearch(unittest.TestCase): def test_search_is_loaded(self): global is_loaded is_loaded = None def _(results, userdata=None): global is_loaded is_loaded = results.is_loaded() session.search("!loaded", _) self.assertEqual(is_loaded, False) session.search("loaded", _) self.assertEqual(is_loaded, True) def test_artists(self): global result artists = None def _(results, userdata=None): global result result = results.artists() session.search("", _) self.assertNotEqual(result, None)
class TestPlaylist(unittest.TestCase): artist = mock_artist('artist') album = mock_album('album', artist) owner = mock_user('owner') tracks = [ (mock_track('track1', [artist], album), owner, 1320961109), (mock_track('track2', [artist], album), owner, 1320961109), (mock_track('track3', [artist], album), owner, 1320961109), ] pure_tracks = [t[0] for t in tracks] session = mock_session() def setUp(self): mock_set_current_session(self.session) def tearDown(self): mock_set_current_session(None) def test_name(self): playlist = mock_playlist('playlist', [], self.owner) self.assertEqual(playlist.name(), 'playlist') def test_name_unicode(self): playlist = mock_playlist(u'plåylïst', [], self.owner) self.assertEqual(playlist.name(), u'plåylïst') def test_rename(self): playlist = mock_playlist(u'foo', [], self.owner) playlist.rename(u'bar') self.assertEqual(playlist.name(), u'bar') def test_rename_unicode(self): playlist = mock_playlist(u'foo', [], self.owner) playlist.rename(u'bąr') self.assertEqual(playlist.name(), u'bąr') @raises(ValueError) def test_rename_too_long(self): playlist = mock_playlist(u'foo', [], self.owner) playlist.rename(u'bar' * 100) def test_len(self): playlist = mock_playlist(u'foo', self.tracks, self.owner) self.assertEqual(len(playlist), 3) def test_sq_item(self): playlist = mock_playlist(u'foo', self.tracks, self.owner) self.assertEqual(playlist[0].name(), 'track1') self.assertEqual(playlist[1].name(), 'track2') self.assertEqual(playlist[2].name(), 'track3') def test_num_subscribers(self): playlist = mock_playlist('foo', [], self.owner, num_subscribers=42) self.assertEqual(playlist.num_subscribers(), 42) def test_subscribers(self): playlist = mock_playlist(u'foo', [], self.owner, subscribers=['foo', 'bar', 'baz']) self.assertEqual(playlist.subscribers(), [u'foo', u'bar', u'baz']) def test_add_tracks_ok(self): playlist = mock_playlist(u'foo', [], self.owner) playlist.add_tracks(0, self.pure_tracks) @raises(IndexError) def test_add_tracks_wrong_position(self): playlist = mock_playlist('foo', [], self.owner) playlist.add_tracks(99, self.pure_tracks) def test_add_tracks_wrong_types(self): playlist = mock_playlist('foo', [], self.owner) self.assertRaises(TypeError, playlist.add_tracks, 0, True) self.assertRaises(TypeError, playlist.add_tracks, [False]) def test_track_create_time(self): playlist = mock_playlist('foo', self.tracks, self.owner) self.assertEqual(playlist.track_create_time(0), 1320961109) def test_owner(self): playlist = mock_playlist('foo', [], self.owner) self.assertEqual(playlist.owner().canonical_name(), self.owner.canonical_name())