Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Prevent real network requests in TLS cleanup test (#3715)

sarayourfriend6f2cc97accde
diff --git a/ingestion_server/justfile b/ingestion_server/justfile
index fda1656fc..10c082f67 100644
--- a/ingestion_server/justfile
+++ b/ingestion_server/justfile
@@ -99,6 +99,9 @@ create-and-populate-filtered-index model="image" destination_suffix="init":
# Run ingestion-server tests locally
test-local *args:
+ # populate the tldextract cache before running tests to prevent unnecessary network requests during tests
+ # and from needing to mock essentially unmockable responses
+ pipenv run tldextract --update
pipenv run pytest {{ args }}
{{ if IS_CI == "" { "just test-logs > test/ingestion_logs.txt && just test-clean-dc" } else { "" } }}
diff --git a/ingestion_server/test/unit_tests/test_cleanup.py b/ingestion_server/test/unit_tests/test_cleanup.py
index e8b8dcc10..696a873c0 100644
--- a/ingestion_server/test/unit_tests/test_cleanup.py
+++ b/ingestion_server/test/unit_tests/test_cleanup.py
@@ -1,8 +1,7 @@
-from unittest.mock import MagicMock
-
+import pook
from psycopg2._json import Json
-from ingestion_server.cleanup import CleanupFunctions, TlsTest
+from ingestion_server.cleanup import CleanupFunctions
from test.unit_tests.conftest import create_mock_image
@@ -42,14 +41,16 @@ class TestCleanup:
assert result == expected
@staticmethod
+ @pook.on
def test_url_protocol_fix():
bad_url = "flickr.com"
tls_support_cache = {}
+ pook.get("https://flickr.com").reply(200)
result = CleanupFunctions.cleanup_url(bad_url, tls_support_cache)
expected = "'https://flickr.com'"
bad_http = "neverssl.com"
- TlsTest.test_tls_supported = MagicMock(return_value=False)
+ pook.get("https://neverssl.com").reply(500)
result_http = CleanupFunctions.cleanup_url(bad_http, tls_support_cache)
expected_http = "'http://neverssl.com'"
assert result == expected