From 306a95954eeba2f533f49213c8c45e533f006ff8 Mon Sep 17 00:00:00 2001 From: Nick Merrill Date: Wed, 17 May 2023 11:07:38 -0400 Subject: [PATCH] Add test for datetime subclass --- tests/test_converters.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_converters.py b/tests/test_converters.py index 1b0f1d9..5d555ac 100644 --- a/tests/test_converters.py +++ b/tests/test_converters.py @@ -48,6 +48,15 @@ def test_default_values(): assert field.type == graphene.String assert field.default_value == "hi" +class DatetimeSubclass(datetime.datetime): + pass + +class TimeSubclass(datetime.time): + pass + +class DateSubclass(datetime.date): + pass + @pytest.mark.parametrize( "input, expected", @@ -60,6 +69,10 @@ def test_default_values(): ((datetime.date, datetime.date(2019, 1, 1)), graphene.Date), ((datetime.time, datetime.time(15, 29)), graphene.Time), ((datetime.datetime, datetime.datetime(2019, 1, 1, 1, 37)), graphene.DateTime), + # Tests support for datetime mocking libraries like Freezegun + ((DatetimeSubclass, DatetimeSubclass(2019, 1, 1, 1, 37)), graphene.DateTime), + ((DateSubclass, DateSubclass(2019, 1, 1)), graphene.Date), + ((TimeSubclass, TimeSubclass(15, 29)), graphene.Time), ], ) def test_builtin_scalars(input, expected):