142 lines
3.3 KiB
Python
142 lines
3.3 KiB
Python
import time
|
|
|
|
from app.models import (
|
|
NoteColours,
|
|
Notes,
|
|
Playdates,
|
|
Playlists,
|
|
# PlaylistTracks,
|
|
Tracks,
|
|
)
|
|
|
|
|
|
def test_notecolours_get_colour(session):
|
|
"""Create a colour record and retrieve all colours"""
|
|
|
|
rec = NoteColours()
|
|
rec.colour = "ffffff"
|
|
rec.substring = "substring"
|
|
rec.is_regex = False
|
|
rec.is_casesensitive = True
|
|
session.add(rec)
|
|
session.commit()
|
|
|
|
records = NoteColours.get_all(session)
|
|
assert len(records) == 1
|
|
record = records[0]
|
|
assert record.colour == "ffffff"
|
|
|
|
|
|
def test_notecolours_get_by_id(session):
|
|
"""Create a colour record and retrieve it by id"""
|
|
|
|
rec = NoteColours()
|
|
rec.colour = "abcdef"
|
|
rec.substring = "substring"
|
|
rec.is_regex = False
|
|
rec.is_casesensitive = True
|
|
session.add(rec)
|
|
session.commit()
|
|
record_id = rec.id
|
|
|
|
record = NoteColours.get_by_id(session, record_id)
|
|
assert record.colour == "abcdef"
|
|
|
|
|
|
def test_playdates_add_playdate(session):
|
|
"""Test playdate and last_played retrieval"""
|
|
|
|
# We need a track
|
|
track_path = "/a/b/c"
|
|
track = Tracks.get_or_create(session, track_path)
|
|
# Need to commit because track record is updated in Playdates.add_playdate()
|
|
session.commit()
|
|
|
|
playdate = Playdates.add_playdate(session, track)
|
|
|
|
last_played = Playdates.last_played(session, track.id)
|
|
|
|
assert playdate.lastplayed == last_played
|
|
|
|
|
|
def test_playdates_remove_track(session):
|
|
"""Test removing a track from a playdate"""
|
|
|
|
# We need a track
|
|
track_path = "/a/b/c"
|
|
track = Tracks.get_or_create(session, track_path)
|
|
# Need to commit because track record is updated in Playdates.add_playdate()
|
|
session.commit()
|
|
|
|
Playdates.add_playdate(session, track)
|
|
Playdates.remove_track(session, track.id)
|
|
|
|
last_played = Playdates.last_played(session, track.id)
|
|
|
|
assert last_played is None
|
|
|
|
|
|
def test_playlist_close(session):
|
|
"""Test closing a playlist"""
|
|
|
|
playlist = Playlists()
|
|
playlist.name = "Test playlist one"
|
|
session.add(playlist)
|
|
session.commit()
|
|
|
|
playlist2 = Playlists()
|
|
playlist2.name = "Test playlist two"
|
|
session.add(playlist2)
|
|
session.commit()
|
|
|
|
apl = Playlists.get_all(session)
|
|
assert len(apl) == 2
|
|
|
|
cpl = Playlists.get_closed(session)
|
|
assert len(cpl) == 0
|
|
|
|
playlist2.close(session)
|
|
|
|
cpl = Playlists.get_closed(session)
|
|
assert len(cpl) == 1
|
|
|
|
|
|
def test_playlist_get_last_user(session):
|
|
"""Test get_last_used function"""
|
|
|
|
playlist1 = Playlists()
|
|
playlist1.name = "Test playlist one"
|
|
session.add(playlist1)
|
|
session.commit()
|
|
|
|
playlist2 = Playlists()
|
|
playlist2.name = "Test playlist two"
|
|
session.add(playlist2)
|
|
session.commit()
|
|
|
|
playlist3 = Playlists()
|
|
playlist3.name = "Test playlist three"
|
|
session.add(playlist3)
|
|
session.commit()
|
|
|
|
apl = Playlists.get_all(session)
|
|
assert len(apl) == 3
|
|
|
|
playlist1.mark_open(session)
|
|
playlist2.close(session)
|
|
time.sleep(1)
|
|
playlist3.mark_open(session)
|
|
|
|
last_used = Playlists.get_open(session)
|
|
assert len(last_used) == 2
|
|
assert last_used[0].name == "Test playlist three"
|
|
|
|
|
|
def test_playlist_new(session):
|
|
"""Test new function"""
|
|
|
|
plname = "This is a test name"
|
|
p = Playlists(session, plname)
|
|
n = Playlists.get_by_id(session, p.id)
|
|
assert p.name == n.name
|