-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: itunes property track name (#12)
* fix bug with itunes tag trackname and add additional tests * chore: bump version * docs: fix docstring error within pretty_list_of_basemodel_printer * chore: add show_source for mkdocs site * fix: remove deprecated warn() calls in YTDLP logger
- Loading branch information
Showing
15 changed files
with
261 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version = "0.0.7" | ||
version = "0.0.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,115 @@ | ||
import pytest | ||
import os, sys, shutil | ||
from pydantic import BaseModel | ||
|
||
from songbirdcore import common | ||
|
||
|
||
@pytest.fixture | ||
def create_test_folder(): | ||
tests_data_folder = os.path.join(sys.path[0], "tests-output") | ||
if not os.path.exists(tests_data_folder): | ||
os.mkdir(tests_data_folder) | ||
yield tests_data_folder | ||
# test cleanup | ||
shutil.rmtree(tests_data_folder) | ||
|
||
|
||
def test_load_data(): | ||
toml_path = os.path.join(sys.path[0], "..", "..", "pyproject.toml") | ||
data = common.load_toml(toml_path) | ||
assert data is not None | ||
|
||
|
||
def test_set_logger_config_globally(): | ||
try: | ||
common.set_logger_config_globally() | ||
except Exception as e: | ||
pytest.fail(f"Unexpected exception {e}!") | ||
|
||
|
||
def test_name_plate(): | ||
try: | ||
common.name_plate(entries=["foo"]) | ||
except Exception as e: | ||
pytest.fail(f"Unexpected exception {e}!") | ||
|
||
|
||
@pytest.fixture() | ||
def create_dummy_file(create_test_folder): | ||
fname = os.path.join(create_test_folder, "dummy.txt") | ||
|
||
with open(fname, "w") as f: | ||
f.write("hello") | ||
yield fname | ||
|
||
|
||
def fname_duper(create_dummy_file): | ||
|
||
fname = common.fname_duper(fname=create_dummy_file, limit=2, count=1, dup_key="dup") | ||
|
||
assert fname is not None | ||
|
||
|
||
def test_fname_duper_fails(create_dummy_file): | ||
fname = common.fname_duper(fname=create_dummy_file, limit=1, count=1, dup_key="dup") | ||
|
||
assert fname is None | ||
|
||
|
||
def test_remove_illegal_characters(): | ||
"""test remove illegal character""" | ||
try: | ||
result = common.remove_illegal_characters("\\\"/*?<>|':") | ||
except Exception as e: | ||
pytest.fail(f"Unexpected exception {e}!") | ||
|
||
assert result == "" | ||
|
||
|
||
def test_find_file(create_dummy_file): | ||
"""test function for finding a file""" | ||
result = common.find_file( | ||
path=os.path.dirname(create_dummy_file), | ||
filename=os.path.basename(create_dummy_file), | ||
) | ||
|
||
assert len(result) > 0 | ||
|
||
|
||
def test_pretty_list_of_basemodel_printer(capsys): | ||
"""test function runs without exception""" | ||
|
||
class Model(BaseModel): | ||
foo: str = "bar" | ||
|
||
try: | ||
common.pretty_list_of_basemodel_printer(list_of_models=[Model()]) | ||
except Exception as e: | ||
pytest.fail(f"Unexpected exception {e}!") | ||
|
||
|
||
def test_pretty_list_of_baseModel_printer(capsys): | ||
"""test ignore_keys functionality""" | ||
|
||
class Model(BaseModel): | ||
foo: str = "bar" | ||
ignore_me: str = "ignore_me" | ||
|
||
try: | ||
common.pretty_list_of_basemodel_printer( | ||
list_of_models=[Model()], ignore_keys=["ignore_me"] | ||
) | ||
except Exception as e: | ||
pytest.fail(f"Unexpected exception {e}!") | ||
|
||
captured = capsys.readouterr() | ||
assert "ignore_me" not in captured.out | ||
|
||
|
||
def tests_pretty_lst_printer(): | ||
"""test function runs without exception""" | ||
try: | ||
common.pretty_lst_printer(["hi", "there"]) | ||
except Exception as e: | ||
pytest.fail(f"Unexpected exception: {e}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import pytest | ||
|
||
from typing import List, Union | ||
import shutil | ||
import os, sys | ||
|
||
from songbirdcore import itunes | ||
from songbirdcore.models import modes, itunes_api | ||
from test_common import create_test_folder | ||
|
||
RESOURCES_FOLDER = "resources" | ||
|
||
|
||
@pytest.fixture() | ||
def query_api() -> ( | ||
List[Union[itunes_api.ItunesApiSongModel, itunes_api.ItunesApiAlbumKeys]] | ||
): | ||
"""pytest fixture that queries the itunes search | ||
api for songs. | ||
Yields: | ||
List[Union[itunes_api.ItunesApiSongModel, itunes_api.ItunesApiAlbumKeys]]: a list of songs that match the album | ||
""" | ||
results = itunes.query_api( | ||
search_variable="jolene", limit=20, mode=modes.Modes.SONG, lookup=False | ||
) | ||
yield results | ||
|
||
|
||
@pytest.fixture() | ||
def query_api_album() -> ( | ||
List[Union[itunes_api.ItunesApiSongModel, itunes_api.ItunesApiAlbumKeys]] | ||
): | ||
"""pytest fixture that queries the itunes | ||
search api for an album, and returns | ||
the songs in that album | ||
Yields: | ||
List[Union[itunes_api.ItunesApiSongModel, itunes_api.ItunesApiAlbumKeys]]: the list of song properties | ||
""" | ||
album_results = itunes.query_api( | ||
search_variable="jolene", limit=20, mode=modes.Modes.ALBUM, lookup=False | ||
) | ||
# select first result by default | ||
result = album_results[0] | ||
song_results = itunes.query_api( | ||
search_variable=result.collectionId, | ||
limit=result.trackCount, | ||
mode=modes.Modes.SONG, | ||
lookup=True, | ||
) | ||
|
||
yield song_results | ||
|
||
|
||
def test_query_api(query_api): | ||
assert len(query_api) > 0 | ||
|
||
|
||
def test_query_api_album(query_api_album): | ||
assert len(query_api_album) > 0 | ||
|
||
|
||
def test_m4a_tagger(create_test_folder, query_api): | ||
"""test m4a tagging function executes | ||
successfully | ||
""" | ||
input_fpath = os.path.join(sys.path[0], RESOURCES_FOLDER, "empty.m4a") | ||
output_fpath = os.path.join(create_test_folder, "empty.m4a") | ||
shutil.copy(input_fpath, output_fpath) | ||
# query api, get the first result | ||
tags = query_api[0] | ||
result = itunes.m4a_tagger(file_path=output_fpath, song_tag_data=tags) | ||
|
||
assert result == True | ||
|
||
|
||
def test_mp3_tagger(create_test_folder, query_api): | ||
"""test mp3 tagging function executes successfully""" | ||
input_fpath = os.path.join(sys.path[0], RESOURCES_FOLDER, "empty.mp3") | ||
output_fpath = os.path.join(create_test_folder, "empty.mp3") | ||
shutil.copy(input_fpath, output_fpath) | ||
# query api, get the first result | ||
tags = query_api[0] | ||
result = itunes.mp3ID3Tagger(mp3_path=output_fpath, song_tag_data=tags) | ||
|
||
assert result == True | ||
|
||
|
||
@pytest.fixture() | ||
def get_itunes_lib_path(): | ||
return os.path.join(sys.path[0], RESOURCES_FOLDER, "mock-itunes-lib") | ||
|
||
|
||
def test_itunes_lib_search_default(get_itunes_lib_path): | ||
"""test itunes lib search functionality using mock itunes library""" | ||
results = itunes.itunes_lib_search( | ||
itunes_lib_path=get_itunes_lib_path, | ||
search_parameters="empty", | ||
album_properties=None, | ||
) | ||
assert len(results) > 0 | ||
|
||
|
||
def test_itunes_lib_search_with_props(query_api_album, get_itunes_lib_path): | ||
"""test itunes lib search enhanced with album properties""" | ||
props = query_api_album[0] | ||
results = itunes.itunes_lib_search( | ||
itunes_lib_path=get_itunes_lib_path, | ||
search_parameters="jolene", | ||
album_properties=props, | ||
) | ||
assert len(results) > 0 | ||
|
||
|
||
def test_artwork_searcher(query_api): | ||
"""test getting artwork url given song properties""" | ||
response = itunes.artwork_searcher(url=query_api[0].artworkUrl100) | ||
assert response.status_code == 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import pytest | ||
from songbirdcore import web | ||
|
||
|
||
class TestSimpleSession: | ||
def setup_test(self): | ||
# self.session = web.SimpleSession("youtube", root_url=youtube_home_url, headers=headers) | ||
pass | ||
@pytest.fixture() | ||
def get_youtube_session(): | ||
return web.SimpleSession("youtube", root_url="https://www.youtube.com") | ||
|
||
def test_get_form_inputs(self): | ||
pass | ||
|
||
def test_enter_search_form(self): | ||
pass | ||
def test_enter_search_form(get_youtube_session: str): | ||
"""test entering youtube's main search from""" | ||
session = get_youtube_session | ||
response = session.enter_search_form( | ||
search_url="https://www.youtube.com/results", | ||
payload={"search_query": "billy joel"}, | ||
) | ||
assert response is not None and response.status_code == 200 |