All test_queries tests pass
This commit is contained in:
parent
a8791f925d
commit
d596792375
@ -1051,13 +1051,13 @@ def playdates_get_last(track_id: int, limit: int = 5) -> str:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def playdates_update(track_id: int) -> None:
|
def playdates_update(track_id: int, when: dt.datetime | None = None) -> None:
|
||||||
"""
|
"""
|
||||||
Update playdates for passed track
|
Update playdates for passed track
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with db.Session() as session:
|
with db.Session() as session:
|
||||||
_ = Playdates(session, track_id)
|
_ = Playdates(session, track_id, when)
|
||||||
|
|
||||||
|
|
||||||
def playdates_between_dates(
|
def playdates_between_dates(
|
||||||
|
|||||||
@ -153,7 +153,7 @@ class NoteColours(dbtables.NoteColoursTable):
|
|||||||
|
|
||||||
class Playdates(dbtables.PlaydatesTable):
|
class Playdates(dbtables.PlaydatesTable):
|
||||||
def __init__(
|
def __init__(
|
||||||
self, session: Session, track_id: int, when: Optional[dt.datetime] = None
|
self, session: Session, track_id: int, when: dt.datetime | None = None
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Record that track was played"""
|
"""Record that track was played"""
|
||||||
|
|
||||||
|
|||||||
@ -10,12 +10,12 @@ import unittest
|
|||||||
# App imports
|
# App imports
|
||||||
from app.models import (
|
from app.models import (
|
||||||
db,
|
db,
|
||||||
Playdates,
|
|
||||||
Tracks,
|
Tracks,
|
||||||
)
|
)
|
||||||
from classes import (
|
from classes import (
|
||||||
Filter,
|
Filter,
|
||||||
)
|
)
|
||||||
|
import ds
|
||||||
|
|
||||||
|
|
||||||
class MyTestCase(unittest.TestCase):
|
class MyTestCase(unittest.TestCase):
|
||||||
@ -25,35 +25,34 @@ class MyTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
with db.Session() as session:
|
# Create some track entries
|
||||||
# Create some track entries
|
track1_meta = dict(
|
||||||
_ = Tracks(**dict(
|
artist="a",
|
||||||
session=session,
|
bitrate=0,
|
||||||
artist="a",
|
duration=100,
|
||||||
bitrate=0,
|
fade_at=0,
|
||||||
duration=100,
|
path="/alpha/bravo/charlie",
|
||||||
fade_at=0,
|
silence_at=0,
|
||||||
path="/alpha/bravo/charlie",
|
start_gap=0,
|
||||||
silence_at=0,
|
title="abc"
|
||||||
start_gap=0,
|
)
|
||||||
title="abc"
|
_ = ds.track_create(track1_meta)
|
||||||
))
|
track2_meta = dict(
|
||||||
track2 = Tracks(**dict(
|
artist="a",
|
||||||
session=session,
|
bitrate=0,
|
||||||
artist="a",
|
duration=100,
|
||||||
bitrate=0,
|
fade_at=0,
|
||||||
duration=100,
|
path="/xray/yankee/zulu",
|
||||||
fade_at=0,
|
silence_at=0,
|
||||||
path="/xray/yankee/zulu",
|
start_gap=0,
|
||||||
silence_at=0,
|
title="xyz"
|
||||||
start_gap=0,
|
)
|
||||||
title="xyz"
|
track2 = ds.track_create(track2_meta)
|
||||||
))
|
|
||||||
track2_id = track2.id
|
# Add playdates
|
||||||
# Add playdates
|
# Track 2 played just over a year ago
|
||||||
# Track 2 played just over a year ago
|
just_over_a_year_ago = dt.datetime.now() - dt.timedelta(days=367)
|
||||||
just_over_a_year_ago = dt.datetime.now() - dt.timedelta(days=367)
|
ds.playdates_update(track2.track_id, when=just_over_a_year_ago)
|
||||||
_ = Playdates(session, track2_id, when=just_over_a_year_ago)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
@ -76,55 +75,49 @@ class MyTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
filter = Filter(path="alpha", last_played_comparator="never")
|
filter = Filter(path="alpha", last_played_comparator="never")
|
||||||
|
|
||||||
with db.Session() as session:
|
results = ds.tracks_filtered(filter)
|
||||||
results = Tracks.get_filtered_tracks(session, filter)
|
assert len(results) == 1
|
||||||
assert len(results) == 1
|
assert 'alpha' in results[0].path
|
||||||
assert 'alpha' in results[0].path
|
|
||||||
|
|
||||||
def test_search_path_2(self):
|
def test_search_path_2(self):
|
||||||
"""Search for unplayed track that doesn't exist"""
|
"""Search for unplayed track that doesn't exist"""
|
||||||
|
|
||||||
filter = Filter(path="xray", last_played_comparator="never")
|
filter = Filter(path="xray", last_played_comparator="never")
|
||||||
|
|
||||||
with db.Session() as session:
|
results = ds.tracks_filtered(filter)
|
||||||
results = Tracks.get_filtered_tracks(session, filter)
|
assert len(results) == 0
|
||||||
assert len(results) == 0
|
|
||||||
|
|
||||||
def test_played_over_a_year_ago(self):
|
def test_played_over_a_year_ago(self):
|
||||||
"""Search for tracks played over a year ago"""
|
"""Search for tracks played over a year ago"""
|
||||||
|
|
||||||
filter = Filter(last_played_unit="years", last_played_number=1)
|
filter = Filter(last_played_unit="years", last_played_number=1)
|
||||||
|
|
||||||
with db.Session() as session:
|
results = ds.tracks_filtered(filter)
|
||||||
results = Tracks.get_filtered_tracks(session, filter)
|
assert len(results) == 1
|
||||||
assert len(results) == 1
|
assert 'zulu' in results[0].path
|
||||||
assert 'zulu' in results[0].path
|
|
||||||
|
|
||||||
def test_played_over_two_years_ago(self):
|
def test_played_over_two_years_ago(self):
|
||||||
"""Search for tracks played over 2 years ago"""
|
"""Search for tracks played over 2 years ago"""
|
||||||
|
|
||||||
filter = Filter(last_played_unit="years", last_played_number=2)
|
filter = Filter(last_played_unit="years", last_played_number=2)
|
||||||
|
|
||||||
with db.Session() as session:
|
results = ds.tracks_filtered(filter)
|
||||||
results = Tracks.get_filtered_tracks(session, filter)
|
assert len(results) == 0
|
||||||
assert len(results) == 0
|
|
||||||
|
|
||||||
def test_never_played(self):
|
def test_never_played(self):
|
||||||
"""Search for tracks never played"""
|
"""Search for tracks never played"""
|
||||||
|
|
||||||
filter = Filter(last_played_comparator="never")
|
filter = Filter(last_played_comparator="never")
|
||||||
|
|
||||||
with db.Session() as session:
|
results = ds.tracks_filtered(filter)
|
||||||
results = Tracks.get_filtered_tracks(session, filter)
|
assert len(results) == 1
|
||||||
assert len(results) == 1
|
assert 'alpha' in results[0].path
|
||||||
assert 'alpha' in results[0].path
|
|
||||||
|
|
||||||
def test_played_anytime(self):
|
def test_played_anytime(self):
|
||||||
"""Search for tracks played over a year ago"""
|
"""Search for tracks played over a year ago"""
|
||||||
|
|
||||||
filter = Filter(last_played_comparator="Any time")
|
filter = Filter(last_played_comparator="Any time")
|
||||||
|
|
||||||
with db.Session() as session:
|
results = ds.tracks_filtered(filter)
|
||||||
results = Tracks.get_filtered_tracks(session, filter)
|
assert len(results) == 1
|
||||||
assert len(results) == 1
|
assert 'zulu' in results[0].path
|
||||||
assert 'zulu' in results[0].path
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user