"""Tests para hoppscotch_delete_request. Deterministas: monkeypatchean requests.post. Verifican el camino ok (deleteRequest=true) y el de error (deleteRequest=false). """ import sys import infra.hoppscotch_delete_request # noqa: F401 # El __init__ rebinds el nombre a la funcion; recuperamos el submodulo real. mod = sys.modules["infra.hoppscotch_delete_request"] class _FakeResponse: def __init__(self, status_code=200, json_data=None): self.status_code = status_code self._json = json_data def json(self): if self._json is None: raise ValueError("no json") return self._json def test_golden_delete_true(monkeypatch): captured = {} def fake_post(url, **kwargs): captured["url"] = url captured["kwargs"] = kwargs return _FakeResponse(200, {"data": {"deleteRequest": True}}) monkeypatch.setattr(mod.requests, "post", fake_post) result = mod.hoppscotch_delete_request("req-1", access_token="ACCESS-JWT") assert result["status"] == "ok" assert result["deleted"] == "req-1" assert captured["url"].endswith("/graphql") assert captured["kwargs"]["cookies"] == {"access_token": "ACCESS-JWT"} assert "deleteRequest" in captured["kwargs"]["json"]["query"] assert captured["kwargs"]["json"]["variables"] == {"r": "req-1"} def test_error_delete_false(monkeypatch): def fake_post(url, **kwargs): return _FakeResponse(200, {"data": {"deleteRequest": False}}) monkeypatch.setattr(mod.requests, "post", fake_post) result = mod.hoppscotch_delete_request("req-2", access_token="A") assert result["status"] == "error" assert "did not return true" in result["error"]