|
25 | 25 | import unittest |
26 | 26 | from unittest.case import expectedFailure |
27 | 27 |
|
28 | | -from testing_utils import extract_test_loc |
29 | | -from testing_utils import get_temp_file |
30 | | -from testing_utils import get_test_loc |
31 | | -from testing_utils import get_test_lines |
32 | | -from testing_utils import get_unicode_content |
| 28 | +import mock |
33 | 29 |
|
34 | 30 | import attributecode |
35 | 31 | from attributecode import CRITICAL |
|
41 | 37 | from attributecode import util |
42 | 38 | from attributecode.util import add_unc |
43 | 39 | from attributecode.util import load_csv |
| 40 | +from testing_utils import extract_test_loc |
| 41 | +from testing_utils import get_temp_file |
| 42 | +from testing_utils import get_test_loc |
| 43 | +from testing_utils import get_test_lines |
| 44 | +from testing_utils import get_unicode_content |
44 | 45 |
|
45 | 46 |
|
46 | 47 | def check_csv(expected, result): |
@@ -1313,3 +1314,25 @@ def test_by_name(self): |
1313 | 1314 | ('eclipse', [d]), |
1314 | 1315 | ]) |
1315 | 1316 | assert expected == results |
| 1317 | + |
| 1318 | + |
| 1319 | +class FetchLicenseTest(unittest.TestCase): |
| 1320 | + @mock.patch.object(model, 'urlopen') |
| 1321 | + def test_valid_api_url(self, mock_data): |
| 1322 | + mock_data.return_value = '' |
| 1323 | + assert model.valid_api_url('non_valid_url') is False |
| 1324 | + |
| 1325 | + @mock.patch('attributecode.util.have_network_connection') |
| 1326 | + @mock.patch('attributecode.model.valid_api_url') |
| 1327 | + def test_pre_process_and_fetch_license_dict(self, have_network_connection, valid_api_url): |
| 1328 | + have_network_connection.return_value = True |
| 1329 | + |
| 1330 | + valid_api_url.return_value = False |
| 1331 | + error_msg = ('Network problem. Please check your Internet connection. ' |
| 1332 | + 'License generation is skipped.') |
| 1333 | + expected = ({}, [Error(ERROR, error_msg)]) |
| 1334 | + assert model.pre_process_and_fetch_license_dict([], '', '') == expected |
| 1335 | + |
| 1336 | + valid_api_url.return_value = True |
| 1337 | + expected = ({}, []) |
| 1338 | + assert model.pre_process_and_fetch_license_dict([], '', '') == expected |
0 commit comments