mirror of
https://github.com/caronc/apprise.git
synced 2025-08-10 16:58:00 +02:00
Use aware UTC datetimes internally (#887)
In lieu of Python v3.12 deprecation warnings
This commit is contained in:
@ -39,6 +39,7 @@ from unittest import mock
|
||||
from json import dumps
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
from datetime import timezone
|
||||
|
||||
# Disable logging for a cleaner testing output
|
||||
import logging
|
||||
@ -250,7 +251,7 @@ def test_plugin_reddit_general(mock_post):
|
||||
}
|
||||
|
||||
# Epoch time:
|
||||
epoch = datetime.utcfromtimestamp(0)
|
||||
epoch = datetime.fromtimestamp(0, timezone.utc)
|
||||
|
||||
good_response = mock.Mock()
|
||||
good_response.content = dumps({
|
||||
@ -267,7 +268,8 @@ def test_plugin_reddit_general(mock_post):
|
||||
})
|
||||
good_response.status_code = requests.codes.ok
|
||||
good_response.headers = {
|
||||
'X-RateLimit-Reset': (datetime.utcnow() - epoch).total_seconds(),
|
||||
'X-RateLimit-Reset': (
|
||||
datetime.now(timezone.utc) - epoch).total_seconds(),
|
||||
'X-RateLimit-Remaining': 1,
|
||||
}
|
||||
|
||||
@ -296,7 +298,8 @@ def test_plugin_reddit_general(mock_post):
|
||||
|
||||
# Force a case where there are no more remaining posts allowed
|
||||
good_response.headers = {
|
||||
'X-RateLimit-Reset': (datetime.utcnow() - epoch).total_seconds(),
|
||||
'X-RateLimit-Reset': (
|
||||
datetime.now(timezone.utc) - epoch).total_seconds(),
|
||||
'X-RateLimit-Remaining': 0,
|
||||
}
|
||||
# behind the scenes, it should cause us to update our rate limit
|
||||
@ -305,7 +308,8 @@ def test_plugin_reddit_general(mock_post):
|
||||
|
||||
# This should cause us to block
|
||||
good_response.headers = {
|
||||
'X-RateLimit-Reset': (datetime.utcnow() - epoch).total_seconds(),
|
||||
'X-RateLimit-Reset': (
|
||||
datetime.now(timezone.utc) - epoch).total_seconds(),
|
||||
'X-RateLimit-Remaining': 10,
|
||||
}
|
||||
assert obj.send(body="test") is True
|
||||
@ -319,7 +323,8 @@ def test_plugin_reddit_general(mock_post):
|
||||
|
||||
# Reset our variable back to 1
|
||||
good_response.headers = {
|
||||
'X-RateLimit-Reset': (datetime.utcnow() - epoch).total_seconds(),
|
||||
'X-RateLimit-Reset': (
|
||||
datetime.now(timezone.utc) - epoch).total_seconds(),
|
||||
'X-RateLimit-Remaining': 1,
|
||||
}
|
||||
# Handle cases where our epoch time is wrong
|
||||
@ -328,7 +333,8 @@ def test_plugin_reddit_general(mock_post):
|
||||
|
||||
# Return our object, but place it in the future forcing us to block
|
||||
good_response.headers = {
|
||||
'X-RateLimit-Reset': (datetime.utcnow() - epoch).total_seconds() + 1,
|
||||
'X-RateLimit-Reset': (
|
||||
datetime.now(timezone.utc) - epoch).total_seconds() + 1,
|
||||
'X-RateLimit-Remaining': 0,
|
||||
}
|
||||
|
||||
@ -337,7 +343,8 @@ def test_plugin_reddit_general(mock_post):
|
||||
|
||||
# Return our object, but place it in the future forcing us to block
|
||||
good_response.headers = {
|
||||
'X-RateLimit-Reset': (datetime.utcnow() - epoch).total_seconds() - 1,
|
||||
'X-RateLimit-Reset': (
|
||||
datetime.now(timezone.utc) - epoch).total_seconds() - 1,
|
||||
'X-RateLimit-Remaining': 0,
|
||||
}
|
||||
assert obj.send(body="test") is True
|
||||
@ -348,7 +355,8 @@ def test_plugin_reddit_general(mock_post):
|
||||
# Invalid JSON
|
||||
response = mock.Mock()
|
||||
response.headers = {
|
||||
'X-RateLimit-Reset': (datetime.utcnow() - epoch).total_seconds(),
|
||||
'X-RateLimit-Reset': (
|
||||
datetime.now(timezone.utc) - epoch).total_seconds(),
|
||||
'X-RateLimit-Remaining': 1,
|
||||
}
|
||||
response.content = '{'
|
||||
@ -393,7 +401,8 @@ def test_plugin_reddit_general(mock_post):
|
||||
})
|
||||
good_response.status_code = requests.codes.ok
|
||||
good_response.headers = {
|
||||
'X-RateLimit-Reset': (datetime.utcnow() - epoch).total_seconds(),
|
||||
'X-RateLimit-Reset': (
|
||||
datetime.now(timezone.utc) - epoch).total_seconds(),
|
||||
'X-RateLimit-Remaining': 1,
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user