Completed
Push — publish ( 2881fa )
by Michael
05:30
created

answer_prompts()   B

Complexity

Conditions 3

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
c 0
b 0
f 0
dl 0
loc 33
rs 8.8571
1
import os
2
import textwrap
3
4
import pytest
5
import responses
0 ignored issues
show
Configuration introduced by
The import responses could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

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.

Loading history...
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(
0 ignored issues
show
Coding Style Naming introduced by
The name test_init_prompts_for_au..._and_writes_tool_config does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
48
    capsys,
49
    git_repo,
50
    changes_config_in_tmpdir,
51
    answer_prompts,
0 ignored issues
show
Comprehensibility Bug introduced by
answer_prompts is re-defining a name which is already available in the outer-scope (previously defined on line 12).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
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",
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (88/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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(
0 ignored issues
show
Coding Style Naming introduced by
The name test_init_finds_auth_token_in_environment does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style Naming introduced by
The name with_releases_directory_...bumpversion_file_prompt does not conform to the argument naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
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",
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (88/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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