feat(infra): auto-commit con 88 cambios
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
"""Tests para enumerate_username_sites (red mockeada con monkeypatch)."""
|
||||
|
||||
import requests
|
||||
|
||||
import enumerate_username_sites as mod
|
||||
from enumerate_username_sites import enumerate_username_sites
|
||||
|
||||
|
||||
class _FakeResp:
|
||||
"""Respuesta HTTP minima con solo status_code."""
|
||||
|
||||
def __init__(self, status_code):
|
||||
self.status_code = status_code
|
||||
|
||||
|
||||
def _make_get(status_by_url):
|
||||
"""Construye un fake de requests.get que devuelve status por URL."""
|
||||
|
||||
def _fake_get(url, **kwargs):
|
||||
return _FakeResp(status_by_url[url])
|
||||
|
||||
return _fake_get
|
||||
|
||||
|
||||
SITES = [
|
||||
{"site": "alpha", "url": "https://alpha.test/{u}"},
|
||||
{"site": "beta", "url": "https://beta.test/{u}"},
|
||||
{"site": "gamma", "url": "https://gamma.test/{u}"},
|
||||
]
|
||||
|
||||
|
||||
def test_status_200_es_existe(monkeypatch):
|
||||
"""Un 200 marca exists=True."""
|
||||
status_map = {
|
||||
"https://alpha.test/bob": 200,
|
||||
"https://beta.test/bob": 200,
|
||||
"https://gamma.test/bob": 200,
|
||||
}
|
||||
monkeypatch.setattr(requests, "get", _make_get(status_map))
|
||||
out = enumerate_username_sites("bob", sites=SITES)
|
||||
assert all(r["exists"] is True for r in out)
|
||||
assert all(r["status"] == 200 for r in out)
|
||||
|
||||
|
||||
def test_status_404_es_no_existe(monkeypatch):
|
||||
"""Un 404 marca exists=False."""
|
||||
status_map = {
|
||||
"https://alpha.test/ghost": 404,
|
||||
"https://beta.test/ghost": 404,
|
||||
"https://gamma.test/ghost": 404,
|
||||
}
|
||||
monkeypatch.setattr(requests, "get", _make_get(status_map))
|
||||
out = enumerate_username_sites("ghost", sites=SITES)
|
||||
assert all(r["exists"] is False for r in out)
|
||||
assert all(r["status"] == 404 for r in out)
|
||||
|
||||
|
||||
def test_status_otro_es_indeterminado(monkeypatch):
|
||||
"""Un codigo distinto de 200/404 deja exists=None pero conserva status."""
|
||||
status_map = {
|
||||
"https://alpha.test/x": 301,
|
||||
"https://beta.test/x": 403,
|
||||
"https://gamma.test/x": 500,
|
||||
}
|
||||
monkeypatch.setattr(requests, "get", _make_get(status_map))
|
||||
out = enumerate_username_sites("x", sites=SITES)
|
||||
assert [r["exists"] for r in out] == [None, None, None]
|
||||
assert [r["status"] for r in out] == [301, 403, 500]
|
||||
|
||||
|
||||
def test_excepcion_por_sitio_no_aborta_el_resto(monkeypatch):
|
||||
"""Un fallo de red en un sitio no interrumpe la enumeracion."""
|
||||
|
||||
def _fake_get(url, **kwargs):
|
||||
if "beta" in url:
|
||||
raise requests.Timeout("simulado")
|
||||
return _FakeResp(200)
|
||||
|
||||
monkeypatch.setattr(requests, "get", _fake_get)
|
||||
out = enumerate_username_sites("u", sites=SITES)
|
||||
assert len(out) == 3
|
||||
by_site = {r["site"]: r for r in out}
|
||||
assert by_site["alpha"]["exists"] is True
|
||||
assert by_site["alpha"]["status"] == 200
|
||||
# El sitio que fallo queda con status/exists None.
|
||||
assert by_site["beta"]["exists"] is None
|
||||
assert by_site["beta"]["status"] is None
|
||||
assert by_site["gamma"]["exists"] is True
|
||||
|
||||
|
||||
def test_estructura_y_url_formateada(monkeypatch):
|
||||
"""Cada resultado lleva las claves esperadas y la URL con el username."""
|
||||
status_map = {
|
||||
"https://alpha.test/neo": 200,
|
||||
"https://beta.test/neo": 404,
|
||||
"https://gamma.test/neo": 200,
|
||||
}
|
||||
monkeypatch.setattr(requests, "get", _make_get(status_map))
|
||||
out = enumerate_username_sites("neo", sites=SITES)
|
||||
for r in out:
|
||||
assert set(r.keys()) == {"site", "url", "exists", "status"}
|
||||
assert "neo" in r["url"]
|
||||
|
||||
|
||||
def test_lista_por_defecto_tiene_doce_sitios():
|
||||
"""La lista DEFAULT_SITES cubre ~12 sitios publicos."""
|
||||
assert len(mod.DEFAULT_SITES) == 12
|
||||
sites = {s["site"] for s in mod.DEFAULT_SITES}
|
||||
assert {"github", "instagram", "reddit", "telegram"} <= sites
|
||||
Reference in New Issue
Block a user