1414# limitations under the License.
1515# ============================================================================
1616
17+ import requests
1718import unittest
1819from unittest import mock
1920
@@ -27,6 +28,7 @@ class FakeResponse(object):
2728
2829 def __init__ (self , response_content ):
2930 self .response_content = response_content
31+ self .text = response_content
3032
3133 def read (self ):
3234 return self .response_content
@@ -44,12 +46,13 @@ def test_api_get_license_details_from_api(self, request_license_data):
4446 errors = []
4547 request_license_data .return_value = license_data , errors
4648
47- expected = ({'short_name' : 'Apache 2.0' , 'full_text' : 'Apache License Version 2.0 ...' , 'key' : 'apache-2.0' }, [])
49+ expected = ({'short_name' : 'Apache 2.0' ,
50+ 'full_text' : 'Apache License Version 2.0 ...' , 'key' : 'apache-2.0' }, [])
4851 result = api .get_license_details_from_api (
4952 api_url = 'api_url' , api_key = 'api_key' , license_key = 'license_key' )
5053 assert expected == result
5154
52- @mock .patch .object (api , 'urlopen ' )
55+ @mock .patch .object (api , 'get ' )
5356 def test_api_request_license_data_with_result (self , mock_data ):
5457 response_content = (
5558 b'{"count":1,"results":[{"name":"Apache 2.0","key":"apache-2.0","text":"Text"}]}'
@@ -63,7 +66,7 @@ def test_api_request_license_data_with_result(self, mock_data):
6366 )
6467 assert expected == license_data
6568
66- @mock .patch .object (api , 'urlopen ' )
69+ @mock .patch .object (api , 'get ' )
6770 def test_api_request_license_data_without_result (self , mock_data ):
6871 response_content = b'{"count":0,"results":[]}'
6972 mock_data .return_value = FakeResponse (response_content )
@@ -79,5 +82,6 @@ def test_api_request_license_data_with_incorrect_url(self, mock_data):
7982 mock_data .return_value = FakeResponse (response_content )
8083 license_data = api .request_license_data (
8184 api_url = 'http://fake.url/' , api_key = 'api_key' , license_key = 'apache-2.0' )
82- expected = ({}, [Error (ERROR , "Invalid '--api_url'. License generation is skipped." )])
85+ expected = (
86+ {}, [Error (ERROR , "Invalid '--api_url'. License generation is skipped." )])
8387 assert expected == license_data
0 commit comments