Skip to content

Commit

Permalink
Test download URLs for tools
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartin16 committed Jan 25, 2024
1 parent 3de597b commit d070cc5
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 16 deletions.
8 changes: 5 additions & 3 deletions src/briefcase/integrations/wix.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from briefcase.exceptions import BriefcaseCommandError, MissingToolError
from briefcase.integrations.base import ManagedTool, ToolCache

WIX_DOWNLOAD_URL = "https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip"


class WiX(ManagedTool):
name = "wix"
Expand Down Expand Up @@ -37,6 +35,10 @@ def __init__(
self.wix_home = tools.base_path / "wix"
self.bin_install = bin_install

@property
def download_url(self) -> str:
return "https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip"

@property
def heat_exe(self) -> Path:
if self.bin_install:
Expand Down Expand Up @@ -133,7 +135,7 @@ def managed_install(self) -> bool:
def install(self):
"""Download and install WiX."""
wix_zip_path = self.tools.download.file(
url=WIX_DOWNLOAD_URL,
url=self.download_url,
download_path=self.tools.base_path,
role="WiX",
)
Expand Down
2 changes: 2 additions & 0 deletions tests/integrations/android_sdk/AndroidSDK/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from briefcase.exceptions import BriefcaseCommandError

from ....utils import assert_url_resolvable
from ..conftest import SDK_MGR_DL_VER, SDK_MGR_VER


Expand All @@ -25,6 +26,7 @@ def test_cmdline_tools_url(mock_tools, android_sdk, host_os, host_arch, name):
assert android_sdk.cmdline_tools_url == (
f"https://dl.google.com/android/repository/commandlinetools-{name}-{SDK_MGR_DL_VER}_latest.zip"
)
assert_url_resolvable(android_sdk.cmdline_tools_url)


@pytest.mark.parametrize(
Expand Down
14 changes: 3 additions & 11 deletions tests/integrations/java/test_JDK__verify.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import os
import platform
import shutil
import subprocess
from pathlib import Path
from unittest import mock

import pytest
import requests

from briefcase.exceptions import (
BriefcaseCommandError,
Expand All @@ -17,6 +15,7 @@
)
from briefcase.integrations.java import JDK

from ...utils import assert_url_resolvable
from .conftest import JDK_BUILD, JDK_RELEASE

CALL_JAVA_HOME = mock.call(["/usr/libexec/java_home"])
Expand Down Expand Up @@ -520,15 +519,8 @@ def test_successful_jdk_download(
)
# The original archive was deleted
archive.unlink.assert_called_once_with()


def test_jdk_url_exists(mock_tools, tmp_path):
"""The JDK download URL is resolvable for the platform."""
# ensure the system hasn't been mocked
mock_tools.host_arch = platform.machine()
mock_tools.host_os = platform.system()

requests.head(JDK(mock_tools, tmp_path).OpenJDK_download_url).raise_for_status()
# The download URL for JDK exists
assert_url_resolvable(mock_tools.java.OpenJDK_download_url)


def test_not_installed(mock_tools, tmp_path):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from briefcase.integrations.linuxdeploy import LinuxDeployGtkPlugin

from ...utils import assert_url_resolvable


@pytest.fixture
def linuxdeploy_gtk_plugin(mock_tools):
Expand Down Expand Up @@ -32,3 +34,4 @@ def test_download_url(linuxdeploy_gtk_plugin):
"https://raw.githubusercontent.com/linuxdeploy/linuxdeploy-plugin-gtk/"
"master/linuxdeploy-plugin-gtk.sh"
)
assert_url_resolvable(linuxdeploy_gtk_plugin.download_url)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from briefcase.integrations.linuxdeploy import LinuxDeployQtPlugin

from ...utils import assert_url_resolvable


@pytest.fixture
def linuxdeploy_qt_plugin(mock_tools):
Expand Down Expand Up @@ -60,3 +62,4 @@ def test_download_url(mock_tools, host_os, host_arch, linuxdeploy_arch):
"https://github.com/linuxdeploy/linuxdeploy-plugin-qt/"
f"releases/download/continuous/linuxdeploy-plugin-qt-{linuxdeploy_arch}.AppImage"
)
assert_url_resolvable(linuxdeploy_qt_plugin.download_url)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
LinuxDeployQtPlugin,
)

from ...utils import assert_url_resolvable


def test_managed_install(linuxdeploy):
"""All linuxdeploy installs are managed."""
Expand Down Expand Up @@ -72,6 +74,7 @@ def test_download_url(mock_tools, host_os, host_arch, linuxdeploy_arch):
"https://github.com/linuxdeploy/linuxdeploy/"
f"releases/download/continuous/linuxdeploy-{linuxdeploy_arch}.AppImage"
)
assert_url_resolvable(linuxdeploy.download_url)


def test_plugins(linuxdeploy):
Expand Down
12 changes: 12 additions & 0 deletions tests/integrations/rcedit/test_RCEdit__properties.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
from ...utils import assert_url_resolvable


def test_managed_install(mock_tools, rcedit):
"""All rcedit installs are managed."""
assert rcedit.managed_install


def test_rcedit_url(mock_tools, rcedit):
"""The URL for RCEdit is correct."""
assert (
rcedit.download_url
== "https://github.com/electron/rcedit/releases/download/v2.0.0/rcedit-x64.exe"
)
assert_url_resolvable(rcedit.download_url)
2 changes: 2 additions & 0 deletions tests/integrations/wix/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from briefcase.integrations.download import Download
from briefcase.integrations.subprocess import Subprocess

WIX_DOWNLOAD_URL = "https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip"


@pytest.fixture
def mock_tools(tmp_path, mock_tools) -> ToolCache:
Expand Down
4 changes: 3 additions & 1 deletion tests/integrations/wix/test_WiX__upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
NetworkFailure,
NonManagedToolError,
)
from briefcase.integrations.wix import WIX_DOWNLOAD_URL, WiX
from briefcase.integrations.wix import WiX

from .conftest import WIX_DOWNLOAD_URL


def test_non_managed_install(mock_tools, tmp_path, capsys):
Expand Down
8 changes: 7 additions & 1 deletion tests/integrations/wix/test_WiX__verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
NetworkFailure,
UnsupportedHostError,
)
from briefcase.integrations.wix import WIX_DOWNLOAD_URL, WiX
from briefcase.integrations.wix import WiX

from ...utils import assert_url_resolvable
from .conftest import WIX_DOWNLOAD_URL


def test_short_circuit(mock_tools):
Expand Down Expand Up @@ -135,6 +138,9 @@ def test_download_wix(mock_tools, tmp_path):
assert wix.light_exe == tmp_path / "tools/wix/light.exe"
assert wix.candle_exe == tmp_path / "tools/wix/candle.exe"

# The WiX URL is resolvable
assert_url_resolvable(wix.download_url)


def test_dont_install(mock_tools, tmp_path):
"""If there's no existing managed WiX install, an install is not requested, verify
Expand Down
13 changes: 13 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from email.message import EmailMessage
from pathlib import Path

import requests
from requests.adapters import HTTPAdapter
from rich.markup import escape
from urllib3.util.retry import Retry

from briefcase.console import Console, InputDisabled

Expand Down Expand Up @@ -298,3 +301,13 @@ def file_content(path: Path) -> str | None:
return None
with path.open(encoding="utf-8") as f:
return f.read()


def assert_url_resolvable(url: str):
"""Tests whether a URL is resolvable with retries; raises for failure."""
with requests.session() as sess:
adapter = HTTPAdapter(max_retries=Retry(status_forcelist={500, 502, 504}))
sess.mount("http://", adapter)
sess.mount("https://", adapter)

sess.head(url).raise_for_status()

0 comments on commit d070cc5

Please sign in to comment.