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 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 play_count_snapshot(request): """Cron view to create a play count snapshot (top 40).""" qs = PlayCount.all().order('-play_count') results = [] for count in qs.fetch(40): results.append(PlayCountSnapshot.create_from_count(count)) for res in results: res.get_result() # wait for result log.info('Created play count snapshot')
def expunge_play_count(request): """Cron view to expire old play counts.""" # Delete tracks that have not been incremented in the last week. qs = PlayCount.all().filter('modified <', datetime.now() - timedelta(days=7)) num = 0 for ob in qs.fetch(1000): ob.delete() num += 1 log.info('Deleted %s old play count entries' % num)
def test_expunge(self): self.count() ob = PlayCount.all()[0] old_ts = datetime.datetime.now() - timedelta(days=8) @staticmethod def now(): return old_ts # Trick the data model into saving an auto-modified timestamp # a week in the past. p = fudge.patch_object(datetime.datetime, 'now', now) try: ob.save() finally: p.restore() res = self.expunge() eq_(res.status_code, 200) eq_(PlayCount.all().count(1), 0)
def test_expunge(self): from nose.exc import SkipTest raise SkipTest( 'App Engine is stupid and doesnt allow you to use a ' 'stub datetime object') self.count() ob = PlayCount.all()[0] old_ts = datetime.datetime.now() - timedelta(days=8) @staticmethod def now(): return old_ts # Trick the data model into saving an auto-modified timestamp # a week in the past. p = fudge.patch_object(datetime.datetime, 'now', now) try: ob.save() finally: p.restore() res = self.expunge() eq_(res.status_code, 200) eq_(PlayCount.all().count(1), 0)
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 test_no_expunge(self): self.count() res = self.expunge() eq_(res.status_code, 200) eq_(PlayCount.all().count(1), 1)