コード例 #1
0
def test_upgrade_exists(mock_command, tmp_path):
    """If linuxdeploy already exists, upgrading deletes first."""
    appimage_path = tmp_path / "tools" / "linuxdeploy-wonky.AppImage"

    # Mock the existence of an install
    appimage_path.touch()

    # Mock a successful download
    def side_effect_create_mock_appimage(*args, **kwargs):
        create_mock_appimage(appimage_path=appimage_path)
        return "new-downloaded-file"

    mock_command.download_url.side_effect = side_effect_create_mock_appimage

    # Create a linuxdeploy wrapper, then upgrade it
    linuxdeploy = LinuxDeploy(mock_command)
    linuxdeploy.upgrade()

    # The mock file should exist as the upgraded version
    assert appimage_path.exists()

    # A download is invoked
    mock_command.download_url.assert_called_with(
        url="https://github.com/linuxdeploy/linuxdeploy/"
        "releases/download/continuous/linuxdeploy-wonky.AppImage",
        download_path=tmp_path / "tools",
    )
    # The downloaded file will be made executable
    mock_command.os.chmod.assert_called_with("new-downloaded-file", 0o755)
コード例 #2
0
def test_upgrade_exists(mock_command, tmp_path):
    "If linuxdeploy already exists, upgrading deletes first"
    appimage_path = tmp_path / 'tools' / 'linuxdeploy-wonky.AppImage'

    # Mock the existence of an install
    appimage_path.touch()

    # Mock a successful download
    mock_command.download_url.return_value = 'new-downloaded-file'

    # Create a linuxdeploy wrapper, then upgrade it
    linuxdeploy = LinuxDeploy(mock_command)
    linuxdeploy.upgrade()

    # The mock file will be deleted
    assert not appimage_path.exists()

    # A download is invoked
    mock_command.download_url.assert_called_with(
        url='https://github.com/linuxdeploy/linuxdeploy/'
            'releases/download/continuous/linuxdeploy-wonky.AppImage',
        download_path=tmp_path / 'tools'
    )
    # The downloaded file will be made executable
    mock_command.os.chmod.assert_called_with('new-downloaded-file', 0o755)
コード例 #3
0
def test_upgrade_does_not_exist(mock_command, tmp_path):
    """If linuxdeploy doesn't already exist, upgrading is an error."""
    # Create a linuxdeploy wrapper, then upgrade it
    linuxdeploy = LinuxDeploy(mock_command)
    with pytest.raises(MissingToolError):
        linuxdeploy.upgrade()

    # The tool wasn't already installed, so an error is raised.
    assert mock_command.download_url.call_count == 0
コード例 #4
0
def test_patch_linuxdeploy_elf_header_bad_appimage(mock_command, tmp_path):
    """If linuxdeploy does not have a valid header, raise an error."""
    appimage_path = tmp_path / "tools" / "linuxdeploy-wonky.AppImage"

    # Mock an bad linuxdeploy AppImage
    create_mock_appimage(appimage_path=appimage_path,
                         mock_appimage_kind="corrupt")

    # Create a linuxdeploy wrapper, then patch the elf header
    linuxdeploy = LinuxDeploy(mock_command)
    with pytest.raises(CorruptToolError):
        linuxdeploy = linuxdeploy.patch_elf_header()
コード例 #5
0
def test_verify_linuxdeploy_download_failure(mock_command, tmp_path):
    "If linuxdeploy doesn't exist, but a download failure occurs, an error is raised"
    mock_command.download_url.side_effect = requests_exceptions.ConnectionError

    with pytest.raises(NetworkFailure):
        LinuxDeploy.verify(mock_command)

    # A download was invoked
    mock_command.download_url.assert_called_with(
        url='https://github.com/linuxdeploy/linuxdeploy/'
            'releases/download/continuous/linuxdeploy-wonky.AppImage',
        download_path=tmp_path / 'tools'
    )
コード例 #6
0
def test_verify_does_not_exist_dont_install(mock_command, tmp_path):
    "If linuxdeploy doesn't exist, and install=False, it is *not* downloaded"
    # Mock a successful download
    mock_command.download_url.return_value = 'new-downloaded-file'

    # True to create a linuxdeploy wrapper by verification.
    # This will fail because it doesn't exist, but installation was disabled.
    with pytest.raises(MissingToolError):
        LinuxDeploy.verify(mock_command, install=False)

    # No download occured
    assert mock_command.download_url.call_count == 0
    assert mock_command.os.chmod.call_count == 0
コード例 #7
0
def build_command(tmp_path, first_app_config):
    command = LinuxAppImageBuildCommand(base_path=tmp_path,
                                        home_path=tmp_path / "home",
                                        apps={'first': first_app_config})
    command.host_os = 'Linux'
    command.host_arch = 'wonky'
    command.verbosity = 0
    command.use_docker = False
    command._path_index = {
        first_app_config: {
            'app_path': "First App.AppDir/usr/app",
            'app_packages_path': "First App.AppDir/usr/app_packages",
        }
    }
    command.os = mock.MagicMock()
    command.os.environ.copy.return_value = {'PATH': '/usr/local/bin:/usr/bin'}

    # Store the underlying subprocess instance
    command._subprocess = mock.MagicMock()
    command.subprocess._subprocess = command._subprocess

    # Set up a Docker wrapper
    command.Docker = Docker

    command.linuxdeploy = LinuxDeploy(command)
    return command
コード例 #8
0
def test_verify_does_not_exist(mock_command, tmp_path):
    """If linuxdeploy doesn't exist, it is downloaded."""
    appimage_path = tmp_path / "tools" / "linuxdeploy-wonky.AppImage"

    # Mock a successful download
    def side_effect_create_mock_appimage(*args, **kwargs):
        create_mock_appimage(appimage_path=appimage_path)
        return "new-downloaded-file"

    mock_command.download_url.side_effect = side_effect_create_mock_appimage

    # Create a linuxdeploy wrapper by verification
    linuxdeploy = LinuxDeploy.verify(mock_command)

    # A download is invoked
    mock_command.download_url.assert_called_with(
        url="https://github.com/linuxdeploy/linuxdeploy/"
        "releases/download/continuous/linuxdeploy-wonky.AppImage",
        download_path=tmp_path / "tools",
    )
    # The downloaded file will be made executable
    mock_command.os.chmod.assert_called_with("new-downloaded-file", 0o755)

    # The build command retains the path to the downloaded file.
    assert linuxdeploy.appimage_path == appimage_path
コード例 #9
0
def build_command(tmp_path, first_app_config):
    command = LinuxAppImageBuildCommand(
        base_path=tmp_path,
        home_path=tmp_path / "home",
        apps={"first": first_app_config},
    )
    command.host_os = "Linux"
    command.host_arch = "wonky"
    command.use_docker = False
    command._path_index = {
        first_app_config: {
            "app_path": "First App.AppDir/usr/app",
            "app_packages_path": "First App.AppDir/usr/app_packages",
        }
    }
    command.os = mock.MagicMock()
    command.os.environ.copy.return_value = {"PATH": "/usr/local/bin:/usr/bin"}

    # Store the underlying subprocess instance
    command._subprocess = mock.MagicMock()
    command.subprocess._subprocess = command._subprocess

    # Set up a Docker wrapper
    command.Docker = Docker

    command.linuxdeploy = LinuxDeploy(command)
    return command
コード例 #10
0
def test_patch_linuxdeploy_elf_header_already_patched(mock_command, tmp_path):
    """If linuxdeploy is already patched, don't patch it."""
    appimage_path = tmp_path / "tools" / "linuxdeploy-wonky.AppImage"

    # Mock a patched linuxdeploy AppImage
    pre_patch_header = create_mock_appimage(appimage_path=appimage_path,
                                            mock_appimage_kind="patched")

    # Create a linuxdeploy wrapper, then patch the elf header
    linuxdeploy = LinuxDeploy(mock_command)
    linuxdeploy.patch_elf_header()

    # Ensure the patch was applied.
    with open(appimage_path, "rb") as mock_appimage:
        mock_appimage.seek(ELF_PATCH_OFFSET)
        patched_header = mock_appimage.read(len(ELF_PATCH_PATCHED_BYTES))

    assert pre_patch_header == ELF_PATCH_PATCHED_BYTES
    assert patched_header == ELF_PATCH_PATCHED_BYTES
コード例 #11
0
def test_upgrade_linuxdeploy_download_failure(mock_command, tmp_path):
    "If linuxdeploy doesn't exist, but a download failure occurs, an error is raised"
    # Mock the existence of an install
    appimage_path = tmp_path / 'tools' / 'linuxdeploy-wonky.AppImage'
    appimage_path.touch()

    mock_command.download_url.side_effect = requests_exceptions.ConnectionError

    # Create a linuxdeploy wrapper, then upgrade it.
    # The upgrade will fail
    linuxdeploy = LinuxDeploy(mock_command)
    with pytest.raises(NetworkFailure):
        linuxdeploy.upgrade()

    # The mock file will be deleted
    assert not appimage_path.exists()

    # A download was invoked
    mock_command.download_url.assert_called_with(
        url='https://github.com/linuxdeploy/linuxdeploy/'
            'releases/download/continuous/linuxdeploy-wonky.AppImage',
        download_path=tmp_path / 'tools'
    )
コード例 #12
0
def test_verify_exists(mock_command, tmp_path):
    """If linuxdeploy already exists, verification doesn't download."""
    appimage_path = tmp_path / "tools" / "linuxdeploy-wonky.AppImage"

    # Mock the existence of an install
    appimage_path.touch()

    # Create a linuxdeploy wrapper by verification
    linuxdeploy = LinuxDeploy.verify(mock_command)

    # No download occured
    assert mock_command.download_url.call_count == 0
    assert mock_command.os.chmod.call_count == 0

    # The build command retains the path to the downloaded file.
    assert linuxdeploy.appimage_path == appimage_path
コード例 #13
0
def test_verify_does_not_exist(mock_command, tmp_path):
    "If linuxdeploy doesn't exist, it is downloaded"
    appimage_path = tmp_path / 'tools' / 'linuxdeploy-wonky.AppImage'

    # Mock a successful download
    mock_command.download_url.return_value = 'new-downloaded-file'

    # Create a linuxdeploy wrapper by verification
    linuxdeploy = LinuxDeploy.verify(mock_command)

    # A download is invoked
    mock_command.download_url.assert_called_with(
        url='https://github.com/linuxdeploy/linuxdeploy/'
            'releases/download/continuous/linuxdeploy-wonky.AppImage',
        download_path=tmp_path / 'tools'
    )
    # The downloaded file will be made executable
    mock_command.os.chmod.assert_called_with('new-downloaded-file', 0o755)

    # The build command retains the path to the downloaded file.
    assert linuxdeploy.appimage_path == appimage_path
コード例 #14
0
 def verify_tools(self):
     super().verify_tools()
     self.linuxdeploy = LinuxDeploy.verify(self)
コード例 #15
0
def test_managed_install():
    """All linuxdeploy installs are managed."""
    linuxdeploy = LinuxDeploy(MagicMock())

    assert linuxdeploy.managed_install
コード例 #16
0
def test_patch_linuxdeploy_elf_header_no_file(mock_command, tmp_path):
    """If there is no linuxdeploy AppImage, raise an error."""
    # Create a linuxdeploy wrapper, then patch the elf header
    linuxdeploy = LinuxDeploy(mock_command)
    with pytest.raises(MissingToolError):
        linuxdeploy = linuxdeploy.patch_elf_header()