Skip to content

Commit

Permalink
Get rid of some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pypt committed Apr 27, 2020
1 parent 62dd39c commit 3867b6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
17 changes: 8 additions & 9 deletions tests/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import textwrap
from decimal import Decimal
from email.utils import format_datetime
from http import HTTPStatus
from unittest import TestCase

import dateutil
import requests_mock
from dateutil.tz import tzoffset

from tests.helpers import gzip
from usp.log import create_logger
Expand Down Expand Up @@ -43,7 +42,7 @@ class TestSitemapTree(TestCase):
# Publication / "last modified" date
TEST_DATE_DATETIME = datetime.datetime(
year=2009, month=12, day=17, hour=12, minute=4, second=56,
tzinfo=dateutil.tz.tzoffset(None, 7200),
tzinfo=tzoffset(None, 7200),
)
TEST_DATE_STR_ISO8601 = TEST_DATE_DATETIME.isoformat()
"""Test string date formatted as ISO 8601 (for XML and Atom 0.3 / 1.0 sitemaps)."""
Expand All @@ -59,8 +58,8 @@ def fallback_to_404_not_found_matcher(request):
"""Reply with "404 Not Found" to unmatched URLs instead of throwing NoMockAddress."""
return requests_mock.create_response(
request,
status_code=HTTPStatus.NOT_FOUND.value,
reason=HTTPStatus.NOT_FOUND.phrase,
status_code=404,
reason='Not Found',
headers={'Content-Type': 'text/html'},
text="<h1>404 Not Found!</h1>",
)
Expand Down Expand Up @@ -276,8 +275,8 @@ def test_sitemap_tree_for_homepage(self):
# Nonexistent sitemap
m.get(
self.TEST_BASE_URL + '/sitemap_news_missing.xml',
status_code=HTTPStatus.NOT_FOUND.value,
reason=HTTPStatus.NOT_FOUND.phrase,
status_code=404,
reason='Not Found',
headers={'Content-Type': 'text/html'},
text="<h1>404 Not Found!</h1>",
)
Expand Down Expand Up @@ -1177,8 +1176,8 @@ def test_sitemap_tree_for_homepage_no_robots_txt(self):
# Nonexistent robots.txt
m.get(
self.TEST_BASE_URL + '/robots.txt',
status_code=HTTPStatus.NOT_FOUND.value,
reason=HTTPStatus.NOT_FOUND.phrase,
status_code=404,
reason='Not Found',
headers={'Content-Type': 'text/html'},
text="<h1>404 Not Found!</h1>",
)
Expand Down
14 changes: 7 additions & 7 deletions usp/web_client/abstract_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@
RETRYABLE_HTTP_STATUS_CODES = {

# Some servers return "400 Bad Request" initially but upon retry start working again, no idea why
HTTPStatus.BAD_REQUEST.value,
int(HTTPStatus.BAD_REQUEST),

# If we timed out requesting stuff, we can just try again
HTTPStatus.REQUEST_TIMEOUT.value,
int(HTTPStatus.REQUEST_TIMEOUT),

# If we got rate limited, it makes sense to wait a bit
HTTPStatus.TOO_MANY_REQUESTS.value,
int(HTTPStatus.TOO_MANY_REQUESTS),

# Server might be just fine on a subsequent attempt
HTTPStatus.INTERNAL_SERVER_ERROR.value,
int(HTTPStatus.INTERNAL_SERVER_ERROR),

# Upstream might reappear on a retry
HTTPStatus.BAD_GATEWAY.value,
int(HTTPStatus.BAD_GATEWAY),

# Service might become available again on a retry
HTTPStatus.SERVICE_UNAVAILABLE.value,
int(HTTPStatus.SERVICE_UNAVAILABLE),

# Upstream might reappear on a retry
HTTPStatus.GATEWAY_TIMEOUT.value,
int(HTTPStatus.GATEWAY_TIMEOUT),

# (unofficial) 509 Bandwidth Limit Exceeded (Apache Web Server/cPanel)
509,
Expand Down

0 comments on commit 3867b6e

Please sign in to comment.