Ejemplo n.º 1
0
    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'
Ejemplo n.º 2
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')
Ejemplo n.º 3
0
    def test_validate_date(self):
        assert SongDB.validate_date(datetime.datetime.today().date().strftime(
            '%d.%m.%Y')) == datetime.datetime.today().date()
        assert SongDB.validate_date('01.01.2019')

        with pytest.raises(ValueError):
            SongDB.validate_date('01.01.19')
        with pytest.raises(ValueError):
            SongDB.validate_date('40.01.2019')
        with pytest.raises(ValueError):
            SongDB.validate_date('01.40.2019')
        with pytest.raises(ValueError):
            SongDB.validate_date('01.01.10000')
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
 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')
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
 def test_compare_date(self):
     d1 = datetime.date(2019, 1, 1)
     d2 = datetime.date(2019, 1, 2)
     assert SongDB.compare_date(d1, d2) == d2
Ejemplo n.º 11
0
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') == []
Ejemplo n.º 12
0
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')