|
@@ -34,44 +34,19 @@ def test_init(path):
|
|
|
symuid.Track(path)
|
|
|
|
|
|
|
|
|
-@pytest.mark.parametrize(('player', 'library_id', 'register_dt', 'count'), [
|
|
|
- ('pytest', 'lib', dt.datetime(2018, 9, 26, 21, 16, 20, tzinfo=dt.timezone.utc), 7),
|
|
|
+@pytest.mark.parametrize(('pc'), [
|
|
|
+ symuid.PlayCount('pytest', 'lib', utc_dt(), 7),
|
|
|
])
|
|
|
-def test_register_play_count(empty_id3_track, player, library_id, register_dt, count):
|
|
|
- empty_id3_track.register_play_count(
|
|
|
- player=player,
|
|
|
- library_id=library_id,
|
|
|
- register_dt=register_dt,
|
|
|
- play_count=count,
|
|
|
- )
|
|
|
- tags = mutagen.File(empty_id3_track.path).tags
|
|
|
- assert len(tags) == 1
|
|
|
- expected_desc = 'symuid:pcnt:{}:{}:{}'.format(
|
|
|
- player, library_id, int(register_dt.timestamp()),
|
|
|
- )
|
|
|
- tag = tags['TXXX:' + expected_desc]
|
|
|
- assert tag.desc == expected_desc
|
|
|
- assert tag.text == [str(count)]
|
|
|
-
|
|
|
-
|
|
|
-@pytest.mark.parametrize(('player', 'library_id', 'register_dt', 'count'), [
|
|
|
- ('pytest', 'lib', utc_dt(), 7),
|
|
|
-])
|
|
|
-def test_register_play_count(empty_id3_track, player, library_id, register_dt, count):
|
|
|
- empty_id3_track.register_play_count(
|
|
|
- player=player,
|
|
|
- library_id=library_id,
|
|
|
- register_dt=register_dt,
|
|
|
- play_count=count,
|
|
|
- )
|
|
|
+def test_register_play_count(empty_id3_track, pc):
|
|
|
+ empty_id3_track.register_play_count(pc)
|
|
|
tags = mutagen.File(empty_id3_track.path).tags
|
|
|
assert len(tags) == 1
|
|
|
expected_desc = 'symuid:pcnt:{}:{}:{}'.format(
|
|
|
- player, library_id, int(register_dt.timestamp()),
|
|
|
+ pc.player, pc.library_id, int(pc.register_dt.timestamp()),
|
|
|
)
|
|
|
tag = tags['TXXX:' + expected_desc]
|
|
|
assert tag.desc == expected_desc
|
|
|
- assert tag.text == [str(count)]
|
|
|
+ assert tag.text == [str(pc.count)]
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(('expected_counts'), [
|
|
@@ -85,12 +60,7 @@ def test_register_play_count(empty_id3_track, player, library_id, register_dt, c
|
|
|
])
|
|
|
def test__get_play_counts_all(empty_id3_track, expected_counts):
|
|
|
for pc in expected_counts:
|
|
|
- empty_id3_track.register_play_count(
|
|
|
- player=pc.player,
|
|
|
- library_id=pc.library_id,
|
|
|
- register_dt=pc.register_dt,
|
|
|
- play_count=pc.count,
|
|
|
- )
|
|
|
+ empty_id3_track.register_play_count(pc)
|
|
|
assert expected_counts == list(empty_id3_track._get_play_counts())
|
|
|
|
|
|
|
|
@@ -100,12 +70,7 @@ def test__get_play_counts_filtered(empty_id3_track):
|
|
|
symuid.PlayCount('a', '1', utc_dt(0), 3),
|
|
|
symuid.PlayCount('b', '2', utc_dt(1), 4)]
|
|
|
for pc in counts:
|
|
|
- empty_id3_track.register_play_count(
|
|
|
- player=pc.player,
|
|
|
- library_id=pc.library_id,
|
|
|
- register_dt=pc.register_dt,
|
|
|
- play_count=pc.count,
|
|
|
- )
|
|
|
+ empty_id3_track.register_play_count(pc)
|
|
|
assert set(empty_id3_track._get_play_counts(player='a')) \
|
|
|
== set(filter(lambda pc: pc.player == 'a', counts))
|
|
|
assert set(empty_id3_track._get_play_counts(player='b')) \
|
|
@@ -123,12 +88,7 @@ def test__get_latest_play_counts(empty_id3_track):
|
|
|
symuid.PlayCount('a', '1', utc_dt(2), 4),
|
|
|
symuid.PlayCount('b', '2', utc_dt(3), 5)]
|
|
|
for pc in counts:
|
|
|
- empty_id3_track.register_play_count(
|
|
|
- player=pc.player,
|
|
|
- library_id=pc.library_id,
|
|
|
- register_dt=pc.register_dt,
|
|
|
- play_count=pc.count,
|
|
|
- )
|
|
|
+ empty_id3_track.register_play_count(pc)
|
|
|
assert set(empty_id3_track._get_latest_play_counts()) \
|
|
|
== set([counts[1], counts[3], counts[4]])
|
|
|
assert set(empty_id3_track._get_latest_play_counts(player='a')) \
|
|
@@ -144,10 +104,5 @@ def test_get_play_count_sum(empty_id3_track):
|
|
|
symuid.PlayCount('a', '1', utc_dt(2), 4),
|
|
|
symuid.PlayCount('b', '2', utc_dt(3), 5)]
|
|
|
for pc in counts:
|
|
|
- empty_id3_track.register_play_count(
|
|
|
- player=pc.player,
|
|
|
- library_id=pc.library_id,
|
|
|
- register_dt=pc.register_dt,
|
|
|
- play_count=pc.count,
|
|
|
- )
|
|
|
+ empty_id3_track.register_play_count(pc)
|
|
|
assert 2 + 4 + 5 == empty_id3_track.get_play_count_sum()
|