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_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")
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 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 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 test_report_dates(self): selector = self.get_selector() playlist = ChirpBroadcast() 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 # default date d = datetime.datetime(2010, 01, 10, 1, 1, 1) # album 'a', will be played twice albums = ['a', 'b', 'c', 'a'] tracks = ['a', 'b', 'c'] for album in albums: for track in tracks: s = "%s_%s" % (album, track) t = create_track("artist_" + s, "album_" + album, "track_" + track, "label_" + s) t.established = d t.put() # change date so each album is played once in a day # total of len(tracks) per day d = d - timedelta(days=1) # run report check against expected counts total_tracks = len(albums) * len(tracks) # date range to get all records from_date = datetime.datetime(2010, 01, 01, 0, 0, 0) to_date = datetime.datetime(2010, 01, 20, 0, 0, 0) # test query object recs pl = playlists_views.filter_tracks_by_date_range(from_date, to_date) self.assertEquals(total_tracks, pl.count()) # test group by query, expect a total of 9 recs since album_a was played twice items = playlists_views.query_group_by_track_key(from_date, to_date) for i in items: if i['album_title'] is 'album_a': self.assertEquals(i['play_count'], 2) self.assertEquals(len(items), 9) # check timestamp is set correctly for same date range from_date = to_date = datetime.datetime(2010, 01, 10, 0, 0, 0) pl = playlists_views.filter_tracks_by_date_range(from_date, to_date) self.assertEquals(len(tracks), pl.count())
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): 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 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_chirp_broadcast_playlist(self): playlist = ChirpBroadcast() self.assertEqual(playlist.established.timetuple()[0:4], datetime.datetime.now().timetuple()[0:4]) self.assertEqual(playlist.modified.timetuple()[0:4], datetime.datetime.now().timetuple()[0:4]) # just for sanity, not very good tests: self.assertEqual(playlist.established_display.timetuple()[0:2], datetime.datetime.now().timetuple()[0:2]) self.assertEqual(playlist.modified_display.timetuple()[0:2], datetime.datetime.now().timetuple()[0:2])
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_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_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_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_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_add_break(self): playlist = ChirpBroadcast() selector = self.get_selector() track = PlaylistTrack( playlist=playlist, selector=selector, freeform_artist_name="Steely Dan", freeform_album_title="Aja", freeform_track_title="Peg") track.put() 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() # add the break: resp = self.client.post(reverse('playlists_add_event'), { 'submit': "Add Break", 'artist': "artist", 'song': "song", 'album': "album", 'song_notes': "song notes" }) # self.assertNoFormErrors(resp) self.assertEqual(resp.status_code, 200) self.assertEqual(resp.context['form']['artist'].data, 'artist') self.assertEqual(resp.context['form']['song'].data, 'song') self.assertEqual(resp.context['form']['album'].data, 'album') self.assertEqual(resp.context['form']['song_notes'].data, 'song notes') # make sure form errors are not in response: assert 'Please enter the label' not in resp.content # add one track after the break: track = PlaylistTrack( playlist=playlist, selector=selector, freeform_artist_name="Kid Sister", freeform_album_title="Ultraviolet", freeform_track_title="Right Hand Hi") track.put() resp = self.client.get(reverse('playlists_landing_page')) context = resp.context[0] events = [t for t in context['playlist_events']] self.assertEqual(events[0].artist_name, "Kid Sister") self.assertEqual(events[0].is_break, False) self.assertEqual(events[0].is_new, True) self.assertEqual(events[1].is_break, True) self.assertEqual(events[1].is_new, False) self.assertEqual(events[2].artist_name, "Def Leoppard") self.assertEqual(events[2].is_break, False) self.assertEqual(events[2].is_new, False) self.assertEqual(events[3].artist_name, "Steely Dan") self.assertEqual(events[3].is_break, False) self.assertEqual(events[3].is_new, False) # print resp.content assert '<p class="break">Break</p>' in resp.content assert '<span class="artist">Def Leoppard</span>' in resp.content assert '<span class="artist">Steely Dan</span>' in resp.content
def test_chirp_broadcast_playlist_is_a_singleton(self): first = ChirpBroadcast() second = ChirpBroadcast() self.assertEqual(first.key(), second.key()) fetched = BroadcastPlaylist.all().filter("channel =", "CHIRP")[0] self.assertEqual(fetched.key(), first.key())
def test_report_csv(self): selector = self.get_selector() playlist = ChirpBroadcast() stevie, talking_book, tracks = create_stevie_wonder_album_data() track = PlaylistTrack(categories=[HEAVY_ROTATION_TAG], playlist=playlist, selector=selector, artist=stevie, album=talking_book, track=tracks['You Are The Sunshine Of My Life'], freeform_label='Motown') 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", freeform_label="Geffen") track.put() time.sleep(0.4) track = PlaylistTrack(playlist=playlist, selector=selector, freeform_artist_name="Def Leoppard", freeform_album_title="Pyromania", freeform_track_title="Photograph", freeform_label="Geffen") track.put() time.sleep(0.4) # Heavy rotation: track = PlaylistTrack(categories=[LIGHT_ROTATION_TAG], playlist=playlist, selector=selector, freeform_artist_name=u'Ivan Krsti\u0107', freeform_album_title=u'Ivan Krsti\u0107', freeform_track_title=u'Ivan Krsti\u0107', freeform_label=u'Ivan Krsti\u0107') track.put() 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), # in light rotation: 'Ivan Krsti\xc4\x87', 'Ivan Krsti\xc4\x87', 'Ivan Krsti\xc4\x87', '1', '0', '1' ], report.next()) self.assertEquals([ str(from_date), str(to_date), 'Pyromania', 'Def Leoppard', 'Geffen', '2', '0', '0' ], report.next()) self.assertEquals( [ str(from_date), str(to_date), # is in heavy rotation 'Talking Book', 'Stevie Wonder', 'Motown', '1', '1', '0' ], report.next())