Skip to content

Commit f2c5a48

Browse files
committed
Merge branch 'master' into latest-skeleton
2 parents 0fca296 + 5eab0dc commit f2c5a48

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/fetchcode/package.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

5252
def get_pypi_bugtracker_url(project_urls):

tests/test_package.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# specific language governing permissions and limitations under the License.
1616

1717
import json
18+
import pytest
1819
from unittest import mock
1920

2021
from 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

0 commit comments

Comments
 (0)