|
1 | 1 | """Tests for aignostics_foundry_core.gui.*.""" |
2 | 2 |
|
3 | 3 | import asyncio |
4 | | -import os |
5 | 4 | import sys |
6 | 5 | import time |
7 | | -from collections.abc import Generator |
8 | 6 | from contextlib import contextmanager |
9 | 7 | from types import SimpleNamespace |
10 | 8 | from unittest.mock import AsyncMock, MagicMock, patch |
11 | 9 |
|
12 | 10 | import pytest |
13 | 11 |
|
14 | | -from aignostics_foundry_core.foundry import reset_context, set_context |
15 | 12 | from aignostics_foundry_core.gui.core import ( |
16 | 13 | BROWSER_RECONNECT_TIMEOUT, |
17 | 14 | RESPONSE_TIMEOUT, |
|
25 | 22 | NavItem, |
26 | 23 | gui_get_nav_groups, |
27 | 24 | ) |
28 | | -from tests.aignostics_foundry_core.api import AUTH0_ROLE_CLAIM_VAR_NAME, INTERNAL_ORG_ID_VAR_NAME |
29 | 25 | from tests.conftest import TEST_PROJECT_NAME, make_context |
30 | 26 |
|
31 | 27 | _PATCH_GET_GUI_USER = "aignostics_foundry_core.gui.auth.get_gui_user" |
|
34 | 30 | _PATH_CORE_LOCATE = "aignostics_foundry_core.gui.core.locate_subclasses" |
35 | 31 |
|
36 | 32 | _TEST_PATH = "/test-page" |
37 | | -_INTERNAL_ORG = "org_internal" |
38 | 33 | _OTHER_ORG = "org_other" |
39 | | -_ROLE_CLAIM = "https://example.com/role" |
40 | 34 | _FIXED_PORT = 9000 |
41 | 35 | _DOCS_PATH = "/docs" |
42 | 36 | _USER_SUB = "auth0|x" |
@@ -248,15 +242,6 @@ def test_browser_reconnect_timeout_is_long(self) -> None: |
248 | 242 | class TestGuiRegisterPages: |
249 | 243 | """Tests for gui_register_pages behaviour.""" |
250 | 244 |
|
251 | | - @pytest.fixture(autouse=True) |
252 | | - def _clear_registry(self) -> Generator[None, None, None]: # pyright: ignore[reportUnusedFunction] |
253 | | - """Ensure the page registry is clean before and after each test.""" |
254 | | - from aignostics_foundry_core.gui import clear_page_registry |
255 | | - |
256 | | - clear_page_registry() |
257 | | - yield |
258 | | - clear_page_registry() |
259 | | - |
260 | 245 | def test_calls_register_pages_on_each_builder(self) -> None: |
261 | 246 | """gui_register_pages calls register_pages() on every discovered builder.""" |
262 | 247 | builder_a = MagicMock(spec=BasePageBuilder) |
@@ -463,17 +448,6 @@ def test_gui_register_pages_called(self) -> None: |
463 | 448 | class TestGetGuiUser: |
464 | 449 | """Tests for get_gui_user behaviour.""" |
465 | 450 |
|
466 | | - @pytest.fixture(autouse=True) |
467 | | - def _gui_context(self) -> Generator[None, None, None]: # pyright: ignore[reportUnusedFunction] |
468 | | - """Install a minimal context and required AuthSettings env vars.""" |
469 | | - set_context(make_context()) |
470 | | - os.environ[INTERNAL_ORG_ID_VAR_NAME] = _INTERNAL_ORG |
471 | | - os.environ[AUTH0_ROLE_CLAIM_VAR_NAME] = _ROLE_CLAIM |
472 | | - yield |
473 | | - os.environ.pop(INTERNAL_ORG_ID_VAR_NAME, None) |
474 | | - os.environ.pop(AUTH0_ROLE_CLAIM_VAR_NAME, None) |
475 | | - reset_context() |
476 | | - |
477 | 451 | async def test_returns_none_when_auth_client_raises(self) -> None: |
478 | 452 | """Returns None when get_auth_client raises (no auth configured).""" |
479 | 453 | from aignostics_foundry_core.gui.auth import get_gui_user |
@@ -549,17 +523,6 @@ async def test_returns_none_when_session_has_no_user_key(self) -> None: |
549 | 523 | class TestRequireGuiUser: |
550 | 524 | """Tests for require_gui_user behaviour.""" |
551 | 525 |
|
552 | | - @pytest.fixture(autouse=True) |
553 | | - def _gui_context(self) -> Generator[None, None, None]: # pyright: ignore[reportUnusedFunction] |
554 | | - """Install a minimal context and required AuthSettings env vars.""" |
555 | | - set_context(make_context()) |
556 | | - os.environ[INTERNAL_ORG_ID_VAR_NAME] = _INTERNAL_ORG |
557 | | - os.environ[AUTH0_ROLE_CLAIM_VAR_NAME] = _ROLE_CLAIM |
558 | | - yield |
559 | | - os.environ.pop(INTERNAL_ORG_ID_VAR_NAME, None) |
560 | | - os.environ.pop(AUTH0_ROLE_CLAIM_VAR_NAME, None) |
561 | | - reset_context() |
562 | | - |
563 | 526 | async def test_redirects_to_login_when_no_user(self) -> None: |
564 | 527 | """Redirects to /auth/login when get_gui_user returns None.""" |
565 | 528 | from aignostics_foundry_core.gui.auth import require_gui_user |
@@ -635,22 +598,6 @@ def _make_nicegui_mock() -> tuple[MagicMock, MagicMock]: |
635 | 598 | class TestPageRegistryDecorators: |
636 | 599 | """Tests for page_* registry decorators (deferred registration).""" |
637 | 600 |
|
638 | | - @pytest.fixture(autouse=True) |
639 | | - def _clear_registry(self) -> Generator[None, None, None]: # pyright: ignore[reportUnusedFunction] |
640 | | - """Ensure registry is clean before and after each test.""" |
641 | | - from aignostics_foundry_core.gui import clear_page_registry |
642 | | - |
643 | | - clear_page_registry() |
644 | | - yield |
645 | | - clear_page_registry() |
646 | | - |
647 | | - @pytest.fixture(autouse=True) |
648 | | - def _context(self) -> Generator[None, None, None]: # pyright: ignore[reportUnusedFunction] |
649 | | - """Install a minimal FoundryContext so get_context() works inside page wrappers.""" |
650 | | - set_context(make_context()) |
651 | | - yield |
652 | | - reset_context() |
653 | | - |
654 | 601 | def _actualize_via_register_pages(self, frame_func: object = None) -> tuple[list[object], MagicMock]: |
655 | 602 | """Run gui_register_pages and return (wrappers, nicegui_mock). |
656 | 603 |
|
@@ -909,13 +856,6 @@ def my_page(user: object) -> None: ... |
909 | 856 | class TestGUINamespace: |
910 | 857 | """Tests for GUINamespace and the gui singleton.""" |
911 | 858 |
|
912 | | - @pytest.fixture(autouse=True) |
913 | | - def _context(self) -> Generator[None, None, None]: # pyright: ignore[reportUnusedFunction] |
914 | | - """Install a minimal FoundryContext so get_context() works inside page wrappers.""" |
915 | | - set_context(make_context()) |
916 | | - yield |
917 | | - reset_context() |
918 | | - |
919 | 859 | def test_gui_exposes_all_decorator_methods(self) -> None: |
920 | 860 | """The gui singleton exposes all page decorator methods as callables.""" |
921 | 861 | from aignostics_foundry_core.gui.auth import gui |
|
0 commit comments