1
|
|
|
import os |
2
|
|
|
import textwrap |
3
|
|
|
from pathlib import Path |
4
|
|
|
|
5
|
|
|
import pytest |
6
|
|
|
import responses |
|
|
|
|
7
|
|
|
|
8
|
|
|
from changes.commands import init |
9
|
|
|
from .conftest import AUTH_TOKEN_ENVVAR, LABEL_URL, BUG_LABEL_JSON |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
@pytest.fixture |
13
|
|
|
def answer_prompts(mocker): |
14
|
|
|
_ = mocker.patch( |
15
|
|
|
'changes.config.click.launch', |
16
|
|
|
autospec=True, |
17
|
|
|
) |
18
|
|
|
|
19
|
|
|
prompt = mocker.patch( |
20
|
|
|
'changes.config.click.prompt', |
21
|
|
|
autospec=True, |
22
|
|
|
) |
23
|
|
|
prompt.side_effect = [ |
24
|
|
|
'foo', |
25
|
|
|
'docs/releases', |
26
|
|
|
'version.txt', |
27
|
|
|
'.' |
28
|
|
|
] |
29
|
|
|
|
30
|
|
|
prompt = mocker.patch( |
31
|
|
|
'changes.config.choose_labels', |
32
|
|
|
autospec=True |
33
|
|
|
) |
34
|
|
|
prompt.return_value = ['bug'] |
35
|
|
|
|
36
|
|
|
saved_token = None |
37
|
|
|
if os.environ.get(AUTH_TOKEN_ENVVAR): |
38
|
|
|
saved_token = os.environ[AUTH_TOKEN_ENVVAR] |
39
|
|
|
del os.environ[AUTH_TOKEN_ENVVAR] |
40
|
|
|
|
41
|
|
|
yield |
42
|
|
|
|
43
|
|
|
if saved_token: |
44
|
|
|
os.environ[AUTH_TOKEN_ENVVAR] = saved_token |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
@responses.activate |
48
|
|
|
def test_init_prompts_for_auth_token_and_writes_tool_config( |
|
|
|
|
49
|
|
|
capsys, |
50
|
|
|
git_repo, |
51
|
|
|
changes_config_in_tmpdir, |
52
|
|
|
answer_prompts, |
|
|
|
|
53
|
|
|
): |
54
|
|
|
responses.add( |
55
|
|
|
responses.GET, |
56
|
|
|
LABEL_URL, |
57
|
|
|
json=BUG_LABEL_JSON, |
58
|
|
|
status=200, |
59
|
|
|
content_type='application/json' |
60
|
|
|
) |
61
|
|
|
|
62
|
|
|
init.init() |
63
|
|
|
|
64
|
|
|
assert changes_config_in_tmpdir.exists() |
65
|
|
|
expected_config = textwrap.dedent( |
66
|
|
|
"""\ |
67
|
|
|
[changes] |
68
|
|
|
auth_token = "foo" |
69
|
|
|
""" |
70
|
|
|
) |
71
|
|
|
assert expected_config == changes_config_in_tmpdir.read_text() |
72
|
|
|
|
73
|
|
|
expected_output = textwrap.dedent( |
74
|
|
|
"""\ |
75
|
|
|
No auth token found, asking for it... |
76
|
|
|
You need a Github Auth Token for changes to create a release. |
77
|
|
|
Releases directory {} not found, creating it.... |
78
|
|
|
""".format( |
79
|
|
|
Path('docs').joinpath('releases') |
80
|
|
|
) |
81
|
|
|
) |
82
|
|
|
out, _ = capsys.readouterr() |
83
|
|
|
assert expected_output == out |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
@responses.activate |
87
|
|
|
def test_init_finds_auth_token_in_environment( |
|
|
|
|
88
|
|
|
capsys, |
89
|
|
|
git_repo, |
90
|
|
|
with_auth_token_envvar, |
91
|
|
|
changes_config_in_tmpdir, |
92
|
|
|
with_releases_directory_and_bumpversion_file_prompt, |
93
|
|
|
): |
94
|
|
|
responses.add( |
95
|
|
|
responses.GET, |
96
|
|
|
LABEL_URL, |
97
|
|
|
json=BUG_LABEL_JSON, |
98
|
|
|
status=200, |
99
|
|
|
content_type='application/json' |
100
|
|
|
) |
101
|
|
|
|
102
|
|
|
init.init() |
103
|
|
|
|
104
|
|
|
# envvar setting is not written to the config file |
105
|
|
|
assert not changes_config_in_tmpdir.exists() |
106
|
|
|
|
107
|
|
|
expected_output = textwrap.dedent( |
108
|
|
|
"""\ |
109
|
|
|
Found Github Auth Token in the environment... |
110
|
|
|
Releases directory {} not found, creating it.... |
111
|
|
|
""".format( |
112
|
|
|
Path('docs').joinpath('releases') |
113
|
|
|
) |
114
|
|
|
) |
115
|
|
|
out, _ = capsys.readouterr() |
116
|
|
|
assert expected_output == out |
117
|
|
|
|
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.py
files in your module folders. Make sure that you place one file in each sub-folder.