Use timezone-aware reset datetime in GithubRetry.py (#2610)

Co-authored-by: Patryk Szulczyk <patryk.szulczyk@skyscanner.net>
Co-authored-by: Enrico Minack <github@enrico.minack.dev>
This commit is contained in:
Patryk Szulczyk
2023-07-07 09:05:48 +02:00
committed by GitHub
co-authored by Patryk Szulczyk Enrico Minack
parent 5fcb0c7d3b
commit 950a69493f
2 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -137,8 +137,8 @@ class GithubRetry(Retry):
if "X-RateLimit-Reset" in response.headers:
value = response.headers.get("X-RateLimit-Reset")
if value and value.isdigit():
reset = self.__datetime.utcfromtimestamp(
int(value)
reset = self.__datetime.fromtimestamp(
int(value), timezone.utc
)
delta = reset - self.__datetime.now(
timezone.utc
+3 -3
View File
@@ -95,7 +95,7 @@ class GithubRetry(unittest.TestCase):
mock.call(20, "Request TEST URL failed with 403: None"),
mock.call(10, f"Response body indicates retry-able {'primary' if is_primary else 'secondary'} rate limit error: {expected_rate_limit_error}"),
] + ([
mock.call(10, "Reset occurs in 0:00:12 (1644768012 / 2022-02-13 16:00:12)")
mock.call(10, "Reset occurs in 0:00:12 (1644768012 / 2022-02-13 16:00:12+00:00)")
] if has_reset else []) + ([
mock.call(10, f"Retry backoff of {expected_retry_backoff}s exceeds required rate limit backoff of {expected_backoff}s")
] if expected_retry_backoff and expected_backoff > 0 else []) + ([
@@ -132,8 +132,8 @@ class GithubRetry(unittest.TestCase):
else:
attr = "github.GithubRetry._GithubRetry__datetime"
with mock.patch(attr) as dt:
dt.now = mock.Mock(return_value=datetime.utcfromtimestamp(now))
dt.utcfromtimestamp = datetime.utcfromtimestamp
dt.now = lambda tz=None: datetime.fromtimestamp(now, tz=tz)
dt.fromtimestamp = datetime.fromtimestamp
yield
def test_primary_rate_error_with_reset(self):