def test_get_latest_version(): from unittest import mock pypi_mock_releases = { 'releases': { '2.0.0': [], '2.0.0rc3': [], '2.0.1': [], '2.1.0': [], '2.2.1': [], '2.9.0b1': [], '2.9.1': [], '3.0.2': [], '2.9.2': [], '2.9.3': [], '2.9.4': [], '3.0.0': [], } } def jget(*args, **kwargs): return pypi_mock_releases with mock.patch('requests.get') as mock_get: mock_get.return_value = mock.Mock( json=jget, status_code=200 ) result = outdated.get_latest_version() assert '3.0.2' == result
def test_get_latest_version_fails_on_http_error(): from unittest import mock with mock.patch('requests.get') as mock_get: mock_get.return_value = mock.Mock(status_code=400) with pytest.raises(Exception): outdated.get_latest_version()