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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
import pytest
from briefcase.commands.create import Git
from briefcase.exceptions import BriefcaseCommandError
def test_no_git(update_command, monkeypatch):
"""If Git is not installed, an error is raised."""
def monkeypatch_verify_git(*a, **kw):
raise BriefcaseCommandError("Briefcase requires git, but it is not installed")
monkeypatch.setattr(Git, "verify", monkeypatch_verify_git)
# The command will fail tool verification.
with pytest.raises(
BriefcaseCommandError, match=r"Briefcase requires git, but it is not installed"
):
update_command()
def test_update(update_command, first_app, second_app):
"""The update command can be called."""
# Configure no command line options
options, _ = update_command.parse_options([])
update_command(**options)
# The right sequence of things will be done
assert update_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App configs have been finalized
("finalize-app-config", "first"),
("finalize-app-config", "second"),
# Update the first app
("verify-app-template", "first"),
("verify-app-tools", "first"),
("code", "first", False),
("cleanup", "first"),
# Update the second app
("verify-app-template", "second"),
("verify-app-tools", "second"),
("code", "second", False),
("cleanup", "second"),
]
def test_update_single(update_command, first_app, second_app):
"""The update command can be called to update a single app from the config."""
# Configure no command line options
options, _ = update_command.parse_options([])
update_command(app=update_command.apps["first"], **options)
# The right sequence of things will be done
assert update_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App config has been finalized
("finalize-app-config", "first"),
# Update the first app
("verify-app-template", "first"),
("verify-app-tools", "first"),
("code", "first", False),
("cleanup", "first"),
]
def test_update_with_requirements(update_command, first_app, second_app):
"""The update command can be called, requesting a requirements update."""
# Configure a requirements update
options, _ = update_command.parse_options(["-r"])
update_command(**options)
# The right sequence of things will be done
assert update_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App configs have been finalized
("finalize-app-config", "first"),
("finalize-app-config", "second"),
# Update the first app
("verify-app-template", "first"),
("verify-app-tools", "first"),
("code", "first", False),
("requirements", "first", False),
("cleanup", "first"),
# Update the second app
("verify-app-template", "second"),
("verify-app-tools", "second"),
("code", "second", False),
("requirements", "second", False),
("cleanup", "second"),
]
def test_update_with_resources(update_command, first_app, second_app):
"""The update command can be called, requesting a resources update."""
# Configure no command line options
options, _ = update_command.parse_options(["--update-resources"])
update_command(**options)
# The right sequence of things will be done
assert update_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App configs have been finalized
("finalize-app-config", "first"),
("finalize-app-config", "second"),
# Update the first app
("verify-app-template", "first"),
("verify-app-tools", "first"),
("code", "first", False),
("resources", "first"),
("cleanup", "first"),
# Update the second app
("verify-app-template", "second"),
("verify-app-tools", "second"),
("code", "second", False),
("resources", "second"),
("cleanup", "second"),
]
def test_update_with_support(update_command, first_app, second_app):
"""The update command can be called, requesting an app support update."""
# Configure no command line options
options, _ = update_command.parse_options(["--update-support"])
update_command(**options)
# The right sequence of things will be done
assert update_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App configs have been finalized
("finalize-app-config", "first"),
("finalize-app-config", "second"),
# Update the first app
("verify-app-template", "first"),
("verify-app-tools", "first"),
("code", "first", False),
("cleanup-support", "first"),
("support", "first"),
("cleanup", "first"),
# Update the second app
("verify-app-template", "second"),
("verify-app-tools", "second"),
("code", "second", False),
("cleanup-support", "second"),
("support", "second"),
("cleanup", "second"),
]
# Parametrize both --apps/-a flags
@pytest.mark.parametrize("app_flags", ["--app", "-a"])
def test_update_app_single(update_command, first_app, second_app, app_flags):
"""If the --app or -a flag is used, only the selected app is updated."""
# Configure command line options with the parameterized flag
options, _ = update_command.parse_options([app_flags, "first"])
# Run the update command
update_command(**options)
# Only the selected app is updated
assert update_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App config has been finalized
("finalize-app-config", "first"),
("finalize-app-config", "second"),
# Update the app
("verify-app-template", "first"),
("verify-app-tools", "first"),
("code", "first", False),
("cleanup", "first"),
]
def test_update_app_invalid(update_command, first_app, second_app):
"""If an invalid app name is passed to --app, raise an error."""
# Add two apps
update_command.apps = {
"first": first_app,
"second": second_app,
}
# Configure the --app option with an invalid app
options, _ = update_command.parse_options(["--app", "invalid"])
# Running the command should raise an error
with pytest.raises(
BriefcaseCommandError,
match=r"App 'invalid' does not exist in this project.",
):
update_command(**options)
def test_update_app_none_defined(update_command):
"""If no apps are defined, do nothing."""
# No apps defined
update_command.apps = {}
# Configure no command line options
options, _ = update_command.parse_options([])
# Run the update command
result = update_command(**options)
# The right sequence of things will be done
assert result is None
assert update_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
]
def test_update_app_all_flags(update_command, first_app, second_app):
"""Verify that all update-related flags work correctly with -a."""
options, _ = update_command.parse_options(
[
"-a",
"first",
"--update-requirements",
"--update-resources",
"--update-support",
"--update-stub",
"--no-input",
"--log",
"-vv",
]
)
# Run the update command
update_command(**options)
# The right sequence of things will be done
assert update_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App config has been finalized
("finalize-app-config", "first"),
("finalize-app-config", "second"),
# Update the app
("verify-app-template", "first"),
("verify-app-tools", "first"),
("code", "first", False),
("requirements", "first", False),
("resources", "first"),
("cleanup-support", "first"),
("support", "first"),
("cleanup", "first"),
]
def test_update_external_app(update_command, first_app):
"""If the user requests a update an external app, an error is raised."""
# Add an apps
update_command.apps = {
"first": first_app,
}
# Make first_app an external app
first_app.sources = None
first_app.external_package_path = "path/to/package"
# Configure no command line options
options, _ = update_command.parse_options([])
# Run the build command
with pytest.raises(
BriefcaseCommandError,
match=r"'first' is declared as an external app",
):
update_command(**options)
|