def test_will_not_download_if_package_installed(self, mock_wget): cache = mock.MagicMock(spec=PackageCache) cache.is_package_installed.return_value = True packages = [{'name': 'package', 'version': '1.3.0', 'url': 'http://website.com/something.tar.gz'}, {'name': 'package4', 'version': '0.3.0', 'url': 'http://website.com/somethingElse.tar.gz'}] installer = UrlInstaller('myProject', packages, cache) mock_wget.download.return_value = 'file' installer.install_packages() mock_wget.assert_not_called()
def test_will_get_packages_and_download(self, mock_wget): cache = mock.MagicMock(spec = PackageCache) cache.is_package_installed.return_value = False packages = [{'name': 'package', 'version': '1.3.0', 'url': 'http://website.com/something.tar.gz'}, {'name': 'package4', 'version': '0.3.0', 'url': 'http://website.com/somethingElse.tar.gz'}] installer = UrlInstaller('myProject', packages, cache) mock_wget.download.return_value = 'file' installer.install_packages() download_file1 = os.path.join('.devenv', 'myProject', 'downloads', 'package-1.3.0.tar.gz') download_file2 = os.path.join('.devenv', 'myProject', 'downloads', 'package4-0.3.0.tar.gz') mock_wget.assert_any_call(packages[0]['url'], out=download_file1) mock_wget.assert_any_call(packages[1]['url'], out=download_file2)
def test_will_not_download_if_exists_in_downloads(self, mock_wget, mock_exists): cache = mock.MagicMock(spec = PackageCache) cache.is_package_installed.return_value = False packages = [{'name': 'package', 'version': '1.3.0', 'url': 'http://website.com/something.tar.gz'}, {'name': 'package4', 'version': '0.3.0', 'url': 'http://website.com/somethingElse.tar.gz'}] installer = UrlInstaller('myProject', packages, cache) mock_wget.download.return_value = 'file' download_file2 = os.path.join('.devenv', 'myProject', 'downloads', 'package4-0.3.0.tar.gz') def side_effect(file): if file == download_file2: return False return True mock_exists.side_effect = side_effect installer.install_packages() download_file2 = os.path.join('.devenv', 'myProject', 'downloads', 'package4-0.3.0.tar.gz') mock_wget.assert_called_once_with(packages[1]['url'], out=download_file2)