diff --git a/test/unit/files/test_drs.py b/test/unit/files/test_drs.py index 10c5ba89eeb8..704631f10472 100644 --- a/test/unit/files/test_drs.py +++ b/test/unit/files/test_drs.py @@ -45,15 +45,17 @@ def drs_repo_handler(request): content_type="application/json", ) + test_url = "drs://drs.example.org/314159" + def check_specific_header(request, **kwargs): assert request.full_url == "https://my.respository.org/myfile.txt" assert request.headers["Authorization"] == "Basic Z2E0Z2g6ZHJz" response: Any = io.StringIO("hello drs world") response.headers = {} + response.geturl = lambda: test_url return response with mock.patch.object(urllib.request, "urlopen", new=check_specific_header): - test_url = "drs://drs.example.org/314159" user_context = user_context_fixture() file_sources = configured_file_sources(FILE_SOURCES_CONF) file_source_pair = file_sources.get_file_source_path(test_url) diff --git a/test/unit/files/test_http.py b/test/unit/files/test_http.py index 5eebeaa2e9e8..9f3b090a34bc 100644 --- a/test/unit/files/test_http.py +++ b/test/unit/files/test_http.py @@ -20,14 +20,16 @@ def test_file_source_http_specific(): + test_url = "https://www.usegalaxy.org/myfile.txt" + def check_specific_header(request, **kwargs): assert request.headers["Authorization"] == "Bearer IBearTokens" response: Any = io.StringIO("hello specific world") response.headers = {} + response.geturl = lambda: test_url return response with mock.patch.object(urllib.request, "urlopen", new=check_specific_header): - test_url = "https://www.usegalaxy.org/myfile.txt" user_context = user_context_fixture() file_sources = configured_file_sources(FILE_SOURCES_CONF) file_source_pair = file_sources.get_file_source_path(test_url) @@ -39,14 +41,16 @@ def check_specific_header(request, **kwargs): def test_file_source_another_http_specific(): + test_url = "http://www.galaxyproject.org/anotherfile.txt" + def check_another_header(request, **kwargs): assert request.headers["Another_header"] == "found" response: Any = io.StringIO("hello another world") + response.geturl = lambda: test_url response.headers = {} return response with mock.patch.object(urllib.request, "urlopen", new=check_another_header): - test_url = "http://www.galaxyproject.org/anotherfile.txt" user_context = user_context_fixture() file_sources = configured_file_sources(FILE_SOURCES_CONF) file_source_pair = file_sources.get_file_source_path(test_url) @@ -58,14 +62,16 @@ def check_another_header(request, **kwargs): def test_file_source_http_generic(): + test_url = "https://www.elsewhere.org/myfile.txt" + def check_generic_headers(request, **kwargs): assert not request.headers response: Any = io.StringIO("hello generic world") response.headers = {} + response.geturl = lambda: test_url return response with mock.patch.object(urllib.request, "urlopen", new=check_generic_headers): - test_url = "https://www.elsewhere.org/myfile.txt" user_context = user_context_fixture() file_sources = configured_file_sources(FILE_SOURCES_CONF) file_source_pair = file_sources.get_file_source_path(test_url) @@ -77,14 +83,16 @@ def check_generic_headers(request, **kwargs): def test_file_source_ftp_url(): + test_url = "ftp://ftp.gnu.org/README" + def check_generic_headers(request, **kwargs): assert not request.headers response: Any = io.StringIO("This is ftp.gnu.org, the FTP server of the the GNU project.") response.headers = {} + response.geturl = lambda: test_url return response with mock.patch.object(urllib.request, "urlopen", new=check_generic_headers): - test_url = "ftp://ftp.gnu.org/README" user_context = user_context_fixture() file_sources = configured_file_sources(FILE_SOURCES_CONF) file_source_pair = file_sources.get_file_source_path(test_url) @@ -108,14 +116,16 @@ def test_file_source_http_without_stock_generic(): def test_file_source_http_without_stock_specific(): + test_url = "https://www.usegalaxy.org/myfile2.txt" + def check_specific_header(request, **kwargs): assert request.headers["Authorization"] == "Bearer IBearTokens" response: Any = io.StringIO("hello specific world 2") response.headers = {} + response.geturl = lambda: test_url return response with mock.patch.object(urllib.request, "urlopen", new=check_specific_header): - test_url = "https://www.usegalaxy.org/myfile2.txt" user_context = user_context_fixture() file_sources = configured_file_sources(FILE_SOURCES_CONF_WITHOUT_STOCK) file_source_pair = file_sources.get_file_source_path(test_url)