Skip to content

Commit

Permalink
Prevent real network requests in TLS cleanup test (#3715)
Browse files Browse the repository at this point in the history
* Prevent real network requests in TLS cleanup test

* Pre-populate tldextract cache to prevent in-test network requests
  • Loading branch information
sarayourfriend authored Jan 29, 2024
1 parent 47a9a26 commit 6f2cc97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ingestion_server/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 { "" } }}

Expand Down
9 changes: 5 additions & 4 deletions ingestion_server/test/unit_tests/test_cleanup.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -42,14 +41,16 @@ def test_accuracy_filter():
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
Expand Down

0 comments on commit 6f2cc97

Please sign in to comment.