File: test_RCEdit__upgrade.py

package info (click to toggle)
python-briefcase 0.3.22-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 7,296 kB
  • sloc: python: 59,405; makefile: 57
file content (66 lines) | stat: -rw-r--r-- 2,045 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
import pytest

from briefcase.exceptions import MissingToolError, NetworkFailure


def test_upgrade_exists(mock_tools, rcedit, tmp_path):
    """If rcedit already exists, upgrading deletes first."""
    rcedit_path = tmp_path / "tools/rcedit-x64.exe"

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

    # Mock a successful download
    def side_effect_create_mock_appimage(*args, **kwargs):
        rcedit_path.touch()
        return "new-downloaded-file"

    mock_tools.file.download.side_effect = side_effect_create_mock_appimage

    # Do upgrade
    rcedit.upgrade()

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

    # A download is invoked
    mock_tools.file.download.assert_called_with(
        url="https://github.com/electron/rcedit/"
        "releases/download/v2.0.0/rcedit-x64.exe",
        download_path=tmp_path / "tools",
        role="RCEdit",
    )


def test_upgrade_does_not_exist(mock_tools, rcedit, tmp_path):
    """If rcedit doesn't already exist, upgrading is an error."""
    # Do upgrade
    with pytest.raises(MissingToolError):
        rcedit.upgrade()

    # The tool wasn't already installed, so an error is raised.
    assert mock_tools.file.download.call_count == 0


def test_upgrade_rcedit_download_failure(mock_tools, rcedit, tmp_path):
    """If rcedit doesn't exist, but a download failure occurs, an error is raised."""
    # Mock the existence of an install
    rcedit_path = tmp_path / "tools/rcedit-x64.exe"
    rcedit_path.touch()

    mock_tools.file.download.side_effect = NetworkFailure("mock")

    # The upgrade will fail
    with pytest.raises(NetworkFailure, match="Unable to mock"):
        rcedit.upgrade()

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

    # A download was invoked
    mock_tools.file.download.assert_called_with(
        url="https://github.com/electron/rcedit/"
        "releases/download/v2.0.0/rcedit-x64.exe",
        download_path=tmp_path / "tools",
        role="RCEdit",
    )