diff --git a/tests/test_utils/test_formatting.py b/tests/test_utils/test_formatting.py
index 5928fc62..8efc1598 100644
--- a/tests/test_utils/test_formatting.py
+++ b/tests/test_utils/test_formatting.py
@@ -1,3 +1,5 @@
+from datetime import datetime, timezone
+
import pytest
from aiogram.enums import MessageEntityType
@@ -120,6 +122,10 @@ class TestNode:
DateTime("test", unix_time=42, date_time_format="yMd"),
'test',
],
+ [
+ DateTime("test", unix_time=42),
+ 'test',
+ ],
],
)
def test_render_plain_only(self, node: Text, result: str):
@@ -379,6 +385,22 @@ class TestUtils:
assert node._params["unix_time"] == 42
assert node._params["date_time_format"] == "yMd"
+ def test_date_time_with_datetime_object(self):
+ dt = datetime(2024, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
+ node = DateTime("test", unix_time=dt)
+ assert isinstance(node, DateTime)
+ assert node._params["unix_time"] == 1704067200
+
+ def test_date_time_with_datetime_and_format(self):
+ dt = datetime(2024, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
+ node = DateTime("test", unix_time=dt, date_time_format="yMd")
+ assert node._params["unix_time"] == 1704067200
+ assert node._params["date_time_format"] == "yMd"
+
+ def test_date_time_as_markdown(self):
+ node = DateTime("test", unix_time=42, date_time_format="yMd")
+ assert node.as_markdown() == ""
+
def test_as_line(self):
node = as_line("test", "test", "test")
assert isinstance(node, Text)
diff --git a/tests/test_utils/test_text_decorations.py b/tests/test_utils/test_text_decorations.py
index 82039229..6325edb8 100644
--- a/tests/test_utils/test_text_decorations.py
+++ b/tests/test_utils/test_text_decorations.py
@@ -1,3 +1,5 @@
+from datetime import datetime, timezone
+
import pytest
from aiogram.types import MessageEntity, User
@@ -146,6 +148,16 @@ class TestTextDecoration:
),
"",
],
+ [
+ html_decoration,
+ MessageEntity(type="date_time", offset=0, length=5, unix_time=42),
+ 'test',
+ ],
+ [
+ markdown_decoration,
+ MessageEntity(type="date_time", offset=0, length=5, unix_time=42),
+ "",
+ ],
],
)
def test_apply_single_entity(
@@ -153,6 +165,38 @@ class TestTextDecoration:
):
assert decorator.apply_entity(entity, "test") == result
+ @pytest.mark.parametrize(
+ "decorator,date_time_format,expected",
+ [
+ (
+ html_decoration,
+ None,
+ 'test',
+ ),
+ (
+ html_decoration,
+ "yMd",
+ 'test',
+ ),
+ (
+ markdown_decoration,
+ None,
+ "",
+ ),
+ (
+ markdown_decoration,
+ "yMd",
+ "",
+ ),
+ ],
+ )
+ def test_date_time_with_datetime_object(
+ self, decorator: TextDecoration, date_time_format: str | None, expected: str
+ ):
+ dt = datetime(2024, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
+ result = decorator.date_time("test", unix_time=dt, date_time_format=date_time_format)
+ assert result == expected
+
def test_unknown_apply_entity(self):
assert (
html_decoration.apply_entity(
@@ -318,6 +362,22 @@ class TestTextDecoration:
],
"test@example.com",
],
+ [
+ html_decoration,
+ "test",
+ [MessageEntity(type="date_time", offset=0, length=4, unix_time=42)],
+ 'test',
+ ],
+ [
+ html_decoration,
+ "test",
+ [
+ MessageEntity(
+ type="date_time", offset=0, length=4, unix_time=42, date_time_format="yMd"
+ )
+ ],
+ 'test',
+ ],
],
)
def test_unparse(