mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-06 07:55:10 +00:00
test: delete slow, timing-based and redundant tests
This commit is contained in:
@@ -3,10 +3,8 @@ provider:query split, the named or bare provider lookup, and the line that repor
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
from collections.abc import Iterator
|
||||
from contextlib import contextmanager
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -96,11 +94,6 @@ def test_a_city_query_without_a_provider_prefix_fails_with_a_hint(providers: lis
|
||||
resolve_proxy(value, providers)
|
||||
|
||||
|
||||
def test_a_prefix_naming_a_failed_provider_reports_why(providers: list) -> None:
|
||||
with pytest.raises(ValueError, match="Gamma could not load: no route"):
|
||||
split_proxy_query("gamma:us", providers)
|
||||
|
||||
|
||||
def test_named_query_asks_only_that_provider(providers: list) -> None:
|
||||
provider, uri = pick_proxy(providers, "ca", "beta")
|
||||
assert isinstance(provider, Beta) and uri == "http://c:d@beta-ca.example:80"
|
||||
@@ -133,20 +126,12 @@ def test_describe_masks_the_host_of_a_basic_proxy() -> None:
|
||||
assert line == "Using Basic Proxy: http://xxxxx:xxxxx@xxxxx:3128"
|
||||
|
||||
|
||||
def test_describe_prefers_the_provider_display() -> None:
|
||||
assert describe_proxy(Beta(), "http://c:d@beta.example:80", "us") == "Using Beta Proxy via Dallas (server 12)"
|
||||
|
||||
|
||||
def test_describe_reports_a_vpn_connection() -> None:
|
||||
tunnel = Tunnel({"public_ip": "203.0.113.9", "city": "Toronto", "country": "Canada"})
|
||||
assert describe_proxy(tunnel, "http://127.0.0.1:8888", "alpha:ca") == "VPN Connected: 203.0.113.9 (Toronto, Canada)"
|
||||
assert tunnel.asked == ["alpha:ca"]
|
||||
|
||||
|
||||
def test_describe_falls_back_when_the_vpn_has_no_connection_info() -> None:
|
||||
assert describe_proxy(Tunnel(None), "http://127.0.0.1:8888", "ca") == "Using Tunnel Proxy: http://127.0.0.1:8888"
|
||||
|
||||
|
||||
def test_describe_shows_the_full_uri_in_debug_only_when_allowed() -> None:
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
uri = "http://user:pass@alpha.example:80"
|
||||
@@ -154,13 +139,6 @@ def test_describe_shows_the_full_uri_in_debug_only_when_allowed() -> None:
|
||||
assert "user:pass" not in describe_proxy(Alpha(), uri, "us", allow_debug=False)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"uri", ["http://user:pass@proxy.example:8080", "https://proxy.example:443", "socks5h://proxy.example:1080"]
|
||||
)
|
||||
def test_resolve_proxy_passes_a_uri_through(providers: list, uri: str) -> None:
|
||||
assert resolve_proxy(uri, providers) == uri
|
||||
|
||||
|
||||
def test_resolve_proxy_logs_the_provider_without_credentials(providers: list, caplog: pytest.LogCaptureFixture) -> None:
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
with caplog.at_level(logging.INFO, logger="proxies"):
|
||||
@@ -170,11 +148,6 @@ def test_resolve_proxy_logs_the_provider_without_credentials(providers: list, ca
|
||||
assert "Using Alpha Proxy: http://xxxxx:xxxxx@alpha.example:80" in caplog.text
|
||||
|
||||
|
||||
def test_resolve_proxy_raises_when_no_provider_answers(providers: list) -> None:
|
||||
with pytest.raises(ValueError, match="No proxy provider had a proxy for de"):
|
||||
resolve_proxy("de", providers)
|
||||
|
||||
|
||||
def test_bare_query_skips_a_provider_that_raises(caplog: pytest.LogCaptureFixture) -> None:
|
||||
class Broken:
|
||||
def get_proxy(self, query: str) -> str:
|
||||
@@ -202,15 +175,6 @@ def test_named_query_passes_the_provider_error_on_as_a_value_error() -> None:
|
||||
assert isinstance(raised.value.__cause__, ConnectionError)
|
||||
|
||||
|
||||
def test_named_query_names_the_provider_for_a_bad_catalogue_response() -> None:
|
||||
class Broken:
|
||||
def get_proxy(self, query: str) -> str:
|
||||
raise json.JSONDecodeError("Expecting value", "", 0)
|
||||
|
||||
with pytest.raises(ValueError, match="The proxy provider broken failed for us: Expecting value"):
|
||||
pick_proxy([Broken()], "us", "broken")
|
||||
|
||||
|
||||
def test_named_query_passes_a_query_error_on_unchanged() -> None:
|
||||
class Strict:
|
||||
def get_proxy(self, query: str) -> str:
|
||||
@@ -263,35 +227,6 @@ def test_resolve_proxy_value_reads_each_form(providers: list, value: str, expect
|
||||
assert resolve_proxy_value(value, providers) == expected
|
||||
|
||||
|
||||
def test_resolve_proxy_value_starts_a_forwarder_for_a_control_d_resolver(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
from unshackle.core.proxies import controld
|
||||
|
||||
monkeypatch.setattr(controld, "local_proxy", lambda uri: "http://127.0.0.1:4000")
|
||||
resolved = resolve_proxy_value("controld://efgh456@dns.controld.com", [])
|
||||
assert resolved == ResolvedProxy("http://127.0.0.1:4000", None, "Using a local proxy on port 4000")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("value", "message"), [("us", "Getting a Proxy to us..."), ("gluetun:ca", "Connecting to VPN (ca)...")]
|
||||
)
|
||||
def test_the_status_wraps_only_the_provider_lookup(providers: list, value: str, message: str) -> None:
|
||||
shown: list[str] = []
|
||||
|
||||
@contextmanager
|
||||
def status(text: str) -> Iterator[None]:
|
||||
shown.append(text)
|
||||
yield
|
||||
|
||||
resolve_proxy_value(value, [*providers, Gluetun(ca="http://g.example:8888")], status=status)
|
||||
resolve_proxy_value("http://proxy.example:8080", providers, status=status)
|
||||
assert shown == [message]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", ["localhost:8080", "1.2.3.4:3128"])
|
||||
def test_resolve_proxy_passes_a_host_and_port_through(providers: list, value: str) -> None:
|
||||
assert resolve_proxy(value, providers) == value
|
||||
|
||||
|
||||
class Recorder(Alpha):
|
||||
def __init__(self, **answers: str) -> None:
|
||||
super().__init__(**answers)
|
||||
|
||||
Reference in New Issue
Block a user