def test_simple(self): assert len(MusicStorage.get()) == 0 music = MusicStorage() music.title = 'demo_title' music.artist = 'demo_artist' music.album = 'demo_album' music.company = 'demo_company' music.public_time = '2013' music.kbps = '64' music.cover = self.cover.read() music.audio = self.audio.read() now = datetime.datetime(2013, 12, 24, 10, 8, 0) music.upload_date = now music.uuid = 'douban-sid-aid' music.save() assert type(music.key) == str key = music.key assert len(MusicStorage.get()) == 1 assert len(MusicStorage.get(title='demo_title')) == 1 assert len(MusicStorage.get(title='demo_title', album='demo_album')) == 1 assert len(MusicStorage.get(title='unkown')) == 0 music = MusicStorage.get()[0] assert music.key == key assert music.title == 'demo_title' assert music.artist == 'demo_artist' assert music.album == 'demo_album' assert music.company == 'demo_company' assert music.public_time == '2013' assert music.kbps == '64' self.cover.seek(0) self.audio.seek(0) assert music.cover.read() == self.cover.read() assert music.audio.read() == self.audio.read() assert music.upload_date == now assert music.uuid == 'douban-sid-aid' music.delete() assert len(MusicStorage.get()) == 0
def add_music(title, artist, album, company, public_time, kbps, cover_fd, audio_fd, uuid): '''add new music, return music obj''' music = MusicStorage() music.title = title music.artist = artist music.album = album music.company = company music.public_time = public_time music.kbps = kbps music.cover = cover_fd music.audio = audio_fd music.upload_date = datetime.datetime.now() music.uuid = uuid # TODO # if on save error, cover & audio also be created in db.fs.files # should be fix in storage music.save() return music
def test_update(self): assert len(MusicStorage.get()) == 0 music = MusicStorage() music.title = 'demo_title' music.artist = 'demo_artist' music.album = 'demo_album' music.company = 'demo_company' music.public_time = '2013' music.kbps = '64' # exchange cover & audio music.cover = self.cover.read() music.audio = self.audio.read() now = datetime.datetime(2013, 12, 24, 10, 8, 0) music.upload_date = now music.uuid = 'douban-sid-aid' music.save() self.cover.seek(0) self.audio.seek(0) music.update(title='new_title', artist='new_artist', album='new_album', company='new_company', public_time='2014', kbps='128', cover=self.audio, audio=self.cover, uuid='new_douban-uuid') music = MusicStorage.get()[0] assert music.title == 'new_title' assert music.artist == 'new_artist' assert music.album == 'new_album' assert music.company == 'new_company' assert music.public_time == '2014' assert music.kbps == '128' self.cover.seek(0) self.audio.seek(0) assert music.cover.read() == self.audio.read() assert music.audio.read() == self.cover.read() assert music.uuid == 'new_douban-uuid'
def get_music(**kwargs): '''return music obj''' return MusicStorage.get(**kwargs)
def get_music_status(): '''return music set status''' return MusicStorage.status()