mirror of
https://github.com/bellingcat/auto-archiver.git
synced 2026-06-08 03:18:28 +03:00
adds an extra check when calling pypi as it's led to uncaught ssl errors
This commit is contained in:
@@ -467,7 +467,11 @@ Here's how that would look: \n\nsteps:\n extractors:\n - [your_extractor_name_
|
|||||||
return self.setup_complete_parser(basic_config, yaml_config, unused_args)
|
return self.setup_complete_parser(basic_config, yaml_config, unused_args)
|
||||||
|
|
||||||
def check_for_updates(self):
|
def check_for_updates(self):
|
||||||
response = requests.get("https://pypi.org/pypi/auto-archiver/json").json()
|
try:
|
||||||
|
response = requests.get("https://pypi.org/pypi/auto-archiver/json", timeout=10).json()
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug(f"Unable to check for updates: {e}")
|
||||||
|
return
|
||||||
latest_version = version.parse(response["info"]["version"])
|
latest_version = version.parse(response["info"]["version"])
|
||||||
current_version = version.parse(__version__)
|
current_version = version.parse(__version__)
|
||||||
# check version compared to current version
|
# check version compared to current version
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from argparse import ArgumentParser, ArgumentTypeError
|
from argparse import ArgumentParser, ArgumentTypeError
|
||||||
|
from requests.exceptions import SSLError
|
||||||
from auto_archiver.core.orchestrator import ArchivingOrchestrator
|
from auto_archiver.core.orchestrator import ArchivingOrchestrator
|
||||||
from auto_archiver.version import __version__
|
from auto_archiver.version import __version__
|
||||||
from auto_archiver.core.config import read_yaml, store_yaml
|
from auto_archiver.core.config import read_yaml, store_yaml
|
||||||
@@ -256,3 +257,34 @@ def test_load_failed_extractor_cleanup(test_args, mocker, caplog):
|
|||||||
assert "Error during setup of modules: Test exception" in caplog.text
|
assert "Error during setup of modules: Test exception" in caplog.text
|
||||||
# make sure the 'cleanup' is called
|
# make sure the 'cleanup' is called
|
||||||
assert "cleanup" in caplog.text
|
assert "cleanup" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_for_updates_ssl_error(orchestrator, mocker):
|
||||||
|
"""check_for_updates should not raise when the HTTP request fails."""
|
||||||
|
mocker.patch(
|
||||||
|
"auto_archiver.core.orchestrator.requests.get",
|
||||||
|
side_effect=SSLError("SSL handshake failed"),
|
||||||
|
)
|
||||||
|
# should not raise
|
||||||
|
orchestrator.check_for_updates()
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_for_updates_timeout(orchestrator, mocker):
|
||||||
|
"""check_for_updates should not raise on connection timeout."""
|
||||||
|
from requests.exceptions import ConnectionError
|
||||||
|
|
||||||
|
mocker.patch(
|
||||||
|
"auto_archiver.core.orchestrator.requests.get",
|
||||||
|
side_effect=ConnectionError("Connection refused"),
|
||||||
|
)
|
||||||
|
orchestrator.check_for_updates()
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_for_updates_new_version_available(orchestrator, mocker):
|
||||||
|
"""check_for_updates should not raise when a newer version exists."""
|
||||||
|
mocker.patch(
|
||||||
|
"auto_archiver.core.orchestrator.requests.get",
|
||||||
|
return_value=mocker.Mock(json=lambda: {"info": {"version": "99.0.0"}}),
|
||||||
|
)
|
||||||
|
# should complete without error
|
||||||
|
orchestrator.check_for_updates()
|
||||||
|
|||||||
Reference in New Issue
Block a user