mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-22 00:45:10 +00:00
refactor(core)!: drop leading underscores from internal definitions
Renames 314 defs and 41 module/class-level constants. Keeps 11 names underscored where the stripped form collides in scope, plus 5.5.0 shims for the three symbols external service repos call.
This commit is contained in:
@@ -18,7 +18,7 @@ class _Response:
|
||||
return self._payload
|
||||
|
||||
|
||||
def _node(
|
||||
def node(
|
||||
imdb_id: str = "tt3581920",
|
||||
text: str = "The Last of Us",
|
||||
year: Optional[int] = 2023,
|
||||
@@ -67,14 +67,14 @@ def test_is_available_without_any_key() -> None:
|
||||
|
||||
|
||||
def test_cache_hit_uses_one_get(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p, session = _provider(monkeypatch, [{"data": {"title": _node()}}])
|
||||
p, session = _provider(monkeypatch, [{"data": {"title": node()}}])
|
||||
result = p.get_by_id("tt3581920", "tv")
|
||||
assert result is not None and result.title == "The Last of Us"
|
||||
assert len(session.gets) == 1 and session.posts == []
|
||||
|
||||
|
||||
def test_persisted_query_miss_falls_back_to_one_post(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p, session = _provider(monkeypatch, [NOT_FOUND, {"data": {"title": _node()}}])
|
||||
p, session = _provider(monkeypatch, [NOT_FOUND, {"data": {"title": node()}}])
|
||||
result = p.get_by_id("tt3581920", "tv")
|
||||
assert result is not None and result.external_ids.imdb_id == "tt3581920"
|
||||
assert len(session.gets) == 1 and len(session.posts) == 1
|
||||
@@ -86,14 +86,14 @@ def test_persisted_query_miss_falls_back_to_one_post(monkeypatch: pytest.MonkeyP
|
||||
|
||||
def test_get_params_carry_no_spaces(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""IMDb's GraphQL gateway decodes "+" literally, so spaced JSON would come back as a 400."""
|
||||
p, session = _provider(monkeypatch, [{"data": {"title": _node()}}])
|
||||
p, session = _provider(monkeypatch, [{"data": {"title": node()}}])
|
||||
p.get_by_id("tt3581920", "tv")
|
||||
assert " " not in session.gets[0]["extensions"]
|
||||
assert " " not in session.gets[0]["variables"]
|
||||
|
||||
|
||||
def test_get_by_id_maps_every_field(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p, _ = _provider(monkeypatch, [{"data": {"title": _node()}}])
|
||||
p, _ = _provider(monkeypatch, [{"data": {"title": node()}}])
|
||||
result = p.get_by_id("tt3581920", "tv")
|
||||
assert result is not None
|
||||
assert (result.title, result.year, result.kind) == ("The Last of Us", 2023, "tv")
|
||||
@@ -105,7 +105,7 @@ def test_get_by_id_maps_every_field(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
@pytest.mark.parametrize("title_type", ["movie", "tvSeries", "videoGame"])
|
||||
def test_caller_kind_wins_over_the_response_title_type(monkeypatch: pytest.MonkeyPatch, title_type: str) -> None:
|
||||
"""kind stays the caller's, so it cannot desync from the tmdb_kind resolve_by_ids seeds."""
|
||||
p, _ = _provider(monkeypatch, [{"data": {"title": _node(title_type=title_type)}}])
|
||||
p, _ = _provider(monkeypatch, [{"data": {"title": node(title_type=title_type)}}])
|
||||
result = p.get_by_id("tt1375666", "tv")
|
||||
assert result is not None and result.kind == "tv"
|
||||
|
||||
@@ -116,12 +116,12 @@ def test_get_by_id_returns_none_on_no_answer(monkeypatch: pytest.MonkeyPatch, pa
|
||||
assert p.get_by_id("tt3581920", "tv") is None
|
||||
|
||||
|
||||
def _edges(*nodes: dict) -> dict:
|
||||
def edges(*nodes: dict) -> dict:
|
||||
return {"data": {"advancedTitleSearch": {"edges": [{"node": {"title": n}} for n in nodes]}}}
|
||||
|
||||
|
||||
def test_search_uses_its_own_operation_and_one_get_on_a_cache_hit(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p, session = _provider(monkeypatch, [_edges(_node())])
|
||||
p, session = _provider(monkeypatch, [edges(node())])
|
||||
result = p.search("The Last of Us", 2023, "tv")
|
||||
assert result is not None and result.external_ids.imdb_id == "tt3581920"
|
||||
assert session.gets[0]["operationName"] == "UnshackleTitleSearch"
|
||||
@@ -129,7 +129,7 @@ def test_search_uses_its_own_operation_and_one_get_on_a_cache_hit(monkeypatch: p
|
||||
|
||||
|
||||
def test_search_query_text_carries_the_constraints(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p, session = _provider(monkeypatch, [NOT_FOUND, _edges(_node())])
|
||||
p, session = _provider(monkeypatch, [NOT_FOUND, edges(node())])
|
||||
p.search("The Last of Us", 2023, "tv")
|
||||
query = session.posts[0]["query"]
|
||||
assert 'searchTerm: "The Last of Us"' in query
|
||||
@@ -138,7 +138,7 @@ def test_search_query_text_carries_the_constraints(monkeypatch: pytest.MonkeyPat
|
||||
|
||||
|
||||
def test_search_omits_the_year_range_when_unknown(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p, session = _provider(monkeypatch, [NOT_FOUND, _edges(_node(title_type="movie"))])
|
||||
p, session = _provider(monkeypatch, [NOT_FOUND, edges(node(title_type="movie"))])
|
||||
p.search("Inception", None, "movie")
|
||||
query = session.posts[0]["query"]
|
||||
assert "releaseDateConstraint" not in query
|
||||
@@ -146,26 +146,26 @@ def test_search_omits_the_year_range_when_unknown(monkeypatch: pytest.MonkeyPatc
|
||||
|
||||
|
||||
def test_search_picks_the_closest_title_not_the_first(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
noise = _node(imdb_id="tt27478132", text="Making of: The Last of Us")
|
||||
exact = _node()
|
||||
p, _ = _provider(monkeypatch, [_edges(noise, exact)])
|
||||
noise = node(imdb_id="tt27478132", text="Making of: The Last of Us")
|
||||
exact = node()
|
||||
p, _ = _provider(monkeypatch, [edges(noise, exact)])
|
||||
result = p.search("The Last of Us", 2023, "tv")
|
||||
assert result is not None and result.external_ids.imdb_id == "tt3581920"
|
||||
|
||||
|
||||
def test_search_rejects_a_title_that_is_not_a_close_match(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p, _ = _provider(monkeypatch, [_edges(_node(imdb_id="tt999", text="Something Else Entirely"))])
|
||||
p, _ = _provider(monkeypatch, [edges(node(imdb_id="tt999", text="Something Else Entirely"))])
|
||||
assert p.search("The Last of Us", 2023, "tv") is None
|
||||
|
||||
|
||||
def test_search_survives_a_null_language_block(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p, _ = _provider(monkeypatch, [_edges(_node(languages=None))])
|
||||
p, _ = _provider(monkeypatch, [edges(node(languages=None))])
|
||||
result = p.search("The Last of Us", 2023, "tv")
|
||||
assert result is not None and result.original_language is None
|
||||
|
||||
|
||||
def test_search_returns_none_when_nothing_comes_back(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p, _ = _provider(monkeypatch, [_edges()])
|
||||
p, _ = _provider(monkeypatch, [edges()])
|
||||
assert p.search("The Last of Us", 2023, "tv") is None
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ def test_escape_graphql_closes_the_string_injection() -> None:
|
||||
|
||||
|
||||
def test_search_term_with_a_quote_stays_inside_the_string(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p, session = _provider(monkeypatch, [NOT_FOUND, _edges(_node(text='The "Best" Show'))])
|
||||
p, session = _provider(monkeypatch, [NOT_FOUND, edges(node(text='The "Best" Show'))])
|
||||
p.search('The "Best" Show', None, "tv")
|
||||
assert 'searchTerm: "The \\"Best\\" Show"' in session.posts[0]["query"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user