Files
AtAnyRate/tests/airbnb/test_browser.py
T
ilia a08839961b Make CI ruff/pytest gates hard, fix stale tests
Removes || true from the ruff and pytest steps (job names unchanged so branch protection contexts still match), adds [tool.ruff] config (E4/E7/E9/F/I, line-length 120), applies ruff autofixes, and rewrites tests that had drifted from the current calendar/auth/main APIs — failures the soft gates had been hiding.
2026-07-26 15:42:40 -04:00

39 lines
1.3 KiB
Python

"""Tests for optional stealth browser launcher."""
from unittest.mock import MagicMock, patch
import pytest
from src.airbnb.browser import open_browser, use_stealth_browser
class TestUseStealthBrowser:
def test_default_off(self, monkeypatch):
monkeypatch.delenv("AIRBNB_STEALTH", raising=False)
assert use_stealth_browser() is False
def test_enabled(self, monkeypatch):
monkeypatch.setenv("AIRBNB_STEALTH", "1")
assert use_stealth_browser() is True
class TestOpenBrowser:
def test_chromium_path(self, monkeypatch):
monkeypatch.delenv("AIRBNB_STEALTH", raising=False)
mock_browser = MagicMock()
mock_pw = MagicMock()
mock_pw.chromium.launch.return_value = mock_browser
with patch("playwright.sync_api.sync_playwright") as mock_sync:
mock_sync.return_value.__enter__.return_value = mock_pw
with open_browser(headless=True) as browser:
assert browser is mock_browser
mock_browser.close.assert_called_once()
def test_stealth_requires_package(self, monkeypatch):
monkeypatch.setenv("AIRBNB_STEALTH", "1")
with patch.dict("sys.modules", {"invisible_playwright": None}):
with pytest.raises(ImportError, match="invisible_playwright"):
with open_browser(headless=True):
pass