Files
wehub-resource-sync 7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

203 lines
6.2 KiB
Python

"""High-value tests for small utility modules: url_utils, network_utils, type_utils, text_cleaner."""
import unittest
from local_deep_research.security.network_utils import is_private_ip
from local_deep_research.utilities.type_utils import to_bool
from local_deep_research.utilities.url_utils import normalize_url
from local_deep_research.text_processing.text_cleaner import remove_surrogates
# ── is_private_ip ──────────────────────────────────────────────────────
class TestIsPrivateIpLocalhost(unittest.TestCase):
def test_localhost_string(self):
assert is_private_ip("localhost") is True
def test_127_0_0_1(self):
assert is_private_ip("127.0.0.1") is True
def test_ipv6_loopback_bracketed(self):
assert is_private_ip("[::1]") is True
def test_0_0_0_0(self):
assert is_private_ip("0.0.0.0") is True
class TestIsPrivateIpRanges(unittest.TestCase):
def test_10_network(self):
assert is_private_ip("10.0.0.1") is True
def test_172_16_network(self):
assert is_private_ip("172.16.0.50") is True
def test_192_168_network(self):
assert is_private_ip("192.168.1.100") is True
def test_public_ip_8888(self):
assert is_private_ip("8.8.8.8") is False
def test_public_ip_1111(self):
assert is_private_ip("1.1.1.1") is False
class TestIsPrivateIpDomains(unittest.TestCase):
def test_local_domain(self):
assert is_private_ip("myhost.local") is True
def test_external_domain(self):
assert is_private_ip("api.openai.com") is False
def test_random_hostname(self):
assert is_private_ip("somehost") is False
class TestIsPrivateIpIpv6(unittest.TestCase):
def test_ipv6_link_local(self):
assert is_private_ip("fe80::1") is True
def test_ipv6_private(self):
assert is_private_ip("fc00::1") is True
def test_bracketed_ipv6_private(self):
assert is_private_ip("[fc00::1]") is True
# ── normalize_url ──────────────────────────────────────────────────────
class TestNormalizeUrl(unittest.TestCase):
def test_already_http(self):
assert normalize_url("http://example.com") == "http://example.com"
def test_already_https(self):
assert normalize_url("https://example.com") == "https://example.com"
def test_malformed_http_colon(self):
assert normalize_url("http:example.com") == "http://example.com"
def test_malformed_https_colon(self):
assert normalize_url("https:example.com") == "https://example.com"
def test_localhost_gets_http(self):
result = normalize_url("localhost:11434")
assert result == "http://localhost:11434"
def test_external_host_gets_https(self):
result = normalize_url("api.openai.com:443")
assert result == "https://api.openai.com:443"
def test_empty_raises_value_error(self):
with self.assertRaises(ValueError):
normalize_url("")
def test_whitespace_stripped(self):
result = normalize_url(" http://example.com ")
assert result == "http://example.com"
def test_double_slash_prefix(self):
result = normalize_url("//localhost:8080")
assert result == "http://localhost:8080"
def test_private_ip_gets_http(self):
result = normalize_url("192.168.1.1:8080")
assert result == "http://192.168.1.1:8080"
# ── to_bool ────────────────────────────────────────────────────────────
class TestToBoolPassthrough(unittest.TestCase):
def test_true(self):
assert to_bool(True) is True
def test_false(self):
assert to_bool(False) is False
class TestToBoolStrings(unittest.TestCase):
def test_true_string(self):
assert to_bool("true") is True
def test_yes(self):
assert to_bool("yes") is True
def test_one_string(self):
assert to_bool("1") is True
def test_on(self):
assert to_bool("on") is True
def test_enabled(self):
assert to_bool("enabled") is True
def test_false_string(self):
assert to_bool("false") is False
def test_zero_string(self):
assert to_bool("0") is False
def test_no_string(self):
assert to_bool("no") is False
def test_empty_string(self):
assert to_bool("") is False
def test_case_insensitive(self):
assert to_bool("TRUE") is True
assert to_bool("True") is True
def test_whitespace_handling(self):
assert to_bool(" true ") is True
class TestToBoolNoneAndOther(unittest.TestCase):
def test_none_default_false(self):
assert to_bool(None) is False
def test_none_default_true(self):
assert to_bool(None, default=True) is True
def test_integer_zero(self):
assert to_bool(0) is False
def test_integer_one(self):
assert to_bool(1) is True
def test_integer_negative(self):
assert to_bool(-1) is True
def test_empty_list(self):
assert to_bool([]) is False
def test_nonempty_list(self):
assert to_bool([1]) is True
# ── remove_surrogates ──────────────────────────────────────────────────
class TestRemoveSurrogates(unittest.TestCase):
def test_normal_text(self):
assert remove_surrogates("hello world") == "hello world"
def test_empty_string_returns_empty(self):
assert remove_surrogates("") == ""
def test_unicode_preserved(self):
assert remove_surrogates("café résumé") == "café résumé"
def test_surrogate_characters_handled(self):
# Create text with a surrogate character
text = "hello \ud800 world"
result = remove_surrogates(text)
# Should not raise and should produce valid UTF-8
result.encode("utf-8")
assert "hello" in result
assert "world" in result
if __name__ == "__main__":
unittest.main()