MCPcopy Index your code
hub / github.com/AstrBotDevs/AstrBot / test_do_update

Function test_do_update

tests/test_dashboard.py:2696–2790  ·  view source on GitHub ↗
(
    app: FastAPIAppAdapter,
    authenticated_header: dict,
    core_lifecycle_td: AstrBotCoreLifecycle,
    monkeypatch,
    tmp_path_factory,
)

Source from the content-addressed store, hash-verified

2694
2695@pytest.mark.asyncio
2696async def test_do_update(
2697 app: FastAPIAppAdapter,
2698 authenticated_header: dict,
2699 core_lifecycle_td: AstrBotCoreLifecycle,
2700 monkeypatch,
2701 tmp_path_factory,
2702):
2703 test_client = app.test_client()
2704
2705 # Use a temporary path for the mock update to avoid side effects
2706 temp_release_dir = tmp_path_factory.mktemp("release")
2707 release_path = temp_release_dir / "astrbot"
2708 calls = []
2709
2710 async def mock_download_core(*args, **kwargs):
2711 calls.append("download-core")
2712 callback = kwargs.get("progress_callback")
2713 if callback:
2714 callback({"downloaded": 10, "total": 10, "percent": 1, "speed": 1})
2715 zip_path = kwargs["path"]
2716 with zipfile.ZipFile(zip_path, "w") as zf:
2717 zf.writestr("AstrBot-main/README.md", "core")
2718 return zip_path
2719
2720 def mock_apply_core(*args, **kwargs):
2721 del args, kwargs
2722 calls.append("apply-core")
2723 os.makedirs(release_path, exist_ok=True)
2724
2725 async def mock_download_dashboard(*args, **kwargs):
2726 calls.append("download-dashboard")
2727 callback = kwargs.get("progress_callback")
2728 if callback:
2729 callback({"downloaded": 10, "total": 10, "percent": 1, "speed": 1})
2730 with zipfile.ZipFile(kwargs["path"], "w") as zf:
2731 zf.writestr("dist/index.html", "dashboard")
2732 return
2733
2734 def mock_extract_dashboard(*args, **kwargs):
2735 del args, kwargs
2736 calls.append("apply-dashboard")
2737
2738 async def mock_pip_install(*args, **kwargs):
2739 """Mocks pip install to prevent actual installation."""
2740 return
2741
2742 monkeypatch.setattr(
2743 core_lifecycle_td.astrbot_updator,
2744 "download_update_package",
2745 mock_download_core,
2746 )
2747 monkeypatch.setattr(
2748 core_lifecycle_td.astrbot_updator,
2749 "apply_update_package",
2750 mock_apply_core,
2751 )
2752 monkeypatch.setattr(
2753 "astrbot.dashboard.services.update_service.download_dashboard",

Callers

nothing calls this directly

Calls 4

test_clientMethod · 0.80
postMethod · 0.45
get_jsonMethod · 0.45

Tested by

no test coverage detected