def test_artist_normal(client): SongFactory(name='name_a').tofile() SongFactory(name='name_b').tofile() url = url_for('main.artist', slug='artist') resp = client.get(url) assert resp.status_code == 200 assert b'name_a' in resp.data assert b'name_b' in resp.data
def test_contains(client): songs = [ Song.frommetadata(song_data) for song_data in playlist_data['songs'] ] playlist = Playlist(name=playlist_data['name'], songs=songs) playlist.tofile() assert 'test' in playlist assert SongFactory(name='Τεστ') in playlist assert 'asdf' not in playlist assert SongFactory(name='Ασδφ') not in playlist
def test_search(self, client): SongFactory(name='a', artist='lorem ipsum').tofile() SongFactory(name='b', artist='lorem ipsum').tofile() SongFactory(name='c', artist='lalalalalal').tofile() artists = list(Artist.search('ipsum')) assert len(artists) == 1 assert len(artists[0].songs) == 2 assert artists[0].slug == 'lorem_ipsum' artists = list(Artist.search('la')) assert len(artists) == 1 assert len(artists[0].songs) == 1 assert artists[0].slug == 'lalalalalal'
def test_session_get(client): SongFactory(name='name').tofile() url = url_for('main.song', slug='name') today = datetime.now().date().strftime('%Y.%m.%d') session_id = f'{today}-1' filename: Path = app.config['DIR'] / 'sessions' / session_id resp = client.get(url) assert resp.status_code == 200 assert not filename.is_file() client.post( url_for('admin.login'), data={'password': '******'}, follow_redirects=True, ) resp = client.get(url) assert resp.status_code == 200 assert filename.is_file() session = Session(session_id) assert len(session.songs) == 1 assert session.songs[0]['slug'] == 'name' assert 'name' in session
def test_add(client): songs = [ Song.frommetadata(song_data) for song_data in playlist_data['songs'] ] playlist = Playlist(name=playlist_data['name'], songs=songs) playlist.tofile() SongFactory(name='Ασδφ', artist='Ασδφ').tofile() playlist.add('asdf') assert (playlist.directory / f'{playlist.slug}.yml').read_text() == dedent("""\ name: Λίστα songs: - name: Ασδφ slug: asdf artist: Ασδφ artist_slug: asdf - name: Νέημ slug: neim artist: Βαμβακάρης artist_slug: vamvakaris root: A - name: Τεστ slug: test artist: Βαμβακάρης artist_slug: vamvakaris """)
def test_cache(client): SongFactory(artist='Βαμβακάρης', name='Ένα').tofile() SongFactory(artist='Βαμβακάρης', name='Δύο').tofile() SongFactory(artist='Σκαρβέλης', name='Τρία').tofile() assert cache_utils.get_songs() == { 'dyo': { 'artist': 'Βαμβακάρης', 'artist_slug': 'vamvakaris', 'name': 'Δύο', 'scale': 'scale', }, 'ena': { 'artist': 'Βαμβακάρης', 'artist_slug': 'vamvakaris', 'name': 'Ένα', 'scale': 'scale', }, 'tria': { 'artist': 'Σκαρβέλης', 'artist_slug': 'skarvelis', 'name': 'Τρία', 'scale': 'scale', }, } assert cache_utils.get_artists() == { 'vamvakaris': { 'name': 'Βαμβακάρης', 'songs': [{ 'name': 'Δύο', 'slug': 'dyo', }, { 'name': 'Ένα', 'slug': 'ena', }], }, 'skarvelis': { 'name': 'Σκαρβέλης', 'songs': [{ 'name': 'Τρία', 'slug': 'tria', }], } }
def test_save_delete(client): with client.session_transaction() as session: session['logged_in'] = True song = SongFactory(body='Bm F# Bm') song.tofile() assert len(Song.all()) == 1 url = url_for('admin.save', slug='name', semitones=1) resp = client.get(url, follow_redirects=True) assert resp.status_code == 200 song = Song.get('name') assert song.body == 'Cm G Cm' resp = client.get(url_for('admin.delete', slug='name'), follow_redirects=True) assert Song.all() == [] resp = client.get(url_for('admin.delete', slug='name'), follow_redirects=True) assert 'Δεν υπάρχει τέτοια σελίδα'.encode() in resp.data
def test_prepare_song(client): song1 = SongFactory(name='name_a', scale='D#') song2 = SongFactory(name='name_b', scale='Eb') song1.tofile() song2.tofile() assert Song.get('name_a', unicode=True).scale == 'D♯' assert Song.get('name_b', unicode=True).scale == 'E♭' assert Song.get('name_a', semitones=-2).scale == 'C#' assert Song.get('name_b', semitones=-2).scale == 'Db' assert Song.get('name_a', root='B').scale == 'B' assert Song.get('name_b', root='B').scale == 'B'
def test_add_invalid_root(client): songs = [ Song.frommetadata(song_data) for song_data in playlist_data['songs'] ] playlist = Playlist(name=playlist_data['name'], songs=songs) playlist.tofile() SongFactory(name='Ασδφ', artist='Ασδφ').tofile() with pytest.raises(InvalidNote): playlist.add('asdf', root='L')
def test_artist(self, client): SongFactory(name='a').tofile() SongFactory(name='b').tofile() assert repr(Artist.get('artist')) == "<Artist 'artist'>"
def test_all(self, client): SongFactory(name='a', artist='artist_a').tofile() SongFactory(name='b', artist='artist_a').tofile() SongFactory(name='c', artist='artist_a').tofile() SongFactory(name='d', artist='artist_b').tofile() assert len(Artist.all()) == 2
def test_artist_one_song(client): SongFactory(name='name_a').tofile() url = url_for('main.artist', slug='artist') resp = client.get(url) assert resp.status_code == 302 assert resp.location == url_for('main.song', slug='name_a')
def test_artist_404(client): SongFactory(name='name_a').tofile() url = url_for('main.artist', slug='asdf') resp = client.get(url) assert resp.status_code == 404
def db(): song1 = SongFactory(name='name_a', body='D#') song2 = SongFactory(name='name_b', body='Eb') song1.tofile() song2.tofile()