def test_download_fail(mock_command, tmp_path):
    "If the download doesn't complete, the upgrade fails"
    # Create a mock of a previously installed WiX version.
    wix_path = tmp_path / 'tools' / 'wix'
    wix_path.mkdir(parents=True)
    (wix_path / 'heat.exe').touch()
    (wix_path / 'light.exe').touch()
    (wix_path / 'candle.exe').touch()

    # Mock the download failure
    mock_command.download_url.side_effect = requests_exceptions.ConnectionError

    # Create an SDK wrapper
    wix = WiX(mock_command, wix_home=wix_path, bin_install=True)

    # Upgrade the install. This will trigger a download that will fail
    with pytest.raises(NetworkFailure):
        wix.upgrade()

    # A download was initiated
    mock_command.download_url.assert_called_with(
        url=WIX_DOWNLOAD_URL,
        download_path=tmp_path / 'tools',
    )

    # ... but the unpack didn't happen
    assert mock_command.shutil.unpack_archive.call_count == 0
def test_non_windows_host(mock_command):
    "If the host OS isn't Windows, the validator fails"

    # Set the host OS to something not Windows
    mock_command.host_os = 'Other OS'

    with pytest.raises(BriefcaseCommandError, match="can only be created on Windows"):
        WiX.verify(mock_command)
def test_invalid_wix_envvar(mock_command, tmp_path):
    "If the WiX envvar points to an invalid WiX install, the validator fails"
    # Mock the environment for a WiX install
    wix_path = tmp_path / 'wix'
    mock_command.os.environ.get.return_value = os.fsdecode(wix_path)

    # Don't create the actual install, and then attempt to validate
    with pytest.raises(BriefcaseCommandError, match="does not point to an install"):
        WiX.verify(mock_command)
def test_non_existing_wix_install(mock_command, tmp_path):
    "If there's no existing managed WiX install, upgrading is an error"
    # Create an SDK wrapper around a non-existing managed install
    wix = WiX(mock_command, wix_home=tmp_path / 'tools' / 'wix')

    with pytest.raises(MissingToolError):
        wix.upgrade()

    # No download was attempted
    assert mock_command.download_url.call_count == 0
def test_non_managed_install(mock_command, tmp_path, capsys):
    "If the WiX install points to a non-managed install, no upgrade is attempted"

    # Make the installation point to somewhere else.
    wix = WiX(mock_command, wix_home=tmp_path / 'other-WiX')

    # Attempt an upgrade. This will fail because the install is non-managed
    with pytest.raises(NonManagedToolError):
        wix.upgrade()

    # No download was attempted
    assert mock_command.download_url.call_count == 0
def test_dont_install(mock_command, tmp_path):
    "If there's no existing managed WiX install, an install is not requested, verify fails"
    # Mock the environment as if there is not WiX variable
    mock_command.os.environ.get.return_value = None

    # Verify, but don't install. This will fail.
    with pytest.raises(MissingToolError):
        WiX.verify(mock_command, install=False)

    # The environment was queried.
    mock_command.os.environ.get.assert_called_with('WIX')

    # No download was initiated
    mock_command.download_url.assert_not_called()
def test_existing_wix_install(mock_command, tmp_path):
    "If there's an existing managed WiX install, it is deleted and redownloaded"
    # Create a mock of a previously installed WiX version.
    wix_path = tmp_path / 'tools' / 'wix'
    wix_path.mkdir(parents=True)
    (wix_path / 'heat.exe').touch()
    (wix_path / 'light.exe').touch()
    (wix_path / 'candle.exe').touch()

    # Mock the download
    wix_path = tmp_path / 'tools' / 'wix'

    wix_zip_path = os.fsdecode(tmp_path / 'tools' / 'wix.zip')
    # Consider to remove if block when we drop py3.7 support, only keep statements from else.
    # MagicMock below py3.8 doesn't has __fspath__ attribute.
    if sys.version_info < (3, 8):
        wix_zip = FsPathMock(wix_zip_path)
    else:
        wix_zip = MagicMock()
        wix_zip.__fspath__.return_value = wix_zip_path

    mock_command.download_url.return_value = wix_zip

    # Create an SDK wrapper
    wix = WiX(mock_command, wix_home=wix_path, bin_install=True)

    # Attempt an upgrade.
    wix.upgrade()

    # The old version has been deleted
    mock_command.shutil.rmtree.assert_called_with(wix_path)

    # A download was initiated
    mock_command.download_url.assert_called_with(
        url=WIX_DOWNLOAD_URL,
        download_path=tmp_path / 'tools',
    )

    # The download was unpacked
    # TODO: Py3.6 compatibility; os.fsdecode not required in Py3.7
    mock_command.shutil.unpack_archive.assert_called_with(
        os.fsdecode(wix_zip_path),
        extract_dir=os.fsdecode(wix_path)
    )

    # The zip file was removed
    wix_zip.unlink.assert_called_with()
def test_unpack_fail(mock_command, tmp_path):
    "If the download archive is corrupted, the validator fails"
    # Create a mock of a previously installed WiX version.
    wix_path = tmp_path / 'tools' / 'wix'
    wix_path.mkdir(parents=True)
    (wix_path / 'heat.exe').touch()
    (wix_path / 'light.exe').touch()
    (wix_path / 'candle.exe').touch()

    # Mock the download
    wix_zip_path = os.fsdecode(tmp_path / 'tools' / 'wix.zip')
    # Consider to remove if block when we drop py3.7 support, only keep statements from else.
    # MagicMock below py3.8 doesn't has __fspath__ attribute.
    if sys.version_info < (3, 8):
        wix_zip = FsPathMock(wix_zip_path)
    else:
        wix_zip = MagicMock()
        wix_zip.__fspath__.return_value = wix_zip_path

    mock_command.download_url.return_value = wix_zip

    # Mock an unpack failure
    mock_command.shutil.unpack_archive.side_effect = EOFError

    # Create an SDK wrapper
    wix = WiX(mock_command, wix_home=wix_path, bin_install=True)

    # Upgrade the install. This will trigger a download,
    # but the unpack will fail.
    with pytest.raises(BriefcaseCommandError):
        wix.upgrade()

    # A download was initiated
    mock_command.download_url.assert_called_with(
        url=WIX_DOWNLOAD_URL,
        download_path=tmp_path / 'tools',
    )

    # The download was unpacked.
    # TODO: Py3.6 compatibility; os.fsdecode not required in Py3.7
    mock_command.shutil.unpack_archive.assert_called_with(
        os.fsdecode(wix_zip_path),
        extract_dir=os.fsdecode(wix_path)
    )

    # The zip file was not removed
    assert wix_zip.unlink.call_count == 0
def test_unpack_fail(mock_command, tmp_path):
    "If the download archive is corrupted, the validator fails"
    # Mock the environment as if there is not WiX variable
    mock_command.os.environ.get.return_value = None

    # Mock the download
    wix_path = tmp_path / 'tools' / 'wix'

    wix_zip_path = os.fsdecode(tmp_path / 'tools' / 'wix.zip')
    # Consider to remove if block when we drop py3.7 support, only keep statements from else.
    # MagicMock below py3.8 doesn't has __fspath__ attribute.
    if sys.version_info < (3, 8):
        wix_zip = FsPathMock(wix_zip_path)
    else:
        wix_zip = MagicMock()
        wix_zip.__fspath__.return_value = wix_zip_path

    mock_command.download_url.return_value = wix_zip

    # Mock an unpack failure
    mock_command.shutil.unpack_archive.side_effect = EOFError

    # Verify the install. This will trigger a download,
    # but the unpack will fail
    with pytest.raises(BriefcaseCommandError, match="interrupted or corrupted"):
        WiX.verify(mock_command)

    # The environment was queried.
    mock_command.os.environ.get.assert_called_with('WIX')

    # A download was initiated
    mock_command.download_url.assert_called_with(
        url=WIX_DOWNLOAD_URL,
        download_path=tmp_path / 'tools',
    )

    # The download was unpacked.
    # TODO: Py3.6 compatibility; os.fsdecode not required in Py3.7
    mock_command.shutil.unpack_archive.assert_called_with(
        os.fsdecode(wix_zip_path),
        extract_dir=os.fsdecode(wix_path)
    )

    # The zip file was not removed
    assert wix_zip.unlink.call_count == 0
def test_unpack_fail(mock_command, tmp_path):
    "If the download archive is corrupted, the validator fails"
    # Mock the environment as if there is not WiX variable
    mock_command.os.environ.get.return_value = None

    # Mock the download
    wix_path = tmp_path / 'tools' / 'wix'

    wix_zip_path = tmp_path / 'tools' / 'wix.zip'
    wix_zip = MagicMock()
    wix_zip.__str__.return_value = str(wix_zip_path)

    mock_command.download_url.return_value = wix_zip

    # Mock an unpack failure
    mock_command.shutil.unpack_archive.side_effect = EOFError

    # Verify the install. This will trigger a download,
    # but the unpack will fail
    with pytest.raises(BriefcaseCommandError, match="interrupted or corrupted"):
        WiX.verify(mock_command)

    # The environment was queried.
    mock_command.os.environ.get.assert_called_with('WIX')

    # A download was initiated
    mock_command.download_url.assert_called_with(
        url=WIX_DOWNLOAD_URL,
        download_path=tmp_path / 'tools',
    )

    # The download was unpacked
    mock_command.shutil.unpack_archive.assert_called_with(
        str(wix_zip_path),
        extract_dir=str(wix_path)
    )

    # The zip file was not removed
    assert wix_zip.unlink.call_count == 0
def test_unpack_fail(mock_command, tmp_path):
    "If the download archive is corrupted, the validator fails"
    # Create a mock of a previously installed WiX version.
    wix_path = tmp_path / 'tools' / 'wix'
    wix_path.mkdir(parents=True)
    (wix_path / 'heat.exe').touch()
    (wix_path / 'light.exe').touch()
    (wix_path / 'candle.exe').touch()

    # Mock the download
    wix_zip_path = tmp_path / 'tools' / 'wix.zip'
    wix_zip = MagicMock()
    wix_zip.__str__.return_value = str(wix_zip_path)

    mock_command.download_url.return_value = wix_zip

    # Mock an unpack failure
    mock_command.shutil.unpack_archive.side_effect = EOFError

    # Create an SDK wrapper
    wix = WiX(mock_command, wix_home=wix_path, bin_install=True)

    # Upgrade the install. This will trigger a download,
    # but the unpack will fail.
    with pytest.raises(BriefcaseCommandError):
        wix.upgrade()

    # A download was initiated
    mock_command.download_url.assert_called_with(
        url=WIX_DOWNLOAD_URL,
        download_path=tmp_path / 'tools',
    )

    # The download was unpacked
    mock_command.shutil.unpack_archive.assert_called_with(
        str(wix_zip_path), extract_dir=str(wix_path))

    # The zip file was not removed
    assert wix_zip.unlink.call_count == 0
def test_existing_wix_install(mock_command, tmp_path):
    "If there's an existing managed WiX install, it is deleted and redownloaded"
    # Create a mock of a previously installed WiX version.
    wix_path = tmp_path / 'tools' / 'wix'
    wix_path.mkdir(parents=True)
    (wix_path / 'heat.exe').touch()
    (wix_path / 'light.exe').touch()
    (wix_path / 'candle.exe').touch()

    # Mock the download
    wix_path = tmp_path / 'tools' / 'wix'

    wix_zip_path = tmp_path / 'tools' / 'wix.zip'
    wix_zip = MagicMock()
    wix_zip.__str__.return_value = str(wix_zip_path)

    mock_command.download_url.return_value = wix_zip

    # Create an SDK wrapper
    wix = WiX(mock_command, wix_home=wix_path, bin_install=True)

    # Attempt an upgrade.
    wix.upgrade()

    # The old version has been deleted
    mock_command.shutil.rmtree.assert_called_with(wix_path)

    # A download was initiated
    mock_command.download_url.assert_called_with(
        url=WIX_DOWNLOAD_URL,
        download_path=tmp_path / 'tools',
    )

    # The download was unpacked
    mock_command.shutil.unpack_archive.assert_called_with(
        str(wix_zip_path), extract_dir=str(wix_path))

    # The zip file was removed
    wix_zip.unlink.assert_called_with()
Exemple #13
0
def test_download_fail(mock_command, tmp_path):
    """If the download doesn't complete, the validator fails."""
    # Mock the environment as if there is not WiX variable
    mock_command.os.environ.get.return_value = None

    # Mock the download failure
    mock_command.download_url.side_effect = requests_exceptions.ConnectionError

    # Verify the install. This will trigger a download
    with pytest.raises(NetworkFailure):
        WiX.verify(mock_command)

    # The environment was queried.
    mock_command.os.environ.get.assert_called_with("WIX")

    # A download was initiated
    mock_command.download_url.assert_called_with(
        url=WIX_DOWNLOAD_URL,
        download_path=tmp_path / "tools",
    )

    # ... but the unpack didn't happen
    assert mock_command.shutil.unpack_archive.call_count == 0
def test_download_wix(mock_command, tmp_path):
    "If there's no existing managed WiX install, it is downloaded and unpacked"
    # Mock the environment as if there is not WiX variable
    mock_command.os.environ.get.return_value = None

    # Mock the download
    wix_path = tmp_path / 'tools' / 'wix'

    wix_zip_path = os.fsdecode(tmp_path / 'tools' / 'wix.zip')
    # Consider to remove if block when we drop py3.7 support, only keep statements from else.
    # MagicMock below py3.8 doesn't has __fspath__ attribute.
    if sys.version_info < (3, 8):
        wix_zip = FsPathMock(wix_zip_path)
    else:
        wix_zip = MagicMock()
        wix_zip.__fspath__.return_value = wix_zip_path

    mock_command.download_url.return_value = wix_zip

    # Verify the install. This will trigger a download
    wix = WiX.verify(mock_command)

    # The environment was queried.
    mock_command.os.environ.get.assert_called_with('WIX')

    # A download was initiated
    mock_command.download_url.assert_called_with(
        url=WIX_DOWNLOAD_URL,
        download_path=tmp_path / 'tools',
    )

    # The download was unpacked.
    # TODO: Py3.6 compatibility; os.fsdecode not required in Py3.7
    mock_command.shutil.unpack_archive.assert_called_with(
        os.fsdecode(wix_zip_path),
        extract_dir=os.fsdecode(wix_path)
    )

    # The zip file was removed
    wix_zip.unlink.assert_called_with()

    # The returned paths are as expected
    assert wix.heat_exe == tmp_path / 'tools' / 'wix' / 'heat.exe'
    assert wix.light_exe == tmp_path / 'tools' / 'wix' / 'light.exe'
    assert wix.candle_exe == tmp_path / 'tools' / 'wix' / 'candle.exe'
def test_download_wix(mock_command, tmp_path):
    "If there's no existing managed WiX install, it is downloaded and unpacked"
    # Mock the environment as if there is not WiX variable
    mock_command.os.environ.get.return_value = None

    # Mock the download
    wix_path = tmp_path / 'tools' / 'wix'

    wix_zip_path = tmp_path / 'tools' / 'wix.zip'
    wix_zip = MagicMock()
    wix_zip.__str__.return_value = str(wix_zip_path)

    mock_command.download_url.return_value = wix_zip

    # Verify the install. This will trigger a download
    wix = WiX.verify(mock_command)

    # The environment was queried.
    mock_command.os.environ.get.assert_called_with('WIX')

    # A download was initiated
    mock_command.download_url.assert_called_with(
        url=WIX_DOWNLOAD_URL,
        download_path=tmp_path / 'tools',
    )

    # The download was unpacked
    mock_command.shutil.unpack_archive.assert_called_with(
        str(wix_zip_path),
        extract_dir=str(wix_path)
    )

    # The zip file was removed
    wix_zip.unlink.assert_called_with()

    # The returned paths are as expected
    assert wix.heat_exe == tmp_path / 'tools' / 'wix' / 'heat.exe'
    assert wix.light_exe == tmp_path / 'tools' / 'wix' / 'light.exe'
    assert wix.candle_exe == tmp_path / 'tools' / 'wix' / 'candle.exe'
def test_valid_wix_envvar(mock_command, tmp_path):
    "If the WiX envvar points to a valid WiX install, the validator succeeds"
    # Mock the environment for a WiX install
    wix_path = tmp_path / 'wix'
    mock_command.os.environ.get.return_value = os.fsdecode(wix_path)

    # Mock the interesting parts of a WiX install
    (wix_path / 'bin').mkdir(parents=True)
    (wix_path / 'bin' / 'heat.exe').touch()
    (wix_path / 'bin' / 'light.exe').touch()
    (wix_path / 'bin' / 'candle.exe').touch()

    # Verify the install
    wix = WiX.verify(mock_command)

    # The environment was queried.
    mock_command.os.environ.get.assert_called_with('WIX')

    # The returned paths are as expected (and are the full paths)
    assert wix.heat_exe == tmp_path / 'wix' / 'bin' / 'heat.exe'
    assert wix.light_exe == tmp_path / 'wix' / 'bin' / 'light.exe'
    assert wix.candle_exe == tmp_path / 'wix' / 'bin' / 'candle.exe'
Exemple #17
0
def test_existing_wix_install(mock_command, tmp_path):
    """If there's an existing managed WiX install, the validator succeeds."""
    # Mock the environment as if there is not WiX variable
    mock_command.os.environ.get.return_value = None

    # Create a mock of a previously installed WiX version.
    wix_path = tmp_path / "tools" / "wix"
    wix_path.mkdir(parents=True)
    (wix_path / "heat.exe").touch()
    (wix_path / "light.exe").touch()
    (wix_path / "candle.exe").touch()

    wix = WiX.verify(mock_command)

    # The environment was queried.
    mock_command.os.environ.get.assert_called_with("WIX")

    # No download was attempted
    assert mock_command.download_url.call_count == 0

    # The returned paths are as expected
    assert wix.heat_exe == tmp_path / "tools" / "wix" / "heat.exe"
    assert wix.light_exe == tmp_path / "tools" / "wix" / "light.exe"
    assert wix.candle_exe == tmp_path / "tools" / "wix" / "candle.exe"
Exemple #18
0
def package_command(tmp_path):
    command = WindowsMSIPackageCommand(base_path=tmp_path)
    command.subprocess = mock.MagicMock()
    command.wix = WiX(command=command, wix_home=tmp_path / "wix")
    return command
Exemple #19
0
 def verify_tools(self):
     super().verify_tools()
     self.wix = WiX.verify(self)
Exemple #20
0
def package_command(tmp_path):
    command = WindowsMSIPackageCommand(base_path=tmp_path)
    command.subprocess = mock.MagicMock()
    command.wix = WiX(tmp_path / 'wix')
    return command