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.
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
"""Tests for Airbnb authentication / storage state management."""
|
|
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
|
|
from src.airbnb.auth import DEFAULT_STATE_PATH, load_authenticated_context
|
|
|
|
|
|
class TestLoadAuthenticatedContext:
|
|
def test_raises_when_state_file_missing(self, tmp_path):
|
|
browser = MagicMock()
|
|
missing_path = tmp_path / "nonexistent.json"
|
|
|
|
with pytest.raises(FileNotFoundError, match="No saved session"):
|
|
load_authenticated_context(browser, state_path=missing_path)
|
|
|
|
def test_loads_context_when_state_exists(self, tmp_path):
|
|
state_path = tmp_path / "state.json"
|
|
state_path.write_text("{}")
|
|
|
|
mock_context = MagicMock()
|
|
mock_browser = MagicMock()
|
|
mock_browser.new_context.return_value = mock_context
|
|
|
|
ctx = load_authenticated_context(mock_browser, state_path=state_path)
|
|
|
|
mock_browser.new_context.assert_called_once_with(
|
|
storage_state=str(state_path),
|
|
viewport={"width": 1440, "height": 900},
|
|
locale="en-CA",
|
|
)
|
|
assert ctx is mock_context
|
|
|
|
def test_default_state_path(self):
|
|
assert DEFAULT_STATE_PATH == Path("state.json")
|