def test_one_songs(self): song = jukebox.song.Song( title='song 1', album='album 1', artist='artist 1', uri='path 1', ) request = mock.Mock(name='request') storage = jukebox.storage.MemoryStorage() pk = yield storage.add_song(song) api = jukebox.api.API(storage=storage) result = yield api.all_songs(request) request.setHeader.assert_called_with('Content-Type', 'application/json') assert result == json.dumps({ 'songs': [{ 'pk': pk, 'title': 'song 1', 'album': 'album 1', 'artist': 'artist 1', }] })
def test_add_get_song(self): storage = self.make_storage() song = jukebox.song.Song( title='song 1', album='album 1', artist='artist 1', uri='path 1', ) pk = yield storage.add_song(song) song_back = yield storage.get_song(pk) util.song_assert(song, song_back)
def test_remove_song(self): storage = self.make_storage() song = jukebox.song.Song( title='song 1', album='album 1', artist='artist 1', uri='path 1', ) pk = yield storage.add_song(song) song = yield storage.get_song(pk) yield storage.remove_song(song) with pytest.raises(KeyError): yield storage.get_song(pk)
def test_multi_add_get(self): storage = self.make_storage() for i in range(10): song = jukebox.song.Song( title='song %s' % i, album='album %s' % i, artist='artist %s' % i, uri='path %s' % i, ) song.pk = yield storage.add_song(song) song_back = yield storage.get_song(song.pk) util.song_assert(song, song_back)
def test_few_songs(self): request = mock.Mock(name='request') storage = jukebox.storage.MemoryStorage() pks = [] for i in range(3): song = jukebox.song.Song( title='song %s' % i, album='album %s' % i, artist='artist %s' % i, uri='path %s' % i, ) pk = yield storage.add_song(song) pks.append(pk) api = jukebox.api.API(storage=storage) result = yield api.all_songs(request) request.setHeader.assert_called_with('Content-Type', 'application/json') assert result == json.dumps({ 'songs': [ { 'pk': pks[0], 'title': 'song 0', 'album': 'album 0', 'artist': 'artist 0', }, { 'pk': pks[1], 'title': 'song 1', 'album': 'album 1', 'artist': 'artist 1', }, { 'pk': pks[2], 'title': 'song 2', 'album': 'album 2', 'artist': 'artist 2', }, ] })
def test_few_songs(self): request = mock.Mock(name='request') storage = jukebox.storage.MemoryStorage() pks = [] for i in range(3): song = jukebox.song.Song( title='song %s' % i, album='album %s' % i, artist='artist %s' % i, uri='path %s' % i, ) pk = yield storage.add_song(song) pks.append(pk) api = jukebox.api.API(storage=storage) result = yield api.all_songs(request) request.setHeader.assert_called_with( 'Content-Type', 'application/json' ) assert result == json.dumps({'songs': [ { 'pk': pks[0], 'title': 'song 0', 'album': 'album 0', 'artist': 'artist 0', }, { 'pk': pks[1], 'title': 'song 1', 'album': 'album 1', 'artist': 'artist 1', }, { 'pk': pks[2], 'title': 'song 2', 'album': 'album 2', 'artist': 'artist 2', }, ]})
def test_multi_add_get_all(self): storage = self.make_storage() songs = [] for i in range(10): song = jukebox.song.Song( title='song %s' % i, album='album %s' % i, artist='artist %s' % i, uri='path %s' % i, ) song.pk = yield storage.add_song(song) songs.append(song) all_songs = yield storage.get_all_songs() all_songs = list(all_songs) songs.sort(key=operator.attrgetter('pk')) all_songs.sort(key=operator.attrgetter('pk')) for song1, song2 in zip(songs, all_songs): util.song_assert(song1, song2)
def test_one_songs(self): song = jukebox.song.Song( title='song 1', album='album 1', artist='artist 1', uri='path 1', ) request = mock.Mock(name='request') storage = jukebox.storage.MemoryStorage() pk = yield storage.add_song(song) api = jukebox.api.API(storage=storage) result = yield api.all_songs(request) request.setHeader.assert_called_with( 'Content-Type', 'application/json' ) assert result == json.dumps({'songs': [{ 'pk': pk, 'title': 'song 1', 'album': 'album 1', 'artist': 'artist 1', }]})