Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /als-apg_osprey /tests /cli /test_panel_registration.py
| """The BLUESKY panel's registration in a built project. | |
| ``_inject_bluesky_web`` writes the ``web.panels.bluesky`` entry into a built | |
| ``config.yml``, pointing the web-terminal proxy at the sidecar and selecting | |
| the panel's static mount via ``path``. This module covers that registration | |
| end to end: the entry a fresh build writes, the profile validation that lets | |
| ``bluesky`` stay url-less (its URL is derived post-build from the sidecar | |
| port), and that the registered path actually serves the panel's HTML. | |
| The rest of ``_inject_bluesky_web`` (template copy, service config, | |
| deployed_services, url derivation, override precedence) is covered by | |
| ``test_inject_bluesky_web.py``. | |
| """ | |
| from __future__ import annotations | |
| import warnings | |
| from pathlib import Path | |
| import pytest | |
| from ruamel.yaml import YAML | |
| from osprey.cli.build_injectors import _inject_bluesky_web | |
| from osprey.cli.build_profile import BlueskyWebConfig, BuildProfile | |
| from osprey.port_layout import default_port | |
| def _facility_data_tree(tmp_path: Path) -> None: | |
| """The tree every profile's ``data:`` key names, beside the profile. | |
| ``data:`` is required of a repo profile and must resolve to a real | |
| directory, so without this each profile below would report one extra | |
| failure about a key none of these tests is about. | |
| """ | |
| (tmp_path / "data").mkdir(exist_ok=True) | |
| def _write_config(project_path: Path, *, panels: dict | None = None) -> None: | |
| """Write a minimal config.yml, optionally pre-seeded with web.panels entries.""" | |
| yaml = YAML() | |
| config: dict = {"deployed_services": [], "services": {}} | |
| if panels is not None: | |
| config["web"] = {"panels": panels} | |
| with open(project_path / "config.yml", "w") as fh: | |
| yaml.dump(config, fh) | |
| def _read_panels(project_path: Path) -> dict: | |
| yaml = YAML() | |
| with open(project_path / "config.yml") as fh: | |
| return yaml.load(fh)["web"]["panels"] | |
| def project_path(tmp_path: Path) -> Path: | |
| path = tmp_path / "project" | |
| path.mkdir() | |
| return path | |
| def test_injector_registers_the_bluesky_panel(project_path: Path) -> None: | |
| """The entry carries the derived url, the panel's mount path, and its label.""" | |
| _write_config(project_path) | |
| _inject_bluesky_web( | |
| BlueskyWebConfig(port=default_port("bluesky_web")), project_path=project_path | |
| ) | |
| bluesky = _read_panels(project_path)["bluesky"] | |
| assert bluesky["url"] == f"${{BLUESKY_WEB_URL:-http://localhost:{default_port('bluesky_web')}}}" | |
| assert bluesky["path"] == "/bluesky/" | |
| assert bluesky["label"] == "BLUESKY" | |
| def test_injector_registers_exactly_one_panel(project_path: Path) -> None: | |
| """One sidecar, one tab: a fresh build writes ``bluesky`` and nothing else. | |
| A second entry here would put two rail entries in front of the same | |
| bundle on every new project and on every rebuild. | |
| """ | |
| _write_config(project_path) | |
| _inject_bluesky_web(BlueskyWebConfig(), project_path=project_path) | |
| assert set(_read_panels(project_path)) == {"bluesky"} | |
| def test_profile_listing_bluesky_validates_without_warning(tmp_path: Path) -> None: | |
| """``bluesky`` is url-less-legal (its URL is derived post-build) — and silent.""" | |
| profile = BuildProfile( | |
| name="modern", | |
| data="data", | |
| web_panels=["bluesky"], | |
| bluesky_web=BlueskyWebConfig(), | |
| ) | |
| with warnings.catch_warnings(): | |
| warnings.simplefilter("error", UserWarning) | |
| profile.validate(tmp_path) | |
| def test_the_registered_path_actually_serves_the_panel(project_path: Path) -> None: | |
| """The operator-visible half: the registered path returns the panel's HTML. | |
| A mount can be registered against an empty directory and still 404 (see | |
| ``tests/interfaces/bluesky_web/test_health.py``), which would leave this | |
| config.yml pointing a tab at nothing. | |
| """ | |
| from fastapi.testclient import TestClient | |
| from osprey.interfaces.bluesky_web.app import app | |
| _write_config(project_path) | |
| _inject_bluesky_web(BlueskyWebConfig(), project_path=project_path) | |
| panels = _read_panels(project_path) | |
| with TestClient(app) as client: | |
| response = client.get(panels["bluesky"]["path"]) | |
| assert response.status_code == 200 | |
| assert "text/html" in response.headers["content-type"] | |
Xet Storage Details
- Size:
- 4.34 kB
- Xet hash:
- 84051eafb945bf9ff8f11f9e7168ac3d73086bfcd78275502fd08a3710504fb9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.