Skip to content

Commit

Permalink
Fix instances where a literal Enum value is needed (#286)
Browse files Browse the repository at this point in the history
e.g. CollectionConfig.platform when writing collection path
  • Loading branch information
a-rich authored Jan 11, 2025
1 parent 672f8b1 commit ddbe9fb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/djtools/sync/sync_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ def download_collection(config: BaseConfig):
config: Configuration object.
"""
logger.info(
f"Downloading {config.sync.import_user}'s {config.collection.platform} collection..."
f"Downloading {config.sync.import_user}'s {config.collection.platform.value} collection..."
)
collection_dir = config.collection.collection_path.parent
src = (
f"{config.sync.bucket_url}/dj/collections/{config.sync.import_user}/"
f"{config.collection.platform}_collection"
f"{config.collection.platform.value}_collection"
)
dst = (
Path(collection_dir)
Expand Down Expand Up @@ -160,11 +160,11 @@ def upload_collection(config: BaseConfig):
config: Configuration object.
"""
logger.info(
f"Uploading {config.sync.user}'s {config.collection.platform} collection..."
f"Uploading {config.sync.user}'s {config.collection.platform.value} collection..."
)
dst = (
f"{config.sync.bucket_url}/dj/collections/{config.sync.user}/"
f"{config.collection.platform}_collection"
f"{config.collection.platform.value}_collection"
)
cmd = [
"aws",
Expand Down
5 changes: 3 additions & 2 deletions src/djtools/utils/normalize_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ def normalize(config: BaseConfig):
audio, headroom=config.utils.audio_headroom
)
audio.export(
track.parent / f"{track.stem}.{config.utils.audio_format}",
track.parent
/ f"{track.stem}.{config.utils.audio_format.value}",
tags=tags,
bitrate=f"{config.utils.audio_bitrate}k",
format=config.utils.audio_format,
format=config.utils.audio_format.value,
)
continue
2 changes: 1 addition & 1 deletion src/djtools/utils/url_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def url_download(config: BaseConfig):
"postprocessors": [
{
"key": "FFmpegExtractAudio",
"preferredcodec": config.utils.audio_format,
"preferredcodec": config.utils.audio_format.value,
"preferredquality": config.utils.audio_bitrate,
}
],
Expand Down
13 changes: 7 additions & 6 deletions tests/sync/test_sync_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest

from djtools.collection.config import RegisteredPlatforms
from djtools.sync.sync_operations import (
download_collection,
download_music,
Expand Down Expand Up @@ -106,7 +107,7 @@ def test_download_collection(
config.sync.user = test_user
config.sync.import_user = import_user
config.collection.collection_path = rekordbox_xml
config.collection.platform = "rekordbox"
config.collection.platform = RegisteredPlatforms.REKORDBOX
new_xml = rekordbox_xml.parent / f"{import_user}_rekordbox.xml"
new_xml.write_text(
rekordbox_xml.read_text(encoding="utf-8"), encoding="utf-8"
Expand All @@ -118,7 +119,7 @@ def test_download_collection(
"s3",
"cp",
f"{TEST_BUCKET}/dj/collections/{import_user}/"
f"{config.collection.platform}_collection",
f"{config.collection.platform.value}_collection",
# NOTE(a-rich): since we could be passing a `rekordbox_xml` formatted
# as a WindowsPath, the comparison needs to be made with `str(new_xml)`
# (rather than `new_xml.as_posix()`).
Expand All @@ -133,7 +134,7 @@ def test_download_collection(
download_collection(config)
mock_popen.assert_called_with(cmd)
assert caplog.records[0].message == (
f"Downloading {config.sync.import_user}'s {config.collection.platform} collection..."
f"Downloading {config.sync.import_user}'s {config.collection.platform.value} collection..."
)
assert caplog.records[1].message == " ".join(cmd)
if not user_is_import_user:
Expand Down Expand Up @@ -190,13 +191,13 @@ def test_upload_collection(
config.sync.bucket_url = TEST_BUCKET
config.sync.user = user
config.collection.collection_path = rekordbox_xml
config.collection.platform = "rekordbox"
config.collection.platform = RegisteredPlatforms.REKORDBOX
cmd = [
"aws",
"s3",
"cp",
config.collection.collection_path.as_posix(),
f"{TEST_BUCKET}/dj/collections/{user}/{config.collection.platform}_collection",
f"{TEST_BUCKET}/dj/collections/{user}/{config.collection.platform.value}_collection",
]
if collection_is_dir:
cmd.append("--recursive")
Expand All @@ -208,7 +209,7 @@ def test_upload_collection(
):
upload_collection(config)
assert caplog.records[0].message == (
f"Uploading {user}'s {config.collection.platform} collection..."
f"Uploading {user}'s {config.collection.platform.value} collection..."
)
assert caplog.records[1].message == " ".join(cmd)
mock_popen.assert_called_with(cmd)

0 comments on commit ddbe9fb

Please sign in to comment.