Image Status check
This commit is contained in:
@@ -244,6 +244,35 @@ def test_an_unlabelled_body_with_an_image_extension_is_accepted(monkeypatch):
|
||||
assert iv.download_image_bytes("https://cdn.example/p/1.jpg") == body
|
||||
|
||||
|
||||
def test_a_429_backs_off_for_retry_after_and_tries_again(monkeypatch):
|
||||
"""Wikimedia throttled the Own Products backfill after ~100 images; the
|
||||
URLs were fine. A 429 is a pause, not a failure."""
|
||||
body = b"x" * (iv.MIN_IMAGE_BYTES + 10)
|
||||
throttled = _Resp(429, b"")
|
||||
throttled.headers["retry-after"] = "2"
|
||||
_patch_requests(monkeypatch, [throttled, _Resp(200, body)])
|
||||
slept: List[float] = []
|
||||
monkeypatch.setattr(iv.time, "sleep", slept.append)
|
||||
|
||||
assert iv.download_image_bytes("https://upload.wikimedia.org/x.jpg") == body
|
||||
assert slept == [2.0]
|
||||
|
||||
|
||||
def test_a_persistent_429_gives_up_after_three_attempts(monkeypatch):
|
||||
calls = _patch_requests(monkeypatch, [_Resp(429, b""), _Resp(429, b""), _Resp(429, b"")])
|
||||
monkeypatch.setattr(iv.time, "sleep", lambda s: None)
|
||||
|
||||
assert iv.download_image_bytes("https://upload.wikimedia.org/x.jpg") is None
|
||||
assert len(calls) == 3
|
||||
|
||||
|
||||
def test_retry_after_is_capped_and_tolerates_garbage():
|
||||
assert iv._retry_after_seconds("3") == 3.0
|
||||
assert iv._retry_after_seconds("9999") == iv._RATE_LIMIT_BACKOFF_CAP_SECONDS
|
||||
assert iv._retry_after_seconds(None) == iv._RATE_LIMIT_BACKOFF_SECONDS
|
||||
assert iv._retry_after_seconds("Wed, 21 Oct 2026 07:28:00 GMT") == iv._RATE_LIMIT_BACKOFF_SECONDS
|
||||
|
||||
|
||||
def test_a_raised_request_is_none_not_an_exception(monkeypatch):
|
||||
import requests
|
||||
|
||||
|
||||
Reference in New Issue
Block a user