def test_incomplete_track(self): selector = self.get_selector() playlist = ChirpBroadcast() track = PlaylistTrack(playlist=playlist, selector=selector, freeform_artist_name="Squarepusher", freeform_track_title="Port Rhombus") track.put() with fudge.patched_context(playlists.tasks, "_fetch_url", stub_fetch_url): resp = self.client.post(reverse('playlists_add_event'), { 'artist': 'Julio Iglesias', 'album': 'Mi Amore' }) # self.assertNoFormErrors(resp) context = resp.context[0] self.assertEqual( context['form'].errors.as_text(), "* song\n * Please enter the song title.\n* label\n * Please enter the label." ) assert 'Please enter the label.' in resp.content tracks = [t for t in context['playlist_events']] self.assertEquals(tracks[0].artist_name, "Squarepusher") self.assertEquals(tracks[0].track_title, "Port Rhombus")
def bootstrap(request): # Don't create dummy playlist tracks if playlist tracks already exist! pl_tracks = PlaylistTrack.all().fetch(1) if len(pl_tracks) > 0: return HttpResponse(status=404) playlist = ChirpBroadcast() minutes = 0 tracks = Track.all().fetch(100) for track in tracks: pl_track = PlaylistTrack( playlist=playlist, selector=request.user, established=datetime.now() - timedelta(minutes=minutes), artist=track.album.album_artist, album=track.album, track=track, ) pl_track.put() if minutes > 0 and minutes % 25 == 0: pl_break = PlaylistBreak(playlist=playlist, established=datetime.now() - timedelta(minutes=minutes - 1)) pl_break.put() minutes += 5 return HttpResponseRedirect("/playlists/")
def make_track(): playlist = ChirpBroadcast() track = PlaylistTrack(selector=selector, playlist=playlist, artist=self.stevie, album=self.talking_book) track.put()
def test_track_by_free_entry(self): selector = create_dj() playlist = ChirpBroadcast() track = PlaylistTrack( selector=selector, playlist=playlist, freeform_artist_name="Stevie Wonder", freeform_album_title="Talking Book", freeform_track_title='You Are The Sunshine Of My Life', freeform_label='Warner Bros.', notes="This track is a bit played out but it still has some nice melodies" ) track.put() self.assertEqual(track.artist_name, "Stevie Wonder") self.assertEqual(track.album_title, "Talking Book") self.assertEqual(track.album_title_display, "Talking Book") self.assertEqual(track.track_title, "You Are The Sunshine Of My Life") self.assertEqual(track.label, "Warner Bros.") self.assertEqual(track.label_display, "Warner Bros.") self.assertEqual(track.notes, "This track is a bit played out but it still has some nice melodies") # for sanity, not real tests: self.assertEqual( track.established_display.timetuple()[0:2], datetime.datetime.now().timetuple()[0:2]) self.assertEqual( track.modified_display.timetuple()[0:2], datetime.datetime.now().timetuple()[0:2])
def bootstrap(request): # Don't create dummy playlist tracks if playlist tracks already exist! pl_tracks = PlaylistTrack.all().fetch(1) if len(pl_tracks) > 0: return HttpResponse(status=404) playlist = ChirpBroadcast() minutes = 0 tracks = Track.all().fetch(100) for track in tracks: pl_track = PlaylistTrack(playlist=playlist, selector=request.user, established=datetime.now() - timedelta(minutes=minutes), artist=track.album.album_artist, album=track.album, track=track) pl_track.put() if minutes > 0 and minutes % 25 == 0: pl_break = PlaylistBreak(playlist=playlist, established=datetime.now() - timedelta(minutes=minutes - 1)) pl_break.put() minutes += 5 return HttpResponseRedirect("/playlists/")
class PlaylistTest(APITest): def setUp(self): super(PlaylistTest, self).setUp() dbconfig['lastfm.api_key'] = 'SEKRET_LASTFM_KEY' self.dj = User(dj_name='DJ Night Moves', first_name='Steve', last_name='Dolfin', email='*****@*****.**', roles=[auth.roles.DJ]) self.dj.save() self.playlist = ChirpBroadcast() (self.stevie, self.talking_book, self.tracks) = create_stevie_wonder_album_data() def play_stevie_song(self, song_name): self.playlist_track = PlaylistTrack( playlist=self.playlist, selector=self.dj, artist=self.stevie, album=self.talking_book, track=self.tracks[song_name], notes='from 1972!', freeform_label='Motown') self.playlist_track.save() return self.playlist_track
def test_cannot_delete_someone_elses_track(self): other_user = User(email="*****@*****.**") other_user.roles.append(auth.roles.DJ) other_user.put() time.sleep(0.4) other_track = PlaylistTrack( playlist=self.playlist, selector=other_user, freeform_artist_name="Peaches", freeform_track_title="Rock Show",) other_track.put() with fudge.patched_context(playlists.tasks, "_fetch_url", stub_fetch_url): resp = self.client.get(reverse('playlists_delete_event', args=[other_track.key()])) self.assertRedirects(resp, reverse('playlists_landing_page')) # simulate the redirect: resp = self.client.get(reverse('playlists_landing_page')) # should be no change: context = resp.context[0] tracks = [t.artist_name for t in context['playlist_events']] self.assertEquals(tracks, ["Peaches", "Steely Dan"])
def test_track_by_free_entry(self): selector = create_dj() playlist = ChirpBroadcast() track = PlaylistTrack( selector=selector, playlist=playlist, freeform_artist_name="Stevie Wonder", freeform_album_title="Talking Book", freeform_track_title='You Are The Sunshine Of My Life', freeform_label='Warner Bros.', notes= "This track is a bit played out but it still has some nice melodies" ) track.put() self.assertEqual(track.artist_name, "Stevie Wonder") self.assertEqual(track.album_title, "Talking Book") self.assertEqual(track.album_title_display, "Talking Book") self.assertEqual(track.track_title, "You Are The Sunshine Of My Life") self.assertEqual(track.label, "Warner Bros.") self.assertEqual(track.label_display, "Warner Bros.") self.assertEqual( track.notes, "This track is a bit played out but it still has some nice melodies" ) # for sanity, not real tests: self.assertEqual(track.established_display.timetuple()[0:2], datetime.datetime.now().timetuple()[0:2]) self.assertEqual(track.modified_display.timetuple()[0:2], datetime.datetime.now().timetuple()[0:2])
def save(self): if not self.current_user: raise ValueError("Cannot save() without a current_user") playlist_track = PlaylistTrack(playlist=self.playlist, selector=self.current_user) if self.cleaned_data['artist_key']: playlist_track.artist = Artist.get(self.cleaned_data['artist_key']) else: playlist_track.freeform_artist_name = self.cleaned_data['artist'] if self.cleaned_data['song_key']: playlist_track.track = Track.get(self.cleaned_data['song_key']) else: playlist_track.freeform_track_title = self.cleaned_data['song'] if self.cleaned_data['album_key']: playlist_track.album = Album.get(self.cleaned_data['album_key']) elif self.cleaned_data['album']: playlist_track.freeform_album_title = self.cleaned_data['album'] if self.cleaned_data['label']: playlist_track.freeform_label = self.cleaned_data['label'] if self.cleaned_data['song_notes']: playlist_track.notes = self.cleaned_data['song_notes'] if self.cleaned_data['is_heavy_rotation']: playlist_track.categories.append('heavy_rotation') if self.cleaned_data['is_light_rotation']: playlist_track.categories.append('light_rotation') if self.cleaned_data['is_local_current']: playlist_track.categories.append('local_current') if self.cleaned_data['is_local_classic']: playlist_track.categories.append('local_classic') AutoRetry(playlist_track).save() return playlist_track
def make_track(): playlist = ChirpBroadcast() track = PlaylistTrack( selector=selector, playlist=playlist, album=self.talking_book, track=self.tracks['You Are The Sunshine Of My Life']) track.put()
def make_track(): playlist = ChirpBroadcast() track = PlaylistTrack( selector=selector, playlist=playlist, artist=self.stevie, album=self.talking_book ) track.put()
def make_track(): playlist = ChirpBroadcast() track = PlaylistTrack( selector=selector, playlist=playlist, album=self.talking_book, track=self.tracks['You Are The Sunshine Of My Life'] ) track.put()
def create_track(artist, album, track, label): track = PlaylistTrack(playlist=playlist, selector=selector, freeform_artist_name=artist, freeform_album_title=album, freeform_track_title=track, freeform_label=label) track.put() return track
def create_track(artist, album, track, label): track = PlaylistTrack( playlist=playlist, selector=selector, freeform_artist_name=artist, freeform_album_title=album, freeform_track_title=track, freeform_label=label) track.put() return track
def play_stevie_song(self, song_name): self.playlist_track = PlaylistTrack(playlist=self.playlist, selector=self.dj, artist=self.stevie, album=self.talking_book, track=self.tracks[song_name], notes='from 1972!', freeform_label='Motown') self.playlist_track.save() return self.playlist_track
def setUp(self): super(TestDeleteTrackFromPlaylist, self).setUp() self.playlist = ChirpBroadcast() selector = self.get_selector() self.track = PlaylistTrack(playlist=self.playlist, selector=selector, freeform_artist_name="Steely Dan", freeform_album_title="Aja", freeform_track_title="Peg") self.track.put()
def save(self): if not self.current_user: raise ValueError("Cannot save() without a current_user") playlist_track = PlaylistTrack( playlist=self.playlist, selector=self.current_user) if self.cleaned_data['artist_key']: playlist_track.artist = Artist.get(self.cleaned_data['artist_key']) else: playlist_track.freeform_artist_name = self.cleaned_data['artist'] if self.cleaned_data['song_key']: playlist_track.track = Track.get(self.cleaned_data['song_key']) else: playlist_track.freeform_track_title = self.cleaned_data['song'] if self.cleaned_data['album_key']: playlist_track.album = Album.get(self.cleaned_data['album_key']) elif self.cleaned_data['album']: playlist_track.freeform_album_title = self.cleaned_data['album'] if self.cleaned_data['label']: playlist_track.freeform_label = self.cleaned_data['label'] if self.cleaned_data['song_notes']: playlist_track.notes = self.cleaned_data['song_notes'] if self.cleaned_data['is_heavy_rotation']: playlist_track.categories.append('heavy_rotation') if self.cleaned_data['is_light_rotation']: playlist_track.categories.append('light_rotation') if self.cleaned_data['is_local_current']: playlist_track.categories.append('local_current') if self.cleaned_data['is_local_classic']: playlist_track.categories.append('local_classic') AutoRetry(playlist_track).save() return playlist_track
def test_partial_track_by_free_entry(self): selector = create_dj() playlist = ChirpBroadcast() track = PlaylistTrack( selector=selector, playlist=playlist, freeform_artist_name="Stevie Wonder", freeform_track_title='You Are The Sunshine Of My Life') track.put() self.assertEqual(track.album_title_display, "[Unknown Album]") self.assertEqual(track.label_display, "[Unknown Label]")
def setUp(self): setup_dbconfig() self.playlist = ChirpBroadcast() selector = self.get_selector() self.track = PlaylistTrack( playlist=self.playlist, selector=selector, freeform_artist_name=u"Ivan Krsti\u0107", freeform_album_title=u"Ivan Krsti\u0107 album", freeform_track_title=u"Ivan Krsti\u0107 song", freeform_label='Some Label') self.track.put()
def test_partial_track_by_free_entry(self): selector = create_dj() playlist = ChirpBroadcast() track = PlaylistTrack( selector=selector, playlist=playlist, freeform_artist_name="Stevie Wonder", freeform_track_title='You Are The Sunshine Of My Life' ) track.put() self.assertEqual(track.album_title_display, "[Unknown Album]") self.assertEqual(track.label_display, "[Unknown Label]")
def test_different_tracks(self): self.count() new_trk = PlaylistTrack(playlist=self.track.playlist, selector=self.track.selector, freeform_artist_name='Prince', freeform_album_title='Purple Rain', freeform_track_title='When Doves Cry') new_trk.put() self.count(track_key=new_trk.key()) count = PlayCount.all()[0] track_ids = [str(w.key()) for w in PlayCount.all()] assert track_ids[0] != track_ids[1], ( 'Different artist/albums cannot have the same key')
def test_different_tracks(self): self.count() new_trk = PlaylistTrack( playlist=self.track.playlist, selector=self.track.selector, freeform_artist_name='Prince', freeform_album_title='Purple Rain', freeform_track_title='When Doves Cry') new_trk.put() self.count(track_key=new_trk.key()) count = PlayCount.all()[0] track_ids = [str(w.key()) for w in PlayCount.all()] assert track_ids[0] != track_ids[1], ( 'Different artist/albums cannot have the same key')
def save(self): if not self.current_user: raise ValueError("Cannot save() without a current_user") playlist_track = PlaylistTrack(playlist=self.playlist, selector=self.current_user) if self.cleaned_data['artist_key']: playlist_track.artist = Artist.get(self.cleaned_data['artist_key']) else: playlist_track.freeform_artist_name = self.cleaned_data['artist'] if self.cleaned_data['song_key']: playlist_track.track = Track.get(self.cleaned_data['song_key']) else: playlist_track.freeform_track_title = self.cleaned_data['song'] if self.cleaned_data['album_key']: playlist_track.album = Album.get(self.cleaned_data['album_key']) elif self.cleaned_data['album']: playlist_track.freeform_album_title = self.cleaned_data['album'] if self.cleaned_data['label']: playlist_track.freeform_label = self.cleaned_data['label'] if self.cleaned_data['song_notes']: playlist_track.notes = self.cleaned_data['song_notes'] if self.cleaned_data['is_heavy_rotation']: playlist_track.categories.append('heavy_rotation') if self.cleaned_data['is_light_rotation']: playlist_track.categories.append('light_rotation') if self.cleaned_data['is_local_current']: playlist_track.categories.append('local_current') if self.cleaned_data['is_local_classic']: playlist_track.categories.append('local_classic') AutoRetry(playlist_track).save() trk = playlist_track memcache.set( 'playlist.last_track', { 'artist_name': trk.artist_name, 'track_title': trk.track_title, 'album_title_display': trk.album_title_display, 'label_display': trk.label_display, 'notes': trk.notes, 'key': str(trk.key()), 'categories': list(trk.categories), 'selector_key': str(trk.selector.key()), 'established_display': trk.established.timetuple()[0:7] }, 30) return playlist_track
def clear_data(): for pl in Playlist.all(): for track in PlaylistTrack.all().filter('playlist =', pl): track.delete() pl.delete() for ob in PlayCount.all(): ob.delete()
def clear_data(): for pl in Playlist.all(): for track in PlaylistTrack.all().filter('playlist =', pl): track.delete() pl.delete() for u in User.all(): u.delete()
def post(self): links_fetched = 0 if not self.request.POST.get('id'): # This is a temporary workaround to free up the task queue. It # seems that old tasks are stuck in an error-retry loop log.error('id not found in POST') self.response.out.write(simplejson.dumps({'success': False})) return track = PlaylistTrack.get(self.request.POST['id']) if track is None: # Track was deleted by DJ, other scenarios? log.warning('track does not exist: %s' % self.request.POST['id']) self.response.out.write(simplejson.dumps({'success': False})) return try: fm = pylast.get_lastfm_network( api_key=dbconfig['lastfm.api_key']) fm_album = fm.get_album(track.artist_name, track.album_title) track.lastfm_url_sm_image = \ fm_album.get_cover_image(pylast.COVER_SMALL) track.lastfm_url_med_image = \ fm_album.get_cover_image(pylast.COVER_MEDIUM) track.lastfm_url_large_image = \ fm_album.get_cover_image(pylast.COVER_LARGE) except pylast.WSError: # Probably album not found log.exception('IGNORED while fetching LastFM data') track.lastfm_urls_processed = True # Even on error track.save() memcache.delete(CurrentPlaylist.cache_key) _push_notify('chirpradio.push.update-playlist-storage') self.response.out.write(simplejson.dumps({ 'success': True, 'links_fetched': links_fetched }))
def test_count_different_track(self): self.count() # Copy the same artist/track into a new track. new_trk = PlaylistTrack( playlist=self.track.playlist, selector=self.track.selector, freeform_artist_name=self.track.freeform_artist_name, freeform_album_title=self.track.freeform_album_title, freeform_track_title='Another track from the album') new_trk.put() self.count(track_key=new_trk.key()) count = PlayCount.all()[0] eq_(count.artist_name, self.track.freeform_artist_name) eq_(count.album_title, self.track.freeform_album_title) eq_(count.label, self.track.label) eq_(count.play_count, 2)
def post(self): links_fetched = 0 if not self.request.POST.get('id'): # This is a temporary workaround to free up the task queue. It # seems that old tasks are stuck in an error-retry loop log.error('id not found in POST') self.response.out.write(simplejson.dumps({'success': False})) return track = PlaylistTrack.get(self.request.POST['id']) if track is None: # Track was deleted by DJ, other scenarios? log.warning('track does not exist: %s' % self.request.POST['id']) self.response.out.write(simplejson.dumps({'success': False})) return try: fm = pylast.get_lastfm_network( api_key=dbconfig['lastfm.api_key']) fm_album = fm.get_album(track.artist_name, track.album_title) track.lastfm_url_sm_image = \ fm_album.get_cover_image(pylast.COVER_SMALL) track.lastfm_url_med_image = \ fm_album.get_cover_image(pylast.COVER_MEDIUM) track.lastfm_url_large_image = \ fm_album.get_cover_image(pylast.COVER_LARGE) except pylast.WSError: # Probably album not found log.exception('IGNORED while fetching LastFM data') track.lastfm_urls_processed = True # Even on error track.save() memcache.delete(CurrentPlaylist.cache_key) self.response.out.write(simplejson.dumps({ 'success': True, 'links_fetched': links_fetched }))
def test_track_by_references(self): selector = create_dj() playlist = ChirpBroadcast() track = PlaylistTrack( selector=selector, playlist=playlist, artist=self.stevie, album=self.talking_book, track=self.tracks['You Are The Sunshine Of My Life'] ) track.put() self.assertEqual(track.artist_name, "Stevie Wonder") self.assertEqual(track.artist, self.stevie) self.assertEqual(track.album_title, "Talking Book") self.assertEqual(track.album, self.talking_book) self.assertEqual(track.track_title, "You Are The Sunshine Of My Life") self.assertEqual(track.track, self.tracks['You Are The Sunshine Of My Life'])
def test_track_by_references(self): selector = create_dj() playlist = ChirpBroadcast() track = PlaylistTrack( selector=selector, playlist=playlist, artist=self.stevie, album=self.talking_book, track=self.tracks['You Are The Sunshine Of My Life']) track.put() self.assertEqual(track.artist_name, "Stevie Wonder") self.assertEqual(track.artist, self.stevie) self.assertEqual(track.album_title, "Talking Book") self.assertEqual(track.album, self.talking_book) self.assertEqual(track.track_title, "You Are The Sunshine Of My Life") self.assertEqual(track.track, self.tracks['You Are The Sunshine Of My Life'])
def get_json(self): playlist_key = chirp_playlist_key() recent_tracks = list(PlaylistTrack.all().filter("playlist =", playlist_key).order("-established").fetch(6)) return { "now_playing": self.track_as_data(recent_tracks.pop(0)), # Last 5 played tracks: "recently_played": [self.track_as_data(t) for t in recent_tracks], }
def filter_tracks_by_date_range(from_date, to_date): fd = datetime(from_date.year, from_date.month, from_date.day, 0, 0, 0) td = datetime(to_date.year, to_date.month, to_date.day, 23, 59, 59) playlist = chirp_playlist_key() pl = PlaylistTrack.all().filter("playlist =", playlist) pl = pl.filter("established >=", fd) pl = pl.filter("established <=", td) pl = pl.order("-established") return pl
def get_json(self): playlist_key = chirp_playlist_key() recent_tracks = list(PlaylistTrack.all().filter( 'playlist =', playlist_key).order('-established').fetch(6)) return { 'now_playing': self.track_as_data(recent_tracks.pop(0)), # Last 5 played tracks: 'recently_played': [self.track_as_data(t) for t in recent_tracks] }
def test_delete_link_appears_for_current_user(self): resp = self.client.get(reverse('playlists_landing_page')) assert '[delete]' in resp.content for track in PlaylistTrack.all(): track.delete() other_user = User(email="*****@*****.**") other_user.roles.append(auth.roles.DJ) other_user.put() other_track = PlaylistTrack(playlist=self.playlist, selector=other_user, freeform_artist_name="Peaches", freeform_track_title="Rock Show") other_track.put() resp = self.client.get(reverse('playlists_landing_page')) assert '[delete]' not in resp.content
def test_chirp_playlist_key(self): playlist_key = chirp_playlist_key() track = PlaylistTrack( selector=create_dj(), playlist=playlist_key, freeform_artist_name="Stevie Wonder", freeform_album_title="Talking Book", freeform_track_title='You Are The Sunshine Of My Life', freeform_label='Warner Bros.', ) track.put() trk = PlaylistTrack.all().filter('playlist =', playlist_key) self.assertEqual(trk[0].artist_name, 'Stevie Wonder') playlist_key = chirp_playlist_key() # from cache trk = PlaylistTrack.all().filter('playlist =', playlist_key) self.assertEqual(trk[0].artist_name, 'Stevie Wonder')
def filter_tracks_by_date_range(from_date, to_date): fd = datetime(from_date.year, from_date.month, from_date.day, 0, 0, 0) td = datetime(to_date.year, to_date.month, to_date.day, 23, 59, 59) playlist = chirp_playlist_key() pl = PlaylistTrack.all().filter('playlist =', playlist) pl = pl.filter('established >=', fd) pl = pl.filter('established <=', td) pl = pl.order('-established') return pl
def test_delete_link_appears_for_current_user(self): resp = self.client.get(reverse('playlists_landing_page')) assert '[delete]' in resp.content for track in PlaylistTrack.all(): track.delete() other_user = User(email="*****@*****.**") other_user.roles.append(auth.roles.DJ) other_user.put() other_track = PlaylistTrack( playlist=self.playlist, selector=other_user, freeform_artist_name="Peaches", freeform_track_title="Rock Show") other_track.put() resp = self.client.get(reverse('playlists_landing_page')) assert '[delete]' not in resp.content
def save(self): if not self.current_user: raise ValueError("Cannot save() without a current_user") playlist_track = PlaylistTrack( playlist=self.playlist, selector=self.current_user) if self.cleaned_data['artist_key']: playlist_track.artist = Artist.get(self.cleaned_data['artist_key']) else: playlist_track.freeform_artist_name = self.cleaned_data['artist'] if self.cleaned_data['song_key']: playlist_track.track = Track.get(self.cleaned_data['song_key']) else: playlist_track.freeform_track_title = self.cleaned_data['song'] if self.cleaned_data['album_key']: playlist_track.album = Album.get(self.cleaned_data['album_key']) elif self.cleaned_data['album']: playlist_track.freeform_album_title = self.cleaned_data['album'] if self.cleaned_data['label']: playlist_track.freeform_label = self.cleaned_data['label'] if self.cleaned_data['song_notes']: playlist_track.notes = self.cleaned_data['song_notes'] if self.cleaned_data['is_heavy_rotation']: playlist_track.categories.append('heavy_rotation') if self.cleaned_data['is_light_rotation']: playlist_track.categories.append('light_rotation') if self.cleaned_data['is_local_current']: playlist_track.categories.append('local_current') if self.cleaned_data['is_local_classic']: playlist_track.categories.append('local_classic') AutoRetry(playlist_track).save() trk = playlist_track memcache.set('playlist.last_track', { 'artist_name': trk.artist_name, 'track_title': trk.track_title, 'album_title_display': trk.album_title_display, 'label_display': trk.label_display, 'notes': trk.notes, 'key': str(trk.key()), 'categories': list(trk.categories), 'selector_key': str(trk.selector.key()), 'established_display': trk.established.timetuple()[0:7] }, 30) return playlist_track
def setUp(self): super(TestDeleteTrackFromPlaylist, self).setUp() self.playlist = ChirpBroadcast() selector = self.get_selector() self.track = PlaylistTrack( playlist=self.playlist, selector=selector, freeform_artist_name="Steely Dan", freeform_album_title="Aja", freeform_track_title="Peg") self.track.put()
def get_json(self): playlist_key = chirp_playlist_key() recent_tracks = list(PlaylistTrack.all() .filter('playlist =', playlist_key) .order('-established') .fetch(6)) return { 'now_playing': self.track_as_data(recent_tracks.pop(0)), # Last 5 played tracks: 'recently_played': [self.track_as_data(t) for t in recent_tracks] }
def play_stevie_song(self, song_name): self.playlist_track = PlaylistTrack( playlist=self.playlist, selector=self.dj, artist=self.stevie, album=self.talking_book, track=self.tracks[song_name], notes='from 1972!', freeform_label='Motown') self.playlist_track.save() return self.playlist_track
def test_break(self): playlist = ChirpBroadcast() selector = create_dj() track = PlaylistTrack(selector=selector, playlist=playlist, freeform_artist_name="The Meters", freeform_album_title="Chicken Strut", freeform_track_title="Hand Clapping Song") track.put() time.sleep(0.4) pl_break = PlaylistBreak(playlist=playlist) pl_break.put() self.assertEqual([type(e) for e in playlist.recent_tracks], [PlaylistTrack]) self.assertEqual([type(e) for e in playlist.recent_events], [PlaylistBreak, PlaylistTrack])
def test_create_ascii_chars(self): self.playlist = ChirpBroadcast() selector = self.get_selector() self.track = PlaylistTrack( playlist=self.playlist, selector=selector, freeform_artist_name=u'artist', freeform_album_title=u'album', freeform_track_title=u'song') self.track.put() def inspect_request(r): # NOTE: due to URL fetching, you can only raise # AssertionError here self.assertEqual(r.get_full_url(), 'http://__dummylive365service__/cgi-bin/add_song.cgi') qs = dict(cgi.parse_qsl(r.data)) self.assertEqual(qs['member_name'], "dummy_member") self.assertEqual(qs['password'], "dummy_password") self.assertEqual(qs['seconds'], '30') # c should be replaced because latin-1 can't encode that and Live365 likes latin-1 self.assertEqual(qs['title'], 'song') self.assertEqual(qs['album'], 'album') self.assertEqual(qs['artist'], 'artist') return True fake_urlopen = (fudge.Fake('urlopen', expect_call=True) .with_args(arg.passes_test(inspect_request))) fake_response = (fake_urlopen .returns_fake() .has_attr(code='200') .provides('read') .returns("<service response>")) with fudge.patched_context(playlists.tasks.urllib2, "urlopen", fake_urlopen): resp = self.client.post(reverse('playlists.send_track_to_live365'), { 'id': self.track.key() }) fudge.verify()
def test_freeform_compilation(self): stevie, talking_book, tracks = create_stevie_wonder_album_data() talking_book.is_compilation = True talking_book.put() for artist, track in (('Stevie Wonder', 'Superstition'), ('Stevie Wonder', 'Big Brother')): new_trk = PlaylistTrack( playlist=self.track.playlist, selector=self.track.selector, freeform_album_title='Talking Book', freeform_artist_name=artist, freeform_track_title=track, freeform_label='...') new_trk.put() self.count(track_key=new_trk.key()) res = self.snapshot() eq_(res.status_code, 200) snap = PlayCountSnapshot.all()[0] eq_(snap.play_count, 2) eq_(snap.artist_name, 'Various') eq_(snap.album_title, 'Talking Book')
def test_recent_tracks(self): playlist = ChirpBroadcast() selector = create_dj() track = PlaylistTrack( selector=selector, playlist=playlist, freeform_artist_name="Autechre", freeform_album_title="Amber", freeform_track_title="Ember" ) track.put() time.sleep(0.4) track = PlaylistTrack( selector=selector, playlist=playlist, freeform_artist_name="The Meters", freeform_album_title="Chicken Strut", freeform_track_title="Hand Clapping Song" ) track.put() recent_tracks = [t for t in playlist.recent_tracks] self.assertEqual(recent_tracks[0].track_title, "Hand Clapping Song") self.assertEqual(recent_tracks[1].track_title, "Ember")
def test_report_ignores_reference_errors(self): selector = self.get_selector() playlist = ChirpBroadcast() stevie, talking_book, tracks = create_stevie_wonder_album_data() track = PlaylistTrack( playlist=playlist, selector=selector, artist=stevie, album=talking_book, track=tracks['You Are The Sunshine Of My Life'], freeform_label='Motown') track.put() # simulate an integrity error. # it is unlikely but happened to us after a bad data import. stevie.delete() talking_book.delete() from_date = datetime.date.today() - timedelta(days=1) to_date = datetime.date.today() + timedelta(days=1) response = self.client.post(reverse('playlists_report'), { 'from_date': from_date, 'to_date': to_date, 'download': 'Download' }) self.assertEquals(response['Content-Type'], 'text/csv; charset=utf-8') report = csv.reader(StringIO(response.content)) self.assertEquals( ['from_date', 'to_date', 'album_title', 'artist_name', 'label', 'play_count', 'heavy_rotation', 'light_rotation'], report.next()) self.assertEquals( [str(from_date), str(to_date), '__bad_reference__', '__bad_reference__', 'Motown', '1', '0', '0'], report.next())
def test_report_ignores_reference_errors(self): selector = self.get_selector() playlist = ChirpBroadcast() stevie, talking_book, tracks = create_stevie_wonder_album_data() track = PlaylistTrack(playlist=playlist, selector=selector, artist=stevie, album=talking_book, track=tracks['You Are The Sunshine Of My Life'], freeform_label='Motown') track.put() # simulate an integrity error. # it is unlikely but happened to us after a bad data import. stevie.delete() talking_book.delete() from_date = datetime.date.today() - timedelta(days=1) to_date = datetime.date.today() + timedelta(days=1) response = self.client.post(reverse('playlists_report'), { 'from_date': from_date, 'to_date': to_date, 'download': 'Download' }) self.assertEquals(response['Content-Type'], 'text/csv; charset=utf-8') report = csv.reader(StringIO(response.content)) self.assertEquals([ 'from_date', 'to_date', 'album_title', 'artist_name', 'label', 'play_count', 'heavy_rotation', 'light_rotation' ], report.next()) self.assertEquals([ str(from_date), str(to_date), '__bad_reference__', '__bad_reference__', 'Motown', '1', '0', '0' ], report.next())
class TaskTest(object): def get_selector(self): user = User(email='*****@*****.**') user.roles = [roles.DJ] user.save() return user def setUp(self): setup_dbconfig() self.playlist = ChirpBroadcast() selector = self.get_selector() self.track = PlaylistTrack( playlist=self.playlist, selector=selector, freeform_artist_name=u"Ivan Krsti\u0107", freeform_album_title=u"Ivan Krsti\u0107 album", freeform_track_title=u"Ivan Krsti\u0107 song", freeform_label='Some Label') self.track.put() def tearDown(self): clear_data() fudge.clear_expectations()
def test_incomplete_track(self): selector = self.get_selector() playlist = ChirpBroadcast() track = PlaylistTrack( playlist=playlist, selector=selector, freeform_artist_name="Squarepusher", freeform_track_title="Port Rhombus") track.put() with fudge.patched_context(playlists.tasks, "_fetch_url", stub_fetch_url): resp = self.client.post(reverse('playlists_add_event'), { 'artist': 'Julio Iglesias', 'album': 'Mi Amore' }) # self.assertNoFormErrors(resp) context = resp.context[0] self.assertEqual(context['form'].errors.as_text(), "* song\n * Please enter the song title.\n* label\n * Please enter the label.") assert 'Please enter the label.' in resp.content tracks = [t for t in context['playlist_events']] self.assertEquals(tracks[0].artist_name, "Squarepusher") self.assertEquals(tracks[0].track_title, "Port Rhombus")
def test_view_shows_3_hours_of_tracks(self): selector = self.get_selector() playlist = ChirpBroadcast() track = PlaylistTrack( playlist=playlist, selector=selector, freeform_artist_name="Steely Dan", freeform_album_title="Aja", freeform_track_title="Peg") track.put() # sleep to workaround microtime issues in Windows App Engine SDK time.sleep(0.4) track = PlaylistTrack( playlist=playlist, selector=selector, freeform_artist_name="Def Leoppard", freeform_album_title="Pyromania", freeform_track_title="Photograph") track.put() time.sleep(0.4) track = PlaylistTrack( playlist=playlist, selector=selector, freeform_artist_name="Freestyle Fellowship", freeform_album_title="To Whom It May Concern", freeform_track_title="Five O'Clock Follies") # older than 3 hours: track.established = datetime.datetime.now() - datetime.timedelta(hours=3, minutes=2) track.put() resp = self.client.get(reverse('playlists_landing_page')) context = resp.context[0] tracks = [t for t in context['playlist_events']] self.assertEquals(tracks[0].track_title, "Photograph") self.assertEquals(tracks[1].track_title, "Peg") self.assertEquals(len(tracks), 2, "tracks older than 3 hours were not hidden")
class APITest(unittest.TestCase): def setUp(self): dbconfig['lastfm.api_key'] = 'SEKRET_LASTFM_KEY' self.client = TestApp(application) self.dj = User(dj_name='DJ Night Moves', first_name='Steve', last_name='Dolfin', email='*****@*****.**', roles=[auth.roles.DJ]) self.dj.save() self.playlist = ChirpBroadcast() (self.stevie, self.talking_book, self.tracks) = create_stevie_wonder_album_data() def tearDown(self): assert memcache.flush_all() clear_data() def play_stevie_song(self, song_name): self.playlist_track = PlaylistTrack( playlist=self.playlist, selector=self.dj, artist=self.stevie, album=self.talking_book, track=self.tracks[song_name], notes='from 1972!', freeform_label='Motown') self.playlist_track.save() return self.playlist_track def request(self, url): r = self.client.get(url) eq_(r.status, '200 OK') eq_(r.headers['content-type'], 'application/json') data = simplejson.loads(r.body) return data
class PlaylistTest(APITest): def setUp(self): super(PlaylistTest, self).setUp() dbconfig['lastfm.api_key'] = 'SEKRET_LASTFM_KEY' self.dj = User(dj_name='DJ Night Moves', first_name='Steve', last_name='Dolfin', email='*****@*****.**', roles=[auth.roles.DJ]) self.dj.save() self.playlist = ChirpBroadcast() (self.stevie, self.talking_book, self.tracks) = create_stevie_wonder_album_data() def play_stevie_song(self, song_name): self.playlist_track = PlaylistTrack(playlist=self.playlist, selector=self.dj, artist=self.stevie, album=self.talking_book, track=self.tracks[song_name], notes='from 1972!', freeform_label='Motown') self.playlist_track.save() return self.playlist_track
def test_recent_tracks(self): playlist = ChirpBroadcast() selector = create_dj() track = PlaylistTrack(selector=selector, playlist=playlist, freeform_artist_name="Autechre", freeform_album_title="Amber", freeform_track_title="Ember") track.put() time.sleep(0.4) track = PlaylistTrack(selector=selector, playlist=playlist, freeform_artist_name="The Meters", freeform_album_title="Chicken Strut", freeform_track_title="Hand Clapping Song") track.put() recent_tracks = [t for t in playlist.recent_tracks] self.assertEqual(recent_tracks[0].track_title, "Hand Clapping Song") self.assertEqual(recent_tracks[1].track_title, "Ember")