diff --git a/src/monitoring_proxy/metrics.py b/src/monitoring_proxy/metrics.py index 90b53a4..0979b3c 100644 --- a/src/monitoring_proxy/metrics.py +++ b/src/monitoring_proxy/metrics.py @@ -46,10 +46,8 @@ async def get_recent_metrics_age(api_url_prefix: str, now: datetime) -> timedelt Get the age of the most recent metrics from the specified `pyaleph` node. """ recent_metrics = await get_recent_metrics(api_url_prefix) - print(recent_metrics) signed_timestamp: float = recent_metrics[0]["content"]["time"] signed_datetime = datetime.fromtimestamp(signed_timestamp, tz=timezone.utc) - print("Z", now, signed_datetime, recent_metrics[0]["content"]["time"]) return now - signed_datetime diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 34ee4f1..42271fd 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -1,5 +1,5 @@ from datetime import datetime, timedelta, timezone -from unittest.mock import AsyncMock, patch +from unittest.mock import AsyncMock, MagicMock, patch import pytest from aioresponses import aioresponses @@ -74,8 +74,15 @@ async def test_returns_metrics_age_by_node(): {"content": {"time": (now - timedelta(minutes=30)).timestamp()}} ] + def mock_now(tz=None): + return now + + mock_datetime = MagicMock(now=mock_now) + mock_datetime.fromtimestamp = datetime.fromtimestamp + with patch("monitoring_proxy.metrics.get_recent_metrics", new=async_mock): - metrics_age = await get_metrics_age_by_node() + with patch("monitoring_proxy.metrics.datetime", new=mock_datetime): + metrics_age = await get_metrics_age_by_node() assert metrics_age.acceptable assert metrics_age.scoring_node < 5400