Debian Codegraph @

tests/platforms/windows/app/create/test_install_app_resources.py

raw
1 import pytest
2
3 from briefcase.exceptions import BriefcaseCommandError
4
5 from .....utils import create_file
6
7
8 def test_minimal_app_resources(create_command, first_app_templated, tmp_path):
9 """Windows apps include, at a minimum, a license as extra resources."""
10 # Create a license file
11 create_file(tmp_path / "base_path/LICENSE", "This is a license file")
12
13 create_command.install_app_resources(first_app_templated)
14
15 # The extras path exists
16 assert (tmp_path / "base_path/build/first-app/windows/app/custom_extras").is_dir()
17
18 # A LICENSE.rtf file has been written.
19 assert (tmp_path / "base_path/build/first-app/windows/app/LICENSE.rtf").is_file()
20
21
22 def test_post_install_script(create_command, first_app_templated, tmp_path):
23 """A post_install script can be provided as extra resources."""
24 # Create a license file
25 create_file(tmp_path / "base_path/LICENSE", "This is a license file")
26
27 # Create a post-install script
28 first_app_templated.post_install_script = "scripts/post_install.bat"
29 create_file(tmp_path / "base_path/scripts/post_install.bat", "echo Hello world")
30
31 create_command.install_app_resources(first_app_templated)
32
33 # The post-install script has been written.
34 base_path = tmp_path / "base_path/build/first-app/windows/app"
35 assert (base_path / "custom_extras/_installer/post_install.bat").is_file()
36
37 # A LICENSE.rtf file has been written.
38 assert (tmp_path / "base_path/build/first-app/windows/app/LICENSE.rtf").is_file()
39
40
41 def test_non_batch_post_install_script(create_command, first_app_templated, tmp_path):
42 """If a post install script isn't a batch file, an error is raised."""
43 first_app_templated.post_install_script = "scripts/post_install.sh"
44 create_file(tmp_path / "base_path/scripts/post_install.sh", "echo Hello world")
45
46 with pytest.raises(
47 BriefcaseCommandError,
48 match=r"Windows post-install scripts must be .bat files.",
49 ):
50 create_command.install_app_resources(first_app_templated)
51
52
53 def test_missing_post_install_script(create_command, first_app_templated):
54 """If a post install script is specified, but not present, an error is raised."""
55 first_app_templated.post_install_script = "scripts/nonexistent.bat"
56
57 with pytest.raises(
58 BriefcaseCommandError,
59 match=r"Couldn't find post-install script scripts/nonexistent.bat",
60 ):
61 create_command.install_app_resources(first_app_templated)
62
63
64 def test_pre_uninstall_script(create_command, first_app_templated, tmp_path):
65 """A pre_uninstall script can be provided as extra resources."""
66 # Create a license file
67 create_file(tmp_path / "base_path/LICENSE", "This is a license file")
68
69 # Create a post-install script
70 first_app_templated.pre_uninstall_script = "scripts/pre_uninstall.bat"
71 create_file(tmp_path / "base_path/scripts/pre_uninstall.bat", "echo Hello world")
72
73 create_command.install_app_resources(first_app_templated)
74
75 # The pre-uninstall script has been written.
76 base_path = tmp_path / "base_path/build/first-app/windows/app"
77 assert (base_path / "custom_extras/_installer/pre_uninstall.bat").is_file()
78
79 # A LICENSE.rtf file has been written.
80 assert (tmp_path / "base_path/build/first-app/windows/app/LICENSE.rtf").is_file()
81
82
83 def test_non_batch_pre_uninstall_script(create_command, first_app_templated, tmp_path):
84 """If a post install script isn't a batch file, an error is raised."""
85 first_app_templated.pre_uninstall_script = "scripts/pre_uninstall.sh"
86 create_file(tmp_path / "base_path/scripts/pre_uninstall.sh", "echo Goodbye world")
87
88 with pytest.raises(
89 BriefcaseCommandError,
90 match=r"Windows pre-uninstall scripts must be .bat files.",
91 ):
92 create_command.install_app_resources(first_app_templated)
93
94
95 def test_missing_pre_uninstall_script(create_command, first_app_templated):
96 """If a post install script is specified, but not present, an error is raised."""
97 first_app_templated.pre_uninstall_script = "scripts/nonexistent.bat"
98
99 with pytest.raises(
100 BriefcaseCommandError,
101 match=r"Couldn't find pre-uninstall script scripts/nonexistent.bat",
102 ):
103 create_command.install_app_resources(first_app_templated)
104
105
106 def test_alternate_installer_path(create_command, first_app_templated, tmp_path):
107 """Windows installer content can be installed in a custom folder."""
108 # Define a custom installer path.
109 first_app_templated.installer_path = "install_scripts"
110
111 # Create a license file
112 create_file(tmp_path / "base_path/LICENSE", "This is a license file")
113
114 # Create a post-install script
115 first_app_templated.post_install_script = "scripts/post_install.bat"
116 create_file(tmp_path / "base_path/scripts/post_install.bat", "echo Hello world")
117
118 # Create a pre-uninstall script
119 first_app_templated.pre_uninstall_script = "scripts/pre_uninstall.bat"
120 create_file(tmp_path / "base_path/scripts/pre_uninstall.bat", "echo Goodbye world")
121
122 create_command.install_app_resources(first_app_templated)
123
124 # The post-install script has been written.
125 base_path = tmp_path / "base_path/build/first-app/windows/app"
126 assert (base_path / "custom_extras/install_scripts/post_install.bat").is_file()
127
128 # The pre-uninstall script has been written.
129 assert (base_path / "custom_extras/install_scripts/post_install.bat").is_file()
130
131 # A LICENSE.rtf file has been written.
132 assert (base_path / "LICENSE.rtf").is_file()
133
134
135 def test_legacy_template_support(create_command, first_app_templated, tmp_path):
136 """If briefcase.toml doesn't define extras_path; fall back to "extras"."""
137 # Create an empty briefcase.toml
138 create_file(tmp_path / "base_path/build/first-app/windows/app/briefcase.toml", "")
139
140 # Create a license file
141 create_file(tmp_path / "base_path/LICENSE", "This is a license file")
142
143 create_command.install_app_resources(first_app_templated)
144
145 # The extras path exists
146 assert (tmp_path / "base_path/build/first-app/windows/app/extras").is_dir()
147
148 # A LICENSE.rtf file has been written.
149 assert (tmp_path / "base_path/build/first-app/windows/app/LICENSE.rtf").is_file()