File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -43,10 +43,10 @@ def get_response(url):
4343 Generate `Package` object for a `url` string
4444 """
4545 resp = requests .get (url )
46- if "json" in dir ( resp ) :
46+ if resp . status_code == 200 :
4747 return resp .json ()
4848
49- raise Exception ("Response of this URL does not contain json object " )
49+ raise Exception (f"Failed to fetch: { url } " )
5050
5151
5252def get_pypi_bugtracker_url (project_urls ):
Original file line number Diff line number Diff line change 1515# specific language governing permissions and limitations under the License.
1616
1717import json
18+ import pytest
1819from unittest import mock
1920
2021from fetchcode .package import info
@@ -97,3 +98,11 @@ def test_rubygems_packages(mock_get):
9798 mock_get .side_effect = side_effect
9899 packages = list (info (purl ))
99100 match_data (packages , expected_data )
101+
102+
103+ @mock .patch ("fetchcode.package.get_response" )
104+ def test_tuby_package_with_invalid_url (mock_get ):
105+ with pytest .raises (Exception ) as e_info :
106+ purl = "pkg:ruby/file"
107+ packages = list (info (purl ))
108+ assert "Failed to fetch: https://rubygems.org/api/v1/gems/file.json" == e_info
You can’t perform that action at this time.
0 commit comments