299 lines
10 KiB
Python
299 lines
10 KiB
Python
# Standard library imports
|
|
import unittest
|
|
|
|
# PyQt imports
|
|
|
|
# Third party imports
|
|
|
|
# App imports
|
|
from app import playlistmodel
|
|
from app import ds
|
|
from app.models import db
|
|
from classes import PlaylistDTO
|
|
from helpers import get_all_track_metadata
|
|
from playlistmodel import PlaylistModel
|
|
|
|
|
|
class MyTestCase(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
"""Runs once before any test in this class"""
|
|
|
|
cls.isa_path = "testdata/isa.mp3"
|
|
cls.isa_title = "I'm So Afraid"
|
|
cls.isa_artist = "Fleetwood Mac"
|
|
cls.mom_path = "testdata/mom.mp3"
|
|
cls.mom_title = "Man of Mystery"
|
|
cls.mom_artist = "The Shadows"
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
"""Runs once after all tests"""
|
|
|
|
pass
|
|
|
|
def setUp(self):
|
|
"""Runs before each test"""
|
|
|
|
db.create_all()
|
|
|
|
def playlist_create_and_model(
|
|
self, playlist_name: str
|
|
) -> (PlaylistDTO, PlaylistModel):
|
|
# Create a playlist and model
|
|
playlist = ds.playlist_create(name=playlist_name, template_id=0)
|
|
assert playlist
|
|
model = playlistmodel.PlaylistModel(playlist.playlist_id, is_template=False)
|
|
assert model
|
|
|
|
return (playlist, model)
|
|
|
|
def playlist_create_model_tracks(self, playlist_name: str):
|
|
(playlist, model) = self.playlist_create_and_model(playlist_name)
|
|
# Create tracks
|
|
metadata1 = get_all_track_metadata(self.isa_path)
|
|
self.track1 = ds.track_create(metadata1)
|
|
|
|
metadata2 = get_all_track_metadata(self.mom_path)
|
|
self.track2 = ds.track_create(metadata2)
|
|
|
|
# Add tracks and header to playlist
|
|
self.row0 = ds.playlist_insert_row(
|
|
playlist.playlist_id,
|
|
row_number=0,
|
|
track_id=self.track1.track_id,
|
|
note="track 1",
|
|
)
|
|
self.row1 = ds.playlist_insert_row(
|
|
playlist.playlist_id,
|
|
row_number=1,
|
|
track_id=0,
|
|
note="Header row",
|
|
)
|
|
self.row2 = ds.playlist_insert_row(
|
|
playlist.playlist_id,
|
|
row_number=2,
|
|
track_id=self.track2.track_id,
|
|
note="track 2",
|
|
)
|
|
|
|
def create_rows(
|
|
self, playlist_name: str, number_of_rows: int
|
|
) -> (PlaylistDTO, PlaylistModel):
|
|
(playlist, model) = self.playlist_create_and_model(playlist_name)
|
|
for row_number in range(number_of_rows):
|
|
ds.playlist_insert_row(
|
|
playlist.playlist_id, row_number, None, str(row_number)
|
|
)
|
|
|
|
return (playlist, model)
|
|
|
|
def tearDown(self):
|
|
"""Runs after each test"""
|
|
|
|
db.drop_all()
|
|
|
|
def test_add_track_to_header(self):
|
|
"""Add a track to a header row"""
|
|
|
|
self.playlist_create_model_tracks("my playlist")
|
|
ds.track_add_to_header(self.row1.playlistrow_id, self.track2.track_id)
|
|
result = ds.playlistrow_by_id(self.row1.playlistrow_id)
|
|
assert result.track.track_id == self.track2.track_id
|
|
|
|
def test_track_create(self):
|
|
metadata = get_all_track_metadata(self.isa_path)
|
|
ds.track_create(metadata)
|
|
results = ds.tracks_all()
|
|
assert len(results) == 1
|
|
assert results[0].path == self.isa_path
|
|
|
|
def test_get_track_by_id(self):
|
|
metadata = get_all_track_metadata(self.isa_path)
|
|
dto = ds.track_create(metadata)
|
|
result = ds.track_by_id(dto.track_id)
|
|
assert result.path == self.isa_path
|
|
|
|
def test_get_track_by_artist(self):
|
|
metadata = get_all_track_metadata(self.isa_path)
|
|
_ = ds.track_create(metadata)
|
|
metadata = get_all_track_metadata(self.mom_path)
|
|
_ = ds.track_create(metadata)
|
|
result_isa = ds.tracks_by_artist(self.isa_artist)
|
|
assert len(result_isa) == 1
|
|
assert result_isa[0].artist == self.isa_artist
|
|
result_mom = ds.tracks_by_artist(self.mom_artist)
|
|
assert len(result_mom) == 1
|
|
assert result_mom[0].artist == self.mom_artist
|
|
|
|
def test_get_track_by_title(self):
|
|
metadata_isa = get_all_track_metadata(self.isa_path)
|
|
_ = ds.track_create(metadata_isa)
|
|
metadata_mom = get_all_track_metadata(self.mom_path)
|
|
_ = ds.track_create(metadata_mom)
|
|
result_isa = ds.tracks_by_title(self.isa_title)
|
|
assert len(result_isa) == 1
|
|
assert result_isa[0].title == self.isa_title
|
|
result_mom = ds.tracks_by_title(self.mom_title)
|
|
assert len(result_mom) == 1
|
|
assert result_mom[0].title == self.mom_title
|
|
|
|
def test_tracks_get_all_tracks(self):
|
|
self.playlist_create_model_tracks(playlist_name="test_track_get_all_tracks")
|
|
all_tracks = ds.tracks_all()
|
|
assert len(all_tracks) == 2
|
|
|
|
def test_tracks_by_path(self):
|
|
metadata_isa = get_all_track_metadata(self.isa_path)
|
|
_ = ds.track_create(metadata_isa)
|
|
metadata_mom = get_all_track_metadata(self.mom_path)
|
|
_ = ds.track_create(metadata_mom)
|
|
result_isa = ds.track_by_path(self.isa_path)
|
|
assert result_isa.title == self.isa_title
|
|
result_mom = ds.track_by_path(self.mom_path)
|
|
assert result_mom.title == self.mom_title
|
|
|
|
def test_move_rows_test1(self):
|
|
# move row 3 to row 5
|
|
|
|
number_of_rows = 10
|
|
(playlist, model) = self.create_rows("test_move_rows_test1", number_of_rows)
|
|
|
|
ds.playlist_move_rows([3], playlist.playlist_id, 5)
|
|
|
|
# Check we have all rows and plr_rownums are correct
|
|
new_order = []
|
|
for row in ds.playlistrows_by_playlist(playlist.playlist_id):
|
|
new_order.append(int(row.note))
|
|
assert new_order == [0, 1, 2, 4, 3, 5, 6, 7, 8, 9]
|
|
|
|
def test_move_rows_test2(self):
|
|
# move row 4 to row 3
|
|
|
|
number_of_rows = 10
|
|
(playlist, model) = self.create_rows("test_move_rows_test2", number_of_rows)
|
|
|
|
ds.playlist_move_rows([4], playlist.playlist_id, 3)
|
|
|
|
# Check we have all rows and plr_rownums are correct
|
|
new_order = []
|
|
for row in ds.playlistrows_by_playlist(playlist.playlist_id):
|
|
new_order.append(int(row.note))
|
|
assert new_order == [0, 1, 2, 4, 3, 5, 6, 7, 8, 9]
|
|
|
|
def test_move_rows_test3(self):
|
|
# move row 4 to row 2
|
|
|
|
number_of_rows = 10
|
|
(playlist, model) = self.create_rows("test_move_rows_test3", number_of_rows)
|
|
|
|
ds.playlist_move_rows([4], playlist.playlist_id, 2)
|
|
|
|
# Check we have all rows and plr_rownums are correct
|
|
new_order = []
|
|
for row in ds.playlistrows_by_playlist(playlist.playlist_id):
|
|
new_order.append(int(row.note))
|
|
assert new_order == [0, 1, 4, 2, 3, 5, 6, 7, 8, 9]
|
|
|
|
def test_move_rows_test4(self):
|
|
# move rows [1, 4, 5, 10] → 8
|
|
|
|
number_of_rows = 11
|
|
(playlist, model) = self.create_rows("test_move_rows_test4", number_of_rows)
|
|
|
|
ds.playlist_move_rows([1, 4, 5, 10], playlist.playlist_id, 8)
|
|
|
|
# Check we have all rows and plr_rownums are correct
|
|
new_order = []
|
|
for row in ds.playlistrows_by_playlist(playlist.playlist_id):
|
|
new_order.append(int(row.note))
|
|
assert new_order == [0, 2, 3, 6, 7, 1, 4, 5, 10, 8, 9]
|
|
|
|
def test_move_rows_test5(self):
|
|
# move rows [3, 6] → 5
|
|
|
|
number_of_rows = 11
|
|
(playlist, model) = self.create_rows("test_move_rows_test5", number_of_rows)
|
|
|
|
ds.playlist_move_rows([3, 6], playlist.playlist_id, 5)
|
|
|
|
# Check we have all rows and plr_rownums are correct
|
|
new_order = []
|
|
for row in ds.playlistrows_by_playlist(playlist.playlist_id):
|
|
new_order.append(int(row.note))
|
|
assert new_order == [0, 1, 2, 4, 3, 6, 5, 7, 8, 9, 10]
|
|
|
|
def test_move_rows_test6(self):
|
|
# move rows [3, 5, 6] → 8
|
|
|
|
number_of_rows = 11
|
|
(playlist, model) = self.create_rows("test_move_rows_test6", number_of_rows)
|
|
|
|
ds.playlist_move_rows([3, 5, 6], playlist.playlist_id, 8)
|
|
|
|
# Check we have all rows and plr_rownums are correct
|
|
new_order = []
|
|
for row in ds.playlistrows_by_playlist(playlist.playlist_id):
|
|
new_order.append(int(row.note))
|
|
assert new_order == [0, 1, 2, 4, 7, 3, 5, 6, 8, 9, 10]
|
|
|
|
def test_move_rows_test7(self):
|
|
# move rows [7, 8, 10] → 5
|
|
|
|
number_of_rows = 11
|
|
(playlist, model) = self.create_rows("test_move_rows_test7", number_of_rows)
|
|
|
|
ds.playlist_move_rows([7, 8, 10], playlist.playlist_id, 5)
|
|
|
|
# Check we have all rows and plr_rownums are correct
|
|
new_order = []
|
|
for row in ds.playlistrows_by_playlist(playlist.playlist_id):
|
|
new_order.append(int(row.note))
|
|
assert new_order == [0, 1, 2, 3, 4, 7, 8, 10, 5, 6, 9]
|
|
|
|
def test_move_rows_test8(self):
|
|
# move rows [1, 2, 3] → 0
|
|
# Replicate issue 244
|
|
|
|
number_of_rows = 11
|
|
(playlist, model) = self.create_rows("test_move_rows_test8", number_of_rows)
|
|
|
|
ds.playlist_move_rows([1, 2, 3], playlist.playlist_id, 0)
|
|
|
|
# Check we have all rows and plr_rownums are correct
|
|
new_order = []
|
|
for row in ds.playlistrows_by_playlist(playlist.playlist_id):
|
|
new_order.append(int(row.note))
|
|
assert new_order == [1, 2, 3, 0, 4, 5, 6, 7, 8, 9, 10]
|
|
|
|
def test_move_rows_to_playlist(self):
|
|
number_of_rows = 11
|
|
rows_to_move = [2, 4, 6]
|
|
to_row = 5
|
|
|
|
(playlist_src, model_src) = self.create_rows("src playlist", number_of_rows)
|
|
(playlist_dst, model_dst) = self.create_rows("dst playlist", number_of_rows)
|
|
|
|
ds.playlist_move_rows(
|
|
rows_to_move, playlist_src.playlist_id, to_row, playlist_dst.playlist_id
|
|
)
|
|
|
|
# Check we have all rows and plr_rownums are correct
|
|
new_order_src = []
|
|
for row in ds.playlistrows_by_playlist(playlist_src.playlist_id):
|
|
new_order_src.append(int(row.note))
|
|
assert new_order_src == [0, 1, 3, 5, 7, 8, 9, 10]
|
|
new_order_dst = []
|
|
for row in ds.playlistrows_by_playlist(playlist_dst.playlist_id):
|
|
new_order_dst.append(int(row.note))
|
|
assert new_order_dst == [0, 1, 2, 3, 4, 2, 4, 6, 5, 6, 7, 8, 9, 10]
|
|
|
|
def test_remove_rows(self):
|
|
pass
|
|
|
|
def test_get_playlist_by_id(self):
|
|
pass
|
|
|
|
def test_settings(self):
|
|
pass
|