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
|
|
|
|
11
|
|
|
@pytest.fixture |
12
|
|
|
def init_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
|
|
|
'test_app/__init__.py', |
26
|
|
|
'.' |
27
|
|
|
] |
28
|
|
|
|
29
|
|
|
prompt = mocker.patch( |
30
|
|
|
'changes.config.read_user_choices', |
31
|
|
|
autospec=True |
32
|
|
|
) |
33
|
|
|
prompt.return_value = ['enhancement', '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
|
|
|
def test_init_prompts_for_auth_token_and_writes_tool_config( |
|
|
|
|
47
|
|
|
capsys, |
48
|
|
|
git_repo, |
49
|
|
|
patch_user_home_to_tmpdir_path, |
50
|
|
|
init_prompts, |
|
|
|
|
51
|
|
|
): |
52
|
|
|
|
53
|
|
|
init.init() |
54
|
|
|
|
55
|
|
|
assert patch_user_home_to_tmpdir_path.exists() |
56
|
|
|
expected_config = textwrap.dedent( |
57
|
|
|
"""\ |
58
|
|
|
[changes] |
59
|
|
|
auth_token = "foo" |
60
|
|
|
""" |
61
|
|
|
) |
62
|
|
|
assert expected_config == patch_user_home_to_tmpdir_path.read_text() |
63
|
|
|
|
64
|
|
|
expected_output = textwrap.dedent( |
65
|
|
|
"""\ |
66
|
|
|
No auth token found, asking for it... |
67
|
|
|
You need a Github Auth Token for changes to create a release. |
68
|
|
|
Indexing repository... |
69
|
|
|
""" |
70
|
|
|
) |
71
|
|
|
out, _ = capsys.readouterr() |
72
|
|
|
assert expected_output == out |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
def test_init_finds_auth_token_in_environment( |
|
|
|
|
76
|
|
|
capsys, |
77
|
|
|
git_repo, |
78
|
|
|
with_auth_token_envvar, |
79
|
|
|
patch_user_home_to_tmpdir_path, |
80
|
|
|
with_releases_directory_and_bumpversion_file_prompt, |
81
|
|
|
): |
82
|
|
|
|
83
|
|
|
init.init() |
84
|
|
|
|
85
|
|
|
assert patch_user_home_to_tmpdir_path.exists() |
86
|
|
|
expected_config = textwrap.dedent( |
87
|
|
|
"""\ |
88
|
|
|
[changes] |
89
|
|
|
auth_token = "foo" |
90
|
|
|
""" |
91
|
|
|
) |
92
|
|
|
assert expected_config == patch_user_home_to_tmpdir_path.read_text() |
93
|
|
|
|
94
|
|
|
expected_output = textwrap.dedent( |
95
|
|
|
"""\ |
96
|
|
|
Found Github Auth Token in the environment... |
97
|
|
|
Indexing repository... |
98
|
|
|
""" |
99
|
|
|
) |
100
|
|
|
out, _ = capsys.readouterr() |
101
|
|
|
assert expected_output == out |
102
|
|
|
|
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.