mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
import logging
|
|
from typing import Any, Optional
|
|
|
|
import pytest
|
|
|
|
from utils.sharepoint.sharepoint_client import (
|
|
ResourceNotFoundError,
|
|
api_call_decorator,
|
|
)
|
|
|
|
|
|
class _FakeResponse:
|
|
def __init__(self, status_code: int, error_code: str, message: str) -> None:
|
|
self.status_code = status_code
|
|
self._error_code = error_code
|
|
self._message = message
|
|
self.headers: dict[str, str] = {}
|
|
|
|
def json(self) -> dict[str, Any]:
|
|
return {"error": {"code": self._error_code, "message": self._message}}
|
|
|
|
|
|
class _FakeClient:
|
|
headers: Optional[dict[str, str]] = {}
|
|
|
|
def is_access_token_expired(self) -> bool:
|
|
return False
|
|
|
|
@api_call_decorator
|
|
def fetch(self, path: str) -> Any:
|
|
return "GET", f"https://graph.example.invalid/root:/{path}:/children", None
|
|
|
|
|
|
def _patch_response(
|
|
monkeypatch: pytest.MonkeyPatch, response: _FakeResponse
|
|
) -> None:
|
|
monkeypatch.setattr(
|
|
"utils.sharepoint.sharepoint_client.requests.request",
|
|
lambda *args, **kwargs: response,
|
|
)
|
|
|
|
|
|
def test_404_raises_resource_not_found_without_error_logs(
|
|
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
|
) -> None:
|
|
# Arrange
|
|
_patch_response(
|
|
monkeypatch,
|
|
_FakeResponse(404, "itemNotFound", "The resource could not be found."),
|
|
)
|
|
|
|
# Act
|
|
with pytest.raises(ResourceNotFoundError):
|
|
_FakeClient().fetch("missing/folder")
|
|
|
|
# Assert
|
|
error_records = [r for r in caplog.records if r.levelno >= logging.ERROR]
|
|
assert error_records == []
|