From 18cbd8fa0c6f49eeaf9ec73d2f3e66de57dd64dd Mon Sep 17 00:00:00 2001 From: buttonfly1000 <2255715+buttonfly1000@users.noreply.github.com> Date: Wed, 2 Oct 2024 13:36:36 +0800 Subject: [PATCH] Fixed failed unit tests caused by using `pytz` inappropriately As per the document https://pythonhosted.org/pytz/ : `Unfortunately using the tzinfo argument of the standard datetime constructors 'does not work' with pytz for many timezones`. This fixes https://github.com/python-restx/flask-restx/issues/620 --- tests/test_fields.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/test_fields.py b/tests/test_fields.py index 8b449887..f58afb7a 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1,5 +1,5 @@ from collections import OrderedDict -from datetime import date, datetime +from datetime import date, datetime, timedelta, timezone from decimal import Decimal from functools import partial @@ -10,6 +10,9 @@ from flask_restx import fields, Api +_CET_TIMEZONE = timezone(timedelta(hours=1), "CET") + + class FieldTestCase(object): field_class = None @@ -542,7 +545,7 @@ def test_max_exclusive(self): "Sat, 01 Jan 2011 23:59:59 -0000", ), ( - datetime(2011, 1, 1, 23, 59, 59, tzinfo=pytz.timezone("CET")), + datetime(2011, 1, 1, 23, 59, 59, tzinfo=_CET_TIMEZONE), "Sat, 01 Jan 2011 22:59:59 -0000", ), ], @@ -566,7 +569,7 @@ def test_rfc822_value(self, value, expected): "2011-01-01T23:59:59.001000+00:00", ), ( - datetime(2011, 1, 1, 23, 59, 59, tzinfo=pytz.timezone("CET")), + datetime(2011, 1, 1, 23, 59, 59, tzinfo=_CET_TIMEZONE), "2011-01-01T23:59:59+01:00", ), ], @@ -676,7 +679,7 @@ def test_max_exclusive(self): (datetime(2011, 1, 1, 23, 59, 59, tzinfo=pytz.utc), "2011-01-01"), (datetime(2011, 1, 1, 23, 59, 59, 1000, tzinfo=pytz.utc), "2011-01-01"), ( - datetime(2011, 1, 1, 23, 59, 59, tzinfo=pytz.timezone("CET")), + datetime(2011, 1, 1, 23, 59, 59, tzinfo=_CET_TIMEZONE), "2011-01-01", ), ],