File: test_create.py

package info (click to toggle)
python-briefcase 0.3.25-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,596 kB
  • sloc: python: 62,519; makefile: 60
file content (247 lines) | stat: -rw-r--r-- 7,597 bytes parent folder | download
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
from unittest.mock import MagicMock

import pytest

from briefcase.exceptions import BriefcaseConfigError, UnsupportedHostError
from briefcase.integrations.flatpak import Flatpak
from briefcase.platforms.linux.flatpak import LinuxFlatpakCreateCommand


@pytest.fixture
def create_command(dummy_console, tmp_path):
    return LinuxFlatpakCreateCommand(
        console=dummy_console,
        base_path=tmp_path / "base_path",
        data_path=tmp_path / "briefcase",
    )


@pytest.mark.parametrize("host_os", ["Darwin", "Windows", "WeirdOS"])
def test_unsupported_host_os(create_command, host_os):
    """Error raised for an unsupported OS."""
    create_command.tools.host_os = host_os

    with pytest.raises(
        UnsupportedHostError,
        match="Flatpaks can only be built on Linux.",
    ):
        create_command()


def test_output_format_template_context(create_command, first_app_config):
    """The template context is provided flatpak details."""
    first_app_config.flatpak_runtime = "org.beeware.Platform"
    first_app_config.flatpak_runtime_version = "37.42"
    first_app_config.flatpak_sdk = "org.beeware.SDK"

    assert create_command.output_format_template_context(first_app_config) == {
        "flatpak_runtime": "org.beeware.Platform",
        "flatpak_runtime_version": "37.42",
        "flatpak_sdk": "org.beeware.SDK",
    }


DEFAULT_FINISH_ARGS = {
    "share=ipc": True,
    "socket=x11": True,
    "nosocket=wayland": True,
    "share=network": True,
    "device=dri": True,
    "socket=pulseaudio": True,
    "filesystem=xdg-cache": True,
    "filesystem=xdg-config": True,
    "filesystem=xdg-data": True,
    "filesystem=xdg-documents": True,
}


@pytest.mark.parametrize(
    "permissions, finish_args, context",
    [
        # No permissions
        (
            {},
            {},
            {
                "finish_args": DEFAULT_FINISH_ARGS,
            },
        ),
        # Only custom permissions
        (
            {
                "custom_permission": "Custom message",
            },
            {
                "allow=bluetooth": True,
            },
            {
                "finish_args": {
                    "share=ipc": True,
                    "socket=x11": True,
                    "nosocket=wayland": True,
                    "share=network": True,
                    "device=dri": True,
                    "socket=pulseaudio": True,
                    "filesystem=xdg-cache": True,
                    "filesystem=xdg-config": True,
                    "filesystem=xdg-data": True,
                    "filesystem=xdg-documents": True,
                    "allow=bluetooth": True,
                },
            },
        ),
        # Camera permissions
        (
            {
                "camera": "I need to see you",
            },
            {},
            {
                "finish_args": DEFAULT_FINISH_ARGS,
            },
        ),
        # Microphone permissions
        (
            {
                "microphone": "I need to hear you",
            },
            {},
            {
                "finish_args": DEFAULT_FINISH_ARGS,
            },
        ),
        # Coarse location permissions
        (
            {
                "coarse_location": "I need to know roughly where you are",
            },
            {},
            {
                "finish_args": DEFAULT_FINISH_ARGS,
            },
        ),
        # Fine location permissions
        (
            {
                "fine_location": "I need to know exactly where you are",
            },
            {},
            {
                "finish_args": DEFAULT_FINISH_ARGS,
            },
        ),
        # Background location permissions
        (
            {
                "background_location": "I always need to know where you are",
            },
            {},
            {
                "finish_args": DEFAULT_FINISH_ARGS,
            },
        ),
        # Coarse location background permissions
        (
            {
                "coarse_location": "I need to know roughly where you are",
                "background_location": "I always need to know where you are",
            },
            {},
            {
                "finish_args": DEFAULT_FINISH_ARGS,
            },
        ),
        # Fine location background permissions
        (
            {
                "fine_location": "I need to know exactly where you are",
                "background_location": "I always need to know where you are",
            },
            {},
            {
                "finish_args": DEFAULT_FINISH_ARGS,
            },
        ),
        # Coarse and fine location permissions
        (
            {
                "coarse_location": "I need to know roughly where you are",
                "fine_location": "I need to know exactly where you are",
            },
            {},
            {
                "finish_args": DEFAULT_FINISH_ARGS,
            },
        ),
        # Coarse and fine background location permissions
        (
            {
                "coarse_location": "I need to know roughly where you are",
                "fine_location": "I need to know exactly where you are",
                "background_location": "I always need to know where you are",
            },
            {},
            {
                "finish_args": DEFAULT_FINISH_ARGS,
            },
        ),
        # Photo library permissions
        (
            {
                "photo_library": "I need to see your library",
            },
            {},
            {
                "finish_args": DEFAULT_FINISH_ARGS,
            },
        ),
        # Override and augment by cross-platform definitions
        (
            {
                "fine_location": "I need to know where you are",
                "NSCustomMessage": "Custom message",
            },
            {
                "socket=pulseaudio": False,
                "allow=bluetooth": True,
            },
            {
                "finish_args": {
                    "share=ipc": True,
                    "socket=x11": True,
                    "nosocket=wayland": True,
                    "share=network": True,
                    "device=dri": True,
                    "socket=pulseaudio": False,
                    "filesystem=xdg-cache": True,
                    "filesystem=xdg-config": True,
                    "filesystem=xdg-data": True,
                    "filesystem=xdg-documents": True,
                    "allow=bluetooth": True,
                },
            },
        ),
    ],
)
def test_permissions_context(
    create_command, first_app, permissions, finish_args, context
):
    """Platform-specific permissions can be added to the context."""
    # Set the permission and entitlement value
    first_app.permission = permissions
    first_app.finish_arg = finish_args
    # Extract the cross-platform permissions
    x_permissions = create_command._x_permissions(first_app)
    # Check that the final platform permissions are rendered as expected.
    assert context == create_command.permissions_context(first_app, x_permissions)


def test_missing_runtime_config(create_command, first_app_config):
    """The app creation errors is a Flatpak runtime is not defined."""
    create_command.tools.flatpak = MagicMock(spec_set=Flatpak)

    with pytest.raises(
        BriefcaseConfigError,
        match="Briefcase configuration error: The App does not specify the Flatpak runtime to use",
    ):
        create_command.output_format_template_context(first_app_config)