Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
65 lines
1.8 KiB
Python
65 lines
1.8 KiB
Python
"""Unit tests for Microsoft login page detection."""
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
from selenium.webdriver.common.by import By
|
|
|
|
from onedrive_planner import (
|
|
_email_form_visible,
|
|
_needs_microsoft_login,
|
|
_password_form_visible,
|
|
_planner_session_ready,
|
|
)
|
|
|
|
|
|
def _driver(*, url: str = "", elements: dict | None = None):
|
|
drv = MagicMock()
|
|
drv.current_url = url
|
|
elements = elements or {}
|
|
|
|
def find_elements(by, sel):
|
|
key = (by, sel)
|
|
return elements.get(key, [])
|
|
|
|
drv.find_elements.side_effect = find_elements
|
|
return drv
|
|
|
|
|
|
def _input(displayed: bool = True):
|
|
el = MagicMock()
|
|
el.is_displayed.return_value = displayed
|
|
return el
|
|
|
|
|
|
class TestLoginHelpers:
|
|
def test_password_only_login_detected(self):
|
|
drv = _driver(
|
|
url="https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
|
|
elements={
|
|
(By.CSS_SELECTOR, "input[type='password']"): [_input()],
|
|
},
|
|
)
|
|
assert _password_form_visible(drv)
|
|
assert not _email_form_visible(drv)
|
|
assert _needs_microsoft_login(drv)
|
|
assert not _planner_session_ready(drv)
|
|
|
|
def test_planner_ready_when_no_login_prompt(self):
|
|
drv = _driver(
|
|
url="https://planner.cloud.microsoft/webui/mytasks/assignedtome/view/grid",
|
|
elements={},
|
|
)
|
|
assert not _needs_microsoft_login(drv)
|
|
assert _planner_session_ready(drv)
|
|
|
|
def test_planner_url_with_password_still_needs_login(self):
|
|
drv = _driver(
|
|
url="https://planner.cloud.microsoft/webui/mytasks/assignedtome/view/grid",
|
|
elements={
|
|
(By.CSS_SELECTOR, "input[type='password']"): [_input()],
|
|
},
|
|
)
|
|
assert _needs_microsoft_login(drv)
|
|
assert not _planner_session_ready(drv)
|