import os
import subprocess
import sys
from pathlib import Path


def test_e2e_refuses_to_run_without_required_environment() -> None:
    script = Path(__file__).parent / "manual" / "e2e.py"
    environment = os.environ.copy()
    for name in (
        "ABUSEIPDB_API_KEY",
        "ABUSEIPDB_E2E_CHECK_IP",
        "ABUSEIPDB_E2E_REPORT_IP",
        "ABUSEIPDB_E2E_BULK_IP",
        "ABUSEIPDB_E2E_NETWORK",
    ):
        environment.pop(name, None)

    result = subprocess.run(
        [sys.executable, str(script), "--allow-writes"],
        capture_output=True,
        check=False,
        env=environment,
        text=True,
    )

    assert result.returncode == 2
    assert "Missing required environment variables" in result.stderr
    assert "ABUSEIPDB_API_KEY" in result.stderr
