1
|
|
|
import os |
2
|
|
|
import textwrap |
3
|
|
|
|
4
|
|
|
import pytest |
5
|
|
|
import responses |
|
|
|
|
6
|
|
|
|
7
|
|
|
from changes.commands import init |
8
|
|
|
from .conftest import AUTH_TOKEN_ENVVAR, LABEL_URL |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
@pytest.fixture |
12
|
|
|
def answer_prompts(mocker): |
13
|
|
|
_ = mocker.patch( |
14
|
|
|
'changes.config.click.launch', |
15
|
|
|
autospec=True, |
16
|
|
|
) |
17
|
|
|
|
18
|
|
|
prompt = mocker.patch( |
19
|
|
|
'changes.config.click.prompt', |
20
|
|
|
autospec=True, |
21
|
|
|
) |
22
|
|
|
prompt.side_effect = [ |
23
|
|
|
'foo', |
24
|
|
|
'docs/releases', |
25
|
|
|
'version.txt', |
26
|
|
|
'.' |
27
|
|
|
] |
28
|
|
|
|
29
|
|
|
prompt = mocker.patch( |
30
|
|
|
'changes.config.read_user_choices', |
31
|
|
|
autospec=True |
32
|
|
|
) |
33
|
|
|
prompt.return_value = ['bug'] |
34
|
|
|
|
35
|
|
|
saved_token = None |
36
|
|
|
if os.environ.get(AUTH_TOKEN_ENVVAR): |
37
|
|
|
saved_token = os.environ[AUTH_TOKEN_ENVVAR] |
38
|
|
|
del os.environ[AUTH_TOKEN_ENVVAR] |
39
|
|
|
|
40
|
|
|
yield |
41
|
|
|
|
42
|
|
|
if saved_token: |
43
|
|
|
os.environ[AUTH_TOKEN_ENVVAR] = saved_token |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
@responses.activate |
47
|
|
|
def test_init_prompts_for_auth_token_and_writes_tool_config( |
|
|
|
|
48
|
|
|
capsys, |
49
|
|
|
git_repo, |
50
|
|
|
changes_config_in_tmpdir, |
51
|
|
|
answer_prompts, |
|
|
|
|
52
|
|
|
): |
53
|
|
|
responses.add( |
54
|
|
|
responses.GET, |
55
|
|
|
LABEL_URL, |
56
|
|
|
json={ |
57
|
|
|
'bug': { |
58
|
|
|
"id": 208045946, |
59
|
|
|
"url": "https://api.github.com/repos/michaeljoseph/test_app/labels/bug", |
|
|
|
|
60
|
|
|
"name": "bug", |
61
|
|
|
"color": "f29513", |
62
|
|
|
"default": True |
63
|
|
|
}, |
64
|
|
|
}, |
65
|
|
|
status=200, |
66
|
|
|
content_type='application/json' |
67
|
|
|
) |
68
|
|
|
|
69
|
|
|
init.init() |
70
|
|
|
|
71
|
|
|
assert changes_config_in_tmpdir.exists() |
72
|
|
|
expected_config = textwrap.dedent( |
73
|
|
|
"""\ |
74
|
|
|
[changes] |
75
|
|
|
auth_token = "foo" |
76
|
|
|
""" |
77
|
|
|
) |
78
|
|
|
assert expected_config == changes_config_in_tmpdir.read_text() |
79
|
|
|
|
80
|
|
|
expected_output = textwrap.dedent( |
81
|
|
|
"""\ |
82
|
|
|
No auth token found, asking for it... |
83
|
|
|
You need a Github Auth Token for changes to create a release. |
84
|
|
|
""" |
85
|
|
|
) |
86
|
|
|
out, _ = capsys.readouterr() |
87
|
|
|
assert expected_output == out |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
@responses.activate |
91
|
|
|
def test_init_finds_auth_token_in_environment( |
|
|
|
|
92
|
|
|
capsys, |
93
|
|
|
git_repo, |
94
|
|
|
with_auth_token_envvar, |
95
|
|
|
changes_config_in_tmpdir, |
96
|
|
|
with_releases_directory_and_bumpversion_file_prompt, |
97
|
|
|
): |
98
|
|
|
responses.add( |
99
|
|
|
responses.GET, |
100
|
|
|
LABEL_URL, |
101
|
|
|
json={ |
102
|
|
|
'bug': { |
103
|
|
|
"id": 208045946, |
104
|
|
|
"url": "https://api.github.com/repos/michaeljoseph/test_app/labels/bug", |
|
|
|
|
105
|
|
|
"name": "bug", |
106
|
|
|
"color": "f29513", |
107
|
|
|
"default": True |
108
|
|
|
}, |
109
|
|
|
}, |
110
|
|
|
status=200, |
111
|
|
|
content_type='application/json' |
112
|
|
|
) |
113
|
|
|
|
114
|
|
|
init.init() |
115
|
|
|
|
116
|
|
|
# envvar setting is not written to the config file |
117
|
|
|
assert not changes_config_in_tmpdir.exists() |
118
|
|
|
|
119
|
|
|
expected_output = textwrap.dedent( |
120
|
|
|
"""\ |
121
|
|
|
Found Github Auth Token in the environment... |
122
|
|
|
""" |
123
|
|
|
) |
124
|
|
|
out, _ = capsys.readouterr() |
125
|
|
|
assert expected_output == out |
126
|
|
|
|
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.