1
|
|
|
import os |
2
|
|
|
import textwrap |
3
|
|
|
|
4
|
|
|
import pytest |
5
|
|
|
from plumbum.cmd import git |
|
|
|
|
6
|
|
|
|
7
|
|
|
from changes.commands import init |
8
|
|
|
from .conftest import AUTH_TOKEN_ENVVAR |
9
|
|
|
|
10
|
|
|
@pytest.fixture |
11
|
|
|
def init_prompts(mocker): |
12
|
|
|
_ = mocker.patch( |
13
|
|
|
'changes.config.click.launch', |
14
|
|
|
autospec=True, |
15
|
|
|
) |
16
|
|
|
|
17
|
|
|
prompt = mocker.patch( |
18
|
|
|
'changes.config.click.prompt', |
19
|
|
|
autospec=True, |
20
|
|
|
) |
21
|
|
|
prompt.side_effect = [ |
22
|
|
|
'foo', |
23
|
|
|
'docs/releases', |
24
|
|
|
'test_app/__init__.py', |
25
|
|
|
'.' |
26
|
|
|
] |
27
|
|
|
|
28
|
|
|
saved_token = None |
29
|
|
|
if os.environ.get(AUTH_TOKEN_ENVVAR): |
30
|
|
|
saved_token = os.environ[AUTH_TOKEN_ENVVAR] |
31
|
|
|
del os.environ[AUTH_TOKEN_ENVVAR] |
32
|
|
|
|
33
|
|
|
yield |
34
|
|
|
|
35
|
|
|
if saved_token: |
36
|
|
|
os.environ[AUTH_TOKEN_ENVVAR] = saved_token |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
def test_init_prompts_for_auth_token_and_writes_tool_config( |
|
|
|
|
40
|
|
|
capsys, |
41
|
|
|
git_repo, |
42
|
|
|
patch_user_home_to_tmpdir_path, |
43
|
|
|
init_prompts, |
|
|
|
|
44
|
|
|
): |
45
|
|
|
|
46
|
|
|
init.init() |
47
|
|
|
|
48
|
|
|
assert patch_user_home_to_tmpdir_path.exists() |
49
|
|
|
expected_config = textwrap.dedent( |
50
|
|
|
"""\ |
51
|
|
|
[changes] |
52
|
|
|
auth_token = "foo" |
53
|
|
|
""" |
54
|
|
|
) |
55
|
|
|
assert expected_config == patch_user_home_to_tmpdir_path.read_text() |
56
|
|
|
|
57
|
|
|
expected_output = textwrap.dedent( |
58
|
|
|
"""\ |
59
|
|
|
No auth token found, asking for it... |
60
|
|
|
You need a Github Auth Token for changes to create a release. |
61
|
|
|
Indexing repository... |
62
|
|
|
""" |
63
|
|
|
) |
64
|
|
|
out, _ = capsys.readouterr() |
65
|
|
|
assert expected_output == out |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
def test_init_finds_auth_token_in_environment( |
|
|
|
|
69
|
|
|
capsys, |
70
|
|
|
git_repo, |
71
|
|
|
with_auth_token_envvar, |
72
|
|
|
patch_user_home_to_tmpdir_path, |
73
|
|
|
with_releases_directory_and_bumpversion_file_prompt, |
74
|
|
|
): |
75
|
|
|
|
76
|
|
|
init.init() |
77
|
|
|
|
78
|
|
|
assert patch_user_home_to_tmpdir_path.exists() |
79
|
|
|
expected_config = textwrap.dedent( |
80
|
|
|
"""\ |
81
|
|
|
[changes] |
82
|
|
|
auth_token = "foo" |
83
|
|
|
""" |
84
|
|
|
) |
85
|
|
|
assert expected_config == patch_user_home_to_tmpdir_path.read_text() |
86
|
|
|
|
87
|
|
|
expected_output = textwrap.dedent( |
88
|
|
|
"""\ |
89
|
|
|
Found Github Auth Token in the environment... |
90
|
|
|
Indexing repository... |
91
|
|
|
""" |
92
|
|
|
) |
93
|
|
|
out, _ = capsys.readouterr() |
94
|
|
|
assert expected_output == out |
95
|
|
|
|
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.