mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-13 02:25:38 +00:00
Improvements for image download helper
This commit is contained in:
@ -275,8 +275,10 @@ class TestHelpers(TestCase):
|
|||||||
we will simply try multiple times
|
we will simply try multiple times
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
tries = 0
|
||||||
|
|
||||||
with self.assertRaises(expected_error):
|
with self.assertRaises(expected_error):
|
||||||
while retries > 0:
|
while tries < retries:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
helpers.download_image_from_url(url, timeout=timeout)
|
helpers.download_image_from_url(url, timeout=timeout)
|
||||||
@ -285,9 +287,11 @@ class TestHelpers(TestCase):
|
|||||||
if type(exc) is expected_error:
|
if type(exc) is expected_error:
|
||||||
# Re-throw this error
|
# Re-throw this error
|
||||||
raise exc
|
raise exc
|
||||||
|
else:
|
||||||
|
print("Unexpected error:", type(exc), exc)
|
||||||
|
|
||||||
time.sleep(30)
|
tries += 1
|
||||||
retries -= 1
|
time.sleep(10 * tries)
|
||||||
|
|
||||||
# Attempt to download an image which throws a 404
|
# Attempt to download an image which throws a 404
|
||||||
dl_helper("https://httpstat.us/404", requests.exceptions.HTTPError, timeout=10)
|
dl_helper("https://httpstat.us/404", requests.exceptions.HTTPError, timeout=10)
|
||||||
@ -295,9 +299,6 @@ class TestHelpers(TestCase):
|
|||||||
# Attempt to download, but timeout
|
# Attempt to download, but timeout
|
||||||
dl_helper("https://httpstat.us/200?sleep=5000", requests.exceptions.ReadTimeout, timeout=1)
|
dl_helper("https://httpstat.us/200?sleep=5000", requests.exceptions.ReadTimeout, timeout=1)
|
||||||
|
|
||||||
# Attempt to download, but not a valid image
|
|
||||||
dl_helper("https://httpstat.us/200", TypeError, timeout=10)
|
|
||||||
|
|
||||||
large_img = "https://github.com/inventree/InvenTree/raw/master/InvenTree/InvenTree/static/img/paper_splash_large.jpg"
|
large_img = "https://github.com/inventree/InvenTree/raw/master/InvenTree/InvenTree/static/img/paper_splash_large.jpg"
|
||||||
|
|
||||||
InvenTreeSetting.set_setting('INVENTREE_DOWNLOAD_IMAGE_MAX_SIZE', 1, change_user=None)
|
InvenTreeSetting.set_setting('INVENTREE_DOWNLOAD_IMAGE_MAX_SIZE', 1, change_user=None)
|
||||||
|
Reference in New Issue
Block a user