120 lines
2.9 KiB
Python
120 lines
2.9 KiB
Python
# Standard library imports
|
|
import datetime as dt
|
|
import unittest
|
|
|
|
# PyQt imports
|
|
|
|
|
|
# Third party imports
|
|
|
|
# App imports
|
|
from classes import (
|
|
Filter,
|
|
)
|
|
import ds
|
|
|
|
|
|
class MyTestCase(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
"""Runs once before any test in this class"""
|
|
|
|
ds.db.create_all()
|
|
|
|
# Create some track entries
|
|
track1_meta = dict(
|
|
artist="a",
|
|
bitrate=0,
|
|
duration=100,
|
|
fade_at=0,
|
|
path="/alpha/bravo/charlie",
|
|
silence_at=0,
|
|
start_gap=0,
|
|
title="abc",
|
|
)
|
|
_ = ds.track_create(track1_meta)
|
|
track2_meta = dict(
|
|
artist="a",
|
|
bitrate=0,
|
|
duration=100,
|
|
fade_at=0,
|
|
path="/xray/yankee/zulu",
|
|
silence_at=0,
|
|
start_gap=0,
|
|
title="xyz",
|
|
)
|
|
track2 = ds.track_create(track2_meta)
|
|
|
|
# Add playdates
|
|
# Track 2 played just over a year ago
|
|
just_over_a_year_ago = dt.datetime.now() - dt.timedelta(days=367)
|
|
ds.playdates_update(track2.track_id, when=just_over_a_year_ago)
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
"""Runs once after all tests"""
|
|
|
|
ds.db.drop_all()
|
|
|
|
def setUp(self):
|
|
"""Runs before each test"""
|
|
|
|
pass
|
|
|
|
def tearDown(self):
|
|
"""Runs after each test"""
|
|
|
|
pass
|
|
|
|
def test_search_path_1(self):
|
|
"""Search for unplayed track"""
|
|
|
|
filter = Filter(path="alpha", last_played_comparator="never")
|
|
|
|
results = ds.tracks_filtered(filter)
|
|
assert len(results) == 1
|
|
assert "alpha" in results[0].path
|
|
|
|
def test_search_path_2(self):
|
|
"""Search for unplayed track that doesn't exist"""
|
|
|
|
filter = Filter(path="xray", last_played_comparator="never")
|
|
|
|
results = ds.tracks_filtered(filter)
|
|
assert len(results) == 0
|
|
|
|
def test_played_over_a_year_ago(self):
|
|
"""Search for tracks played over a year ago"""
|
|
|
|
filter = Filter(last_played_unit="years", last_played_number=1)
|
|
|
|
results = ds.tracks_filtered(filter)
|
|
assert len(results) == 1
|
|
assert "zulu" in results[0].path
|
|
|
|
def test_played_over_two_years_ago(self):
|
|
"""Search for tracks played over 2 years ago"""
|
|
|
|
filter = Filter(last_played_unit="years", last_played_number=2)
|
|
|
|
results = ds.tracks_filtered(filter)
|
|
assert len(results) == 0
|
|
|
|
def test_never_played(self):
|
|
"""Search for tracks never played"""
|
|
|
|
filter = Filter(last_played_comparator="never")
|
|
|
|
results = ds.tracks_filtered(filter)
|
|
assert len(results) == 1
|
|
assert "alpha" in results[0].path
|
|
|
|
def test_played_anytime(self):
|
|
"""Search for tracks played over a year ago"""
|
|
|
|
filter = Filter(last_played_comparator="Any time")
|
|
|
|
results = ds.tracks_filtered(filter)
|
|
assert len(results) == 1
|
|
assert "zulu" in results[0].path
|