Skip to content

Commit

Permalink
Fix utcnow calls ahead of 3.12 deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
gcoxmoz committed Dec 28, 2023
1 parent 09adc18 commit ad08992
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 5 deletions.
4 changes: 1 addition & 3 deletions duo_openvpn_mozilla/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import json
import syslog
import configparser
import pytz
import iamvpnlibrary
from duo_openvpn_mozilla.duo_auth import DuoAPIAuth
from duo_openvpn_mozilla.openvpn_credentials import OpenVPNCredentials
Expand Down Expand Up @@ -117,8 +116,7 @@ def log(self, summary, details, severity):
'processid': os.getpid(),
'severity': severity,
'processname': sys.argv[0],
# Have to use pytz because py2 is terrible here.
'timestamp': pytz.timezone('UTC').localize(datetime.datetime.utcnow()).isoformat(),
'timestamp': datetime.datetime.now(datetime.timezone.utc).isoformat(),
'details': details,
'hostname': socket.getfqdn(),
'summary': summary,
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def _minimal_ext_cmd(cmd):
install_requires=[
'iamvpnlibrary>=0.10.0',
'duo_client>=3.3.0',
'pytz',
],
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_duo_openvpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def test_10_log_nosend(self):
def test_11_log_send(self):
''' Test the log method tries to send '''
datetime_mock = mock.Mock(wraps=datetime.datetime)
datetime_mock.utcnow.return_value = datetime.datetime(2020, 12, 25, 13, 14, 15, 123456)
datetime_mock.now.return_value = datetime.datetime(2020, 12, 25, 13, 14, 15, 123456, tzinfo=datetime.timezone.utc)
self.library.event_send = True
self.library.event_facility = syslog.LOG_LOCAL1
with mock.patch('syslog.openlog') as mock_openlog, \
Expand Down

0 comments on commit ad08992

Please sign in to comment.