@@ -43,6 +43,7 @@ def test_scanpipe_pipes_fetch_get_fetcher(self):
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 + "/" ))
4545 self .assertEqual (fetch .fetch_package_url , fetch .get_fetcher ("pkg:npm/d3@5.8.0" ))
46+ self .assertEqual (fetch .fetch_package_url , fetch .get_fetcher ("pkg:pypi/django" ))
4647
4748 with self .assertRaises (ValueError ) as cm :
4849 fetch .get_fetcher ("" )
@@ -108,6 +109,19 @@ def test_scanpipe_pipes_fetch_package_url(self, mock_get):
108109 downloaded_file = fetch .fetch_package_url (package_url )
109110 self .assertTrue (Path (downloaded_file .directory , "filename.zip" ).exists ())
110111
112+ @mock .patch ("fetchcode.pypi.fetch_json_response" )
113+ @mock .patch ("requests.sessions.Session.get" )
114+ def test_scanpipe_pipes_fetch_pypi_package_url (self , mock_get , mock_fetch_json ):
115+ package_url = "pkg:pypi/django@5.2"
116+ download_url = "https://files.pythonhosted.org/packages/Django-5.2.tar.gz"
117+
118+ mock_get .return_value = make_mock_response (url = download_url )
119+ mock_fetch_json .return_value = {"urls" : [{"url" : download_url }]}
120+
121+ downloaded_file = fetch .fetch_package_url (package_url )
122+ self .assertEqual (download_url , mock_get .call_args [0 ][0 ])
123+ self .assertTrue (Path (downloaded_file .directory , "Django-5.2.tar.gz" ).exists ())
124+
111125 @mock .patch ("scanpipe.pipes.fetch.get_docker_image_platform" )
112126 @mock .patch ("scanpipe.pipes.fetch._get_skopeo_location" )
113127 @mock .patch ("scanpipe.pipes.fetch.run_command_safely" )
0 commit comments