File: test_LinuxDeployURLPlugin__verify.py

package info (click to toggle)
python-briefcase 0.3.22-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,300 kB
  • sloc: python: 59,405; makefile: 57
file content (83 lines) | stat: -rw-r--r-- 2,679 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import pytest

from briefcase.exceptions import (
    BriefcaseCommandError,
    NetworkFailure,
    UnsupportedHostError,
)
from briefcase.integrations.linuxdeploy import LinuxDeployURLPlugin

from .utils import side_effect_create_mock_appimage


@pytest.mark.parametrize("host_os", ["Windows", "wonky"])
def test_unsupported_os(mock_tools, host_os):
    """When host OS is not supported, an error is raised."""
    mock_tools.host_os = host_os

    with pytest.raises(
        UnsupportedHostError,
        match=f"{LinuxDeployURLPlugin.name} is not supported on {host_os}",
    ):
        LinuxDeployURLPlugin.verify(mock_tools)


def test_verify(mock_tools, tmp_path):
    """URL plugins will be downloaded."""
    # Mock a successful download
    mock_tools.file.download.side_effect = side_effect_create_mock_appimage(
        tmp_path
        / "tools"
        / "linuxdeploy_plugins"
        / "sometool"
        / "f3355f8e631ffc1abbb7afd37b36315f7846182ca2276c481fb9a43a7f4d239f"
        / "linuxdeploy-plugin-sometool-wonky.AppImage"
    )

    LinuxDeployURLPlugin.verify(
        mock_tools,
        url="https://example.com/path/to/linuxdeploy-plugin-sometool-wonky.AppImage",
    )

    mock_tools.file.download.assert_called_with(
        url="https://example.com/path/to/linuxdeploy-plugin-sometool-wonky.AppImage",
        download_path=tmp_path
        / "tools"
        / "linuxdeploy_plugins"
        / "sometool"
        / "f3355f8e631ffc1abbb7afd37b36315f7846182ca2276c481fb9a43a7f4d239f",
        role="user-provided linuxdeploy plugin from URL",
    )


def test_download_failure(mock_tools, tmp_path):
    """A failure downloading a custom URL plugin raises an error."""

    # Mock a successful download
    mock_tools.file.download.side_effect = NetworkFailure("mock")

    url = "https://example.com/path/to/linuxdeploy-plugin-sometool-wonky.AppImage"

    with pytest.raises(NetworkFailure, match="Unable to mock"):
        LinuxDeployURLPlugin.verify(mock_tools, url=url)

    # A download was invoked
    mock_tools.file.download.assert_called_with(
        url=url,
        download_path=mock_tools.base_path
        / "linuxdeploy_plugins"
        / "sometool"
        / "f3355f8e631ffc1abbb7afd37b36315f7846182ca2276c481fb9a43a7f4d239f",
        role="user-provided linuxdeploy plugin from URL",
    )


def test_invalid_plugin_name(mock_tools, tmp_path):
    """If the URL filename doesn't match the pattern of a linuxdeploy plugin, an error
    is raised."""

    with pytest.raises(BriefcaseCommandError):
        LinuxDeployURLPlugin.verify(
            mock_tools,
            url="https://example.com/path/to/not-a-plugin.exe",
        )