mirror of
https://github.com/bunny-lab-io/Borealis.git
synced 2025-12-16 07:25:48 -07:00
Revert from Gitea Mirror Due to Catastrophic Destruction in Github
This commit is contained in:
66
Data/Engine/Unit_Tests/test_access_management_api.py
Normal file
66
Data/Engine/Unit_Tests/test_access_management_api.py
Normal file
@@ -0,0 +1,66 @@
|
||||
# ======================================================
|
||||
# Data\Engine\Unit_Tests\test_access_management_api.py
|
||||
# Description: Exercises access-management endpoints covering GitHub API token administration.
|
||||
#
|
||||
# API Endpoints (if applicable): None
|
||||
# ======================================================
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
import pytest
|
||||
|
||||
from Data.Engine.integrations import github as github_integration
|
||||
|
||||
from .conftest import EngineTestHarness
|
||||
|
||||
|
||||
def _admin_client(harness: EngineTestHarness):
|
||||
client = harness.app.test_client()
|
||||
with client.session_transaction() as sess:
|
||||
sess["username"] = "admin"
|
||||
sess["role"] = "Admin"
|
||||
return client
|
||||
|
||||
|
||||
def test_github_token_get_without_value(engine_harness: EngineTestHarness) -> None:
|
||||
client = _admin_client(engine_harness)
|
||||
response = client.get("/api/github/token")
|
||||
assert response.status_code == 200
|
||||
payload = response.get_json()
|
||||
assert payload["has_token"] is False
|
||||
assert payload["status"] == "missing"
|
||||
assert payload["token"] == ""
|
||||
|
||||
|
||||
def test_github_token_update(engine_harness: EngineTestHarness, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
class DummyResponse:
|
||||
def __init__(self, status_code: int, payload: Dict[str, Any]):
|
||||
self.status_code = status_code
|
||||
self._payload = payload
|
||||
self.headers = {"X-RateLimit-Limit": "5000"}
|
||||
self.text = ""
|
||||
|
||||
def json(self) -> Dict[str, Any]:
|
||||
return self._payload
|
||||
|
||||
def fake_get(url: str, headers: Any = None, timeout: Any = None) -> DummyResponse:
|
||||
return DummyResponse(200, {"commit": {"sha": "abc123"}})
|
||||
|
||||
monkeypatch.setattr(github_integration.requests, "get", fake_get)
|
||||
|
||||
client = _admin_client(engine_harness)
|
||||
response = client.post("/api/github/token", json={"token": "ghp_test"})
|
||||
assert response.status_code == 200
|
||||
payload = response.get_json()
|
||||
assert payload["has_token"] is True
|
||||
assert payload["valid"] is True
|
||||
assert payload["status"] == "ok"
|
||||
assert payload["token"] == "ghp_test"
|
||||
|
||||
verify_response = client.get("/api/github/token")
|
||||
assert verify_response.status_code == 200
|
||||
verify_payload = verify_response.get_json()
|
||||
assert verify_payload["has_token"] is True
|
||||
assert verify_payload["token"] == "ghp_test"
|
||||
@@ -10,6 +10,7 @@ from __future__ import annotations
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from Data.Engine.integrations import github as github_integration
|
||||
from Data.Engine.services.API.devices import management as device_management
|
||||
|
||||
from .conftest import EngineTestHarness
|
||||
@@ -98,13 +99,15 @@ def test_repo_current_hash_uses_cache(engine_harness: EngineTestHarness, monkeyp
|
||||
def json(self) -> Any:
|
||||
return self._payload
|
||||
|
||||
request_exception = getattr(github_integration.requests, "RequestException", RuntimeError)
|
||||
|
||||
def fake_get(url: str, headers: Any, timeout: int) -> DummyResponse:
|
||||
calls["count"] += 1
|
||||
if calls["count"] == 1:
|
||||
return DummyResponse(200, {"commit": {"sha": "abc123"}})
|
||||
raise device_management.requests.RequestException("network error")
|
||||
raise request_exception("network error")
|
||||
|
||||
monkeypatch.setattr(device_management.requests, "get", fake_get)
|
||||
monkeypatch.setattr(github_integration.requests, "get", fake_get)
|
||||
|
||||
client = engine_harness.app.test_client()
|
||||
first = client.get("/api/repo/current_hash?repo=test/test&branch=main")
|
||||
|
||||
Reference in New Issue
Block a user