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
|
||||
"""
|
||||
|
||||
with db.Session() as session:
|
||||
_ = Playdates(session, track_id)
|
||||
_ = Playdates(session, track_id, when)
|
||||
|
||||
|
||||
def playdates_between_dates(
|
||||
|
||||
@ -153,7 +153,7 @@ class NoteColours(dbtables.NoteColoursTable):
|
||||
|
||||
class Playdates(dbtables.PlaydatesTable):
|
||||
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:
|
||||
"""Record that track was played"""
|
||||
|
||||
|
||||
@ -10,12 +10,12 @@ import unittest
|
||||
# App imports
|
||||
from app.models import (
|
||||
db,
|
||||
Playdates,
|
||||
Tracks,
|
||||
)
|
||||
from classes import (
|
||||
Filter,
|
||||
)
|
||||
import ds
|
||||
|
||||
|
||||
class MyTestCase(unittest.TestCase):
|
||||
@ -25,10 +25,8 @@ class MyTestCase(unittest.TestCase):
|
||||
|
||||
db.create_all()
|
||||
|
||||
with db.Session() as session:
|
||||
# Create some track entries
|
||||
_ = Tracks(**dict(
|
||||
session=session,
|
||||
track1_meta = dict(
|
||||
artist="a",
|
||||
bitrate=0,
|
||||
duration=100,
|
||||
@ -37,9 +35,9 @@ class MyTestCase(unittest.TestCase):
|
||||
silence_at=0,
|
||||
start_gap=0,
|
||||
title="abc"
|
||||
))
|
||||
track2 = Tracks(**dict(
|
||||
session=session,
|
||||
)
|
||||
_ = ds.track_create(track1_meta)
|
||||
track2_meta = dict(
|
||||
artist="a",
|
||||
bitrate=0,
|
||||
duration=100,
|
||||
@ -48,12 +46,13 @@ class MyTestCase(unittest.TestCase):
|
||||
silence_at=0,
|
||||
start_gap=0,
|
||||
title="xyz"
|
||||
))
|
||||
track2_id = track2.id
|
||||
)
|
||||
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)
|
||||
_ = Playdates(session, track2_id, when=just_over_a_year_ago)
|
||||
ds.playdates_update(track2.track_id, when=just_over_a_year_ago)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
@ -76,8 +75,7 @@ class MyTestCase(unittest.TestCase):
|
||||
|
||||
filter = Filter(path="alpha", last_played_comparator="never")
|
||||
|
||||
with db.Session() as session:
|
||||
results = Tracks.get_filtered_tracks(session, filter)
|
||||
results = ds.tracks_filtered(filter)
|
||||
assert len(results) == 1
|
||||
assert 'alpha' in results[0].path
|
||||
|
||||
@ -86,8 +84,7 @@ class MyTestCase(unittest.TestCase):
|
||||
|
||||
filter = Filter(path="xray", last_played_comparator="never")
|
||||
|
||||
with db.Session() as session:
|
||||
results = Tracks.get_filtered_tracks(session, filter)
|
||||
results = ds.tracks_filtered(filter)
|
||||
assert len(results) == 0
|
||||
|
||||
def test_played_over_a_year_ago(self):
|
||||
@ -95,8 +92,7 @@ class MyTestCase(unittest.TestCase):
|
||||
|
||||
filter = Filter(last_played_unit="years", last_played_number=1)
|
||||
|
||||
with db.Session() as session:
|
||||
results = Tracks.get_filtered_tracks(session, filter)
|
||||
results = ds.tracks_filtered(filter)
|
||||
assert len(results) == 1
|
||||
assert 'zulu' in results[0].path
|
||||
|
||||
@ -105,8 +101,7 @@ class MyTestCase(unittest.TestCase):
|
||||
|
||||
filter = Filter(last_played_unit="years", last_played_number=2)
|
||||
|
||||
with db.Session() as session:
|
||||
results = Tracks.get_filtered_tracks(session, filter)
|
||||
results = ds.tracks_filtered(filter)
|
||||
assert len(results) == 0
|
||||
|
||||
def test_never_played(self):
|
||||
@ -114,8 +109,7 @@ class MyTestCase(unittest.TestCase):
|
||||
|
||||
filter = Filter(last_played_comparator="never")
|
||||
|
||||
with db.Session() as session:
|
||||
results = Tracks.get_filtered_tracks(session, filter)
|
||||
results = ds.tracks_filtered(filter)
|
||||
assert len(results) == 1
|
||||
assert 'alpha' in results[0].path
|
||||
|
||||
@ -124,7 +118,6 @@ class MyTestCase(unittest.TestCase):
|
||||
|
||||
filter = Filter(last_played_comparator="Any time")
|
||||
|
||||
with db.Session() as session:
|
||||
results = Tracks.get_filtered_tracks(session, filter)
|
||||
results = ds.tracks_filtered(filter)
|
||||
assert len(results) == 1
|
||||
assert 'zulu' in results[0].path
|
||||
|
||||
Loading…
Reference in New Issue
Block a user