File: test_package_zip.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 (133 lines) | stat: -rw-r--r-- 4,266 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
from unittest.mock import MagicMock


def test_package_zip(
    package_command,
    first_app_with_binaries,
    sekrit_identity,
):
    """A macOS App can be packaged as a zip."""
    # Mock the creation of the ditto archive
    package_command.ditto_archive = MagicMock()

    # Select zip packaging
    first_app_with_binaries.packaging_format = "zip"

    # Select a code signing identity
    package_command.select_identity.return_value = sekrit_identity

    # Package the app in zip (not DMG) format
    package_command.package_app(first_app_with_binaries)

    # A request has been made to sign the app
    package_command.sign_app.assert_called_once_with(
        app=first_app_with_binaries,
        identity=sekrit_identity,
    )

    # A request has been made to notarize the app
    package_command.notarize.assert_called_once_with(
        first_app_with_binaries,
        identity=sekrit_identity,
    )

    # No dmg was built.
    assert package_command.dmgbuild.build_dmg.call_count == 0

    # If the DMG doesn't exist, it can't be signed either.
    # This ignores the calls that would have been made transitively
    # by calling sign_app()
    assert package_command.sign_file.call_count == 0

    # The notarization process will create the final artefact;
    # since we're mocking notarize, we rely on the notarization tests
    # to verify that the final distribution artefact was created.


def test_zip_no_notarization(
    package_command,
    sekrit_identity,
    first_app_with_binaries,
    tmp_path,
):
    """A macOS App can be packaged as a zip, without notarization."""
    # Mock the creation of the ditto archive
    package_command.ditto_archive = MagicMock()

    # Select zip packaging
    first_app_with_binaries.packaging_format = "zip"

    # Select a code signing identity
    package_command.select_identity.return_value = sekrit_identity

    # Package the app in zip (not DMG) format, disabling notarization
    package_command.package_app(
        first_app_with_binaries,
        notarize_app=False,
    )

    # A request has been made to sign the app
    package_command.sign_app.assert_called_once_with(
        app=first_app_with_binaries,
        identity=sekrit_identity,
    )

    # No request has been made to notarize the app
    package_command.notarize.assert_not_called()

    # No dmg was built.
    assert package_command.dmgbuild.build_dmg.call_count == 0

    # If the DMG doesn't exist, it can't be signed either.
    # This ignores the calls that would have been made transitively
    # by calling sign_app()
    assert package_command.sign_file.call_count == 0

    # Since we're not notarizing, the packaged archive was created.
    package_command.ditto_archive.assert_called_once_with(
        tmp_path / "base_path/build/first-app/macos/app/First App.app",
        tmp_path / "base_path/dist/First App-0.0.1.app.zip",
    )


def test_external_app(
    package_command,
    external_first_app,
    sekrit_identity,
):
    """An external macOS App can be packaged as a zip."""
    # Mock the creation of the ditto archive
    package_command.ditto_archive = MagicMock()

    # Select zip packaging
    external_first_app.packaging_format = "zip"

    # Select a code signing identity
    package_command.select_identity.return_value = sekrit_identity

    # Package the app in zip (not DMG) format
    package_command.package_app(external_first_app)

    # A request has been made to sign the app
    package_command.sign_app.assert_called_once_with(
        app=external_first_app,
        identity=sekrit_identity,
    )

    # A request has been made to notarize the app
    package_command.notarize.assert_called_once_with(
        external_first_app,
        identity=sekrit_identity,
    )

    # No dmg was built.
    assert package_command.dmgbuild.build_dmg.call_count == 0

    # If the DMG doesn't exist, it can't be signed either.
    # This ignores the calls that would have been made transitively
    # by calling sign_app()
    assert package_command.sign_file.call_count == 0

    # The notarization process will create the final artefact;
    # since we're mocking notarize, we rely on the notarization tests
    # to verify that the final distribution artefact was created.