File: test_create_app.py

package info (click to toggle)
python-briefcase 0.3.22-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,300 kB
  • sloc: python: 59,405; makefile: 57
file content (195 lines) | stat: -rw-r--r-- 6,943 bytes parent folder | download | duplicates (2)
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
import pytest

from briefcase.config import AppConfig
from briefcase.exceptions import UnsupportedPlatform


def test_create_app(tracking_create_command, tmp_path):
    """If the app doesn't already exist, it will be created."""
    tracking_create_command.create_app(tracking_create_command.apps["first"])

    # Input wasn't required by the user
    assert tracking_create_command.console.prompts == []

    # The right sequence of things will be done
    assert tracking_create_command.actions == [
        ("generate", "first"),
        ("support", "first"),
        ("verify-app-template", "first"),
        ("verify-app-tools", "first"),
        ("code", "first", False),
        ("requirements", "first", False),
        ("resources", "first"),
        ("cleanup", "first"),
    ]

    # New app content has been created
    assert (tmp_path / "base_path/build/first/tester/dummy/new").exists()
    # A stub binary has *not* been created
    assert not (tmp_path / "base_path/build/first/tester/dummy/Stub.bin").exists()


def test_create_existing_app_overwrite(tracking_create_command, tmp_path):
    """An existing app can be overwritten if requested."""
    # Answer yes when asked
    tracking_create_command.console.values = ["y"]

    # Generate an app in the location.
    bundle_path = tmp_path / "base_path/build/first/tester/dummy"
    bundle_path.mkdir(parents=True)
    with (bundle_path / "original").open("w", encoding="utf-8") as f:
        f.write("original template!")

    tracking_create_command.create_app(tracking_create_command.apps["first"])

    # Input was required by the user
    assert tracking_create_command.console.prompts == [
        "Application 'first' already exists; overwrite [y/N]? "
    ]

    # The right sequence of things will be done
    assert tracking_create_command.actions == [
        ("generate", "first"),
        ("support", "first"),
        ("verify-app-template", "first"),
        ("verify-app-tools", "first"),
        ("code", "first", False),
        ("requirements", "first", False),
        ("resources", "first"),
        ("cleanup", "first"),
    ]

    # Original content has been deleted
    assert not (bundle_path / "original").exists()

    # New app content has been created
    assert (bundle_path / "new").exists()


def test_create_existing_app_no_overwrite(tracking_create_command, tmp_path):
    """If you say no, the existing app won't be overwritten."""
    # Answer no when asked
    tracking_create_command.console.values = ["n"]

    bundle_path = tmp_path / "base_path/build/first/tester/dummy"
    bundle_path.mkdir(parents=True)
    with (bundle_path / "original").open("w", encoding="utf-8") as f:
        f.write("original template!")
    tracking_create_command.create_app(tracking_create_command.apps["first"])

    # Input was required by the user
    assert tracking_create_command.console.prompts == [
        "Application 'first' already exists; overwrite [y/N]? "
    ]

    # No app creation actions will be performed
    assert tracking_create_command.actions == []

    # Original content still exists
    assert (bundle_path / "original").exists()

    # New app content has not been created
    assert not (bundle_path / "new").exists()


def test_create_existing_app_no_overwrite_default(tracking_create_command, tmp_path):
    """By default, the existing app won't be overwritten."""
    # Answer '' (i.e., just press return) when asked
    tracking_create_command.console.values = [""]

    bundle_path = tmp_path / "base_path/build/first/tester/dummy"
    bundle_path.mkdir(parents=True)
    with (bundle_path / "original").open("w", encoding="utf-8") as f:
        f.write("original template!")

    tracking_create_command.create_app(tracking_create_command.apps["first"])

    # Input was required by the user
    assert tracking_create_command.console.prompts == [
        "Application 'first' already exists; overwrite [y/N]? "
    ]

    # And no actions were necessary
    assert tracking_create_command.actions == []

    # Original content still exists
    assert (bundle_path / "original").exists()

    # New app content has not been created
    assert not (bundle_path / "new").exists()


def test_create_existing_app_input_disabled(tracking_create_command, tmp_path):
    """If input is disabled, fallback to default without get input from user."""
    # Answer '' (i.e., just press return) when asked
    tracking_create_command.console.input_enabled = False

    bundle_path = tmp_path / "base_path/build/first/tester/dummy"
    bundle_path.mkdir(parents=True)
    with (bundle_path / "original").open("w", encoding="utf-8") as f:
        f.write("original template!")

    tracking_create_command.create_app(tracking_create_command.apps["first"])

    # Input wasn't required by the user
    assert tracking_create_command.console.prompts == []

    # And no actions were necessary
    assert tracking_create_command.actions == []

    # Original content still exists
    assert (bundle_path / "original").exists()

    # New app content has not been created
    assert not (bundle_path / "new").exists()


def test_create_app_not_supported(tracking_create_command, tmp_path):
    """If the supported attribute is false, the command will terminate with an error
    message."""

    with pytest.raises(UnsupportedPlatform):
        tracking_create_command.create_app(
            AppConfig(
                app_name="third",
                bundle="com.example",
                version="0.0.3",
                description="The third simple app",
                sources=["src/third"],
                supported=False,
                license={"file": "LICENSE"},
            )
        )

    # No actions carried out
    assert tracking_create_command.actions == []


def test_create_app_with_stub(tracking_create_command, tmp_path):
    """If an app template defines a stub revision, the stub will be created."""
    # Add an entry to the path index indicating a stub is required
    tracking_create_command._briefcase_toml[tracking_create_command.apps["first"]] = {
        "paths": {"stub_binary_revision": "b1"}
    }

    tracking_create_command.create_app(tracking_create_command.apps["first"])

    # Input wasn't required by the user
    assert tracking_create_command.console.prompts == []

    # The right sequence of things will be done
    assert tracking_create_command.actions == [
        ("generate", "first"),
        ("support", "first"),
        ("stub", "first"),
        ("verify-app-template", "first"),
        ("verify-app-tools", "first"),
        ("code", "first", False),
        ("requirements", "first", False),
        ("resources", "first"),
        ("cleanup", "first"),
    ]

    # New app content and stub binary has been created
    assert (tmp_path / "base_path/build/first/tester/dummy/new").exists()
    assert (tmp_path / "base_path/build/first/tester/dummy/Stub.bin").exists()