From 86502e588326a61876b1d4065faba3e3965d6ca7 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Fri, 7 Aug 2026 13:06:52 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A7=AA=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EA=B0=9C=EC=84=A0:=20models.py=EC=9D=98=20utcnow=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/tests/test_models.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 backend/tests/test_models.py diff --git a/backend/tests/test_models.py b/backend/tests/test_models.py new file mode 100644 index 00000000..b49579b7 --- /dev/null +++ b/backend/tests/test_models.py @@ -0,0 +1,30 @@ +import datetime as dt +from unittest import mock + +from app.models import utcnow + +def test_utcnow(): + """Test that utcnow returns a timezone-aware datetime in UTC.""" + now = utcnow() + assert isinstance(now, dt.datetime) + assert now.tzinfo is not None + assert now.tzinfo == dt.timezone.utc + + # Assert it's reasonably close to the actual current time + assert (dt.datetime.now(dt.timezone.utc) - now).total_seconds() < 1.0 + +@mock.patch("app.models.dt.datetime") +def test_utcnow_calls_now(mock_datetime): + """Test that utcnow calls datetime.now with dt.timezone.utc.""" + # Set up the mock to return a specific value + mock_now = mock.Mock() + mock_datetime.now.return_value = mock_now + + # Call the function + result = utcnow() + + # Verify datetime.now was called with UTC timezone + mock_datetime.now.assert_called_once_with(dt.timezone.utc) + + # Verify it returns exactly what datetime.now returned + assert result == mock_now From 3d89c86c2d46836cb20227cc6d4f5037b0aa61d1 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Fri, 7 Aug 2026 22:30:42 +0900 Subject: [PATCH 2/2] test(models): consolidate utcnow coverage contracts --- backend/tests/test_models.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/backend/tests/test_models.py b/backend/tests/test_models.py index b49579b7..9021dfcd 100644 --- a/backend/tests/test_models.py +++ b/backend/tests/test_models.py @@ -3,28 +3,24 @@ from app.models import utcnow -def test_utcnow(): - """Test that utcnow returns a timezone-aware datetime in UTC.""" + +def test_utcnow() -> None: + """Verify that utcnow returns a timezone-aware UTC value near the current time.""" now = utcnow() assert isinstance(now, dt.datetime) - assert now.tzinfo is not None - assert now.tzinfo == dt.timezone.utc + assert now.tzinfo is dt.timezone.utc + + delta = dt.datetime.now(dt.timezone.utc) - now + assert abs(delta.total_seconds()) < 1.0 - # Assert it's reasonably close to the actual current time - assert (dt.datetime.now(dt.timezone.utc) - now).total_seconds() < 1.0 @mock.patch("app.models.dt.datetime") -def test_utcnow_calls_now(mock_datetime): - """Test that utcnow calls datetime.now with dt.timezone.utc.""" - # Set up the mock to return a specific value +def test_utcnow_calls_now(mock_datetime: mock.Mock) -> None: + """Verify that utcnow delegates to datetime.now with the UTC timezone.""" mock_now = mock.Mock() mock_datetime.now.return_value = mock_now - # Call the function result = utcnow() - # Verify datetime.now was called with UTC timezone mock_datetime.now.assert_called_once_with(dt.timezone.utc) - - # Verify it returns exactly what datetime.now returned assert result == mock_now