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):
43
43
Generate `Package` object for a `url` string
44
44
"""
45
45
resp = requests .get (url )
46
- if "json" in dir ( resp ) :
46
+ if resp . status_code == 200 :
47
47
return resp .json ()
48
48
49
- raise Exception ("Response of this URL does not contain json object " )
49
+ raise Exception (f"Failed to fetch: { url } " )
50
50
51
51
52
52
def get_pypi_bugtracker_url (project_urls ):
Original file line number Diff line number Diff line change 15
15
# specific language governing permissions and limitations under the License.
16
16
17
17
import json
18
+ import pytest
18
19
from unittest import mock
19
20
20
21
from fetchcode .package import info
@@ -97,3 +98,11 @@ def test_rubygems_packages(mock_get):
97
98
mock_get .side_effect = side_effect
98
99
packages = list (info (purl ))
99
100
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