def test_get_song_entry(self, db): sdb = SongDB() song_entry = sdb.get_song_entry('Heilig1') assert song_entry == [] song_entry = sdb.get_song_entry('Heilig2') assert song_entry[0]['song'] == 'Heilig2'
def test_import_songs(self, db): with open(this_path('test_songdb.txt'), 'r') as f: songs = [song.split()[0] for song in f] with SongDB() as sdb: sdb.import_songs(songs) assert db.get(where('song') == 'HeiligWO5')['last_time'] is None assert db.get(where('song') == 'HeiligWO5')['cnt'] == 0
def test_new_setlist(db): pList = SetList() pList.new_setlist('01.02.3456', [ ['Anbetung', 'Heilig'], ]) db = SongDB() assert db.get_song_entry('Heilig')[0]['last_time'] == db.validate_date( '01.02.3456')
def test_clear_cache(self, db): with open(this_path('test_songdb_dates.txt'), 'r') as f: songs = { song.split(',')[0]: song.split(',')[1].split()[0] for song in f } with SongDB() as sdb: sdb.update_songs(songs) sdb.clear_cache() assert db.get(where('song') == 'HeiligWO5') is None
def test_update_songs(self, db): with open(this_path('test_songdb_dates.txt'), 'r') as f: songs = { song.split(',')[0]: song.split(',')[1].split()[0] for song in f } with SongDB() as sdb: sdb.update_songs(songs) assert '06.01.2019' in db.get( where('song') == 'HeiligWO5')['last_time'] assert db.get(where('song') == 'HeiligWO5')['cnt'] == 1
def test_new_song_entry(self, db): today = datetime.datetime.today().date().strftime('%d.%m.%Y') with SongDB( ) as sdb: # close needed as cachedmiddle used --> context manager sdb.new_song_entry("Heilig", today) assert today in db.get(where('song') == 'Heilig')['last_time'] assert db.get(where('song') == 'Heilig')['cnt'] == 1 with SongDB() as sdb: sdb.new_song_entry("New_Song") assert db.get(where('song') == 'New_Song')['last_time'] is None assert db.get(where('song') == 'New_Song')['cnt'] == 0 with SongDB() as sdb: sdb.new_song_entry("New_Song", "01.02.2134") assert "01.02.2134" in db.get(where('song') == 'New_Song')['last_time'] assert db.get(where('song') == 'New_Song')['cnt'] == 1 with SongDB() as sdb: sdb.new_song_entry("New_Song", "01.02.2020") assert "01.02.2134" in db.get(where('song') == 'New_Song')['last_time'] assert db.get(where('song') == 'New_Song')['cnt'] == 2
def new_setlist(self, date, song_groups: list, force=False): """ Create new PDF Setlist for given date. Song groups are in order --> group title then all songs. @param date: planned date for setlist @param song_groups: list of song groups. @param force: Insert song to database if not existing yet @return: None """ with SongDB() as sdb: self.date(date if sdb.validate_date(date) else '') for sg in song_groups: self.group(sg[0]) for s in sg[1:]: if not force and not sdb.get_song_entry(s): # Clear cache if setlist is wrong and will not be used # Database must have only songs which are used and reflect only (e.g. song sung on day x times) sdb.clear_cache() raise ValueError( 'Please insert this song first into your database', s) self.song(s) sdb.new_song_entry(s, date) self.output('Setlist_' + date + '.pdf')
def test_list_from_folder(self, db, tmpdir): sdb = SongDB() songlist = sdb.list_from_folder(unpack_test_data(tmpdir)) assert 'Alles will ich Jesu weihen' in songlist
def test_cmd_not_available_song(db): os.system( 'setlist --date 01.02.3456 --song-group Anbetung "Test New Song"') db = SongDB() assert db.get_song_entry('Test New Song') == []
def test_cmd(db): os.system('setlist --date 01.02.3456 --song-group Anbetung Heilig') db = SongDB() assert db.get_song_entry('Heilig')[0]['last_time'] == db.validate_date( '01.02.3456')