@@ -42,6 +42,7 @@ def test_scanpipe_pipes_fetch_get_fetcher(self):
4242 git_http_url = "https://github.com/aboutcode-org/scancode.io.git"
4343 self .assertEqual (fetch .fetch_git_repo , fetch .get_fetcher (git_http_url ))
4444 self .assertEqual (fetch .fetch_git_repo , fetch .get_fetcher (git_http_url + "/" ))
45+ self .
assertEqual (
fetch .
fetch_package_url ,
fetch .
get_fetcher (
"pkg:npm/[email protected] " ))
4546
4647 with self .assertRaises (ValueError ) as cm :
4748 fetch .get_fetcher ("" )
@@ -88,6 +89,25 @@ def test_scanpipe_pipes_fetch_http(self, mock_get):
8889 downloaded_file = fetch .fetch_http (url )
8990 self .assertTrue (Path (downloaded_file .directory , "another_name.zip" ).exists ())
9091
92+ @mock .patch ("requests.sessions.Session.get" )
93+ def test_scanpipe_pipes_fetch_package_url (self , mock_get ):
94+ package_url = "pkg:not_a_valid_purl"
95+ with self .assertRaises (ValueError ) as cm :
96+ fetch .fetch_package_url (package_url )
97+ expected = f"purl is missing the required type component: '{ package_url } '."
98+ self .assertEqual (expected , str (cm .exception ))
99+
100+ package_url = "pkg:generic/name@version"
101+ with self .assertRaises (ValueError ) as cm :
102+ fetch .fetch_package_url (package_url )
103+ expected = f"Could not resolve a download URL for { package_url } ."
104+ self .assertEqual (expected , str (cm .exception ))
105+
106+ package_url = "pkg:npm/[email protected] " 107+ mock_get .return_value = make_mock_response (url = "https://exa.com/filename.zip" )
108+ downloaded_file = fetch .fetch_package_url (package_url )
109+ self .assertTrue (Path (downloaded_file .directory , "filename.zip" ).exists ())
110+
91111 @mock .patch ("scanpipe.pipes.fetch.get_docker_image_platform" )
92112 @mock .patch ("scanpipe.pipes.fetch._get_skopeo_location" )
93113 @mock .patch ("scanpipe.pipes.fetch.run_command_safely" )
0 commit comments