Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecation warning for datetime.datetime.utcnow #939

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/saml2/time_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import calendar
from datetime import datetime
from datetime import timedelta
from datetime import UTC
import re
import sys
import time
Expand Down Expand Up @@ -175,7 +176,7 @@ def time_in_a_while(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0
:return: UTC time
"""
delta = timedelta(days, seconds, microseconds, milliseconds, minutes, hours, weeks)
return datetime.utcnow() + delta
return datetime.now(UTC) + delta


def time_a_while_ago(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0):
Expand All @@ -185,7 +186,7 @@ def time_a_while_ago(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=
minutes[, hours[, weeks]]]]]]])
"""
delta = timedelta(days, seconds, microseconds, milliseconds, minutes, hours, weeks)
return datetime.utcnow() - delta
return datetime.now(UTC) - delta


def in_a_while(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0, format=TIME_FORMAT):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_41_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_issuer_none(self):
@patch("saml2.time_util.datetime")
def test_false_sign(self, mock_datetime, caplog):
caplog.set_level(logging.ERROR)
mock_datetime.utcnow = Mock(return_value=datetime.datetime(2016, 9, 4, 9, 59, 39))
mock_datetime.now = Mock(return_value=datetime.datetime(2016, 9, 4, 9, 59, 39))
with open(FALSE_ASSERT_SIGNED) as fp:
xml_response = fp.read()

Expand Down