Completed
Push — publish ( 2db8ae...f5ec56 )
by Michael
05:19
created

test_publish()   B

Complexity

Conditions 2

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 44
rs 8.8571
1
import shlex
2
import textwrap
3
from pathlib import Path
4
5
from plumbum.cmd import git
0 ignored issues
show
Configuration introduced by
The import plumbum.cmd 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
import pytest
7
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...
8
9
from changes.commands import init, stage, publish
10
from .conftest import github_merge_commit, ISSUE_URL, LABEL_URL, PULL_REQUEST_JSON, BUG_LABEL_JSON
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (98/79).

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

Loading history...
11
12
13
@pytest.fixture
14
def answer_prompts(mocker):
15
    prompt = mocker.patch(
16
        'changes.commands.publish.click.confirm',
17
        autospec=True,
18
    )
19
    prompt.side_effect = [
20
        'y'
21
    ]
22
23
24
def test_publish_no_staged_release(
25
    capsys,
26
    configured
27
):
28
    init.init()
29
    publish.publish()
30
31
    expected_output = textwrap.dedent(
32
        """\
33
        No staged release to publish...
34
        """
35
    )
36
    out, _ = capsys.readouterr()
37
    assert expected_output == out
38
39
40
@responses.activate
41
def test_publish(
42
    capsys,
43
    configured,
44
    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 14).

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...
45
):
46
47
    github_merge_commit(111)
48
    responses.add(
49
        responses.GET,
50
        ISSUE_URL.format('111'),
51
        json=PULL_REQUEST_JSON,
52
        status=200,
53
        content_type='application/json'
54
    )
55
    responses.add(
56
        responses.GET,
57
        LABEL_URL,
58
        json=BUG_LABEL_JSON,
59
        status=200,
60
        content_type='application/json'
61
    )
62
63
    init.init()
64
    stage.stage(
65
        draft=False,
66
        release_name='Icarus',
67
        release_description='The first flight'
68
    )
69
    publish.publish()
70
71
    release_notes_path = Path('docs').joinpath('releases').joinpath('0.0.2.md')
72
73
    pre = textwrap.dedent(
74
        """\
75
        Staging [fix] release for version 0.0.2...
76
        Running: bumpversion --verbose --allow-dirty --no-commit --no-tag patch...
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (82/79).

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

Loading history...
77
        Generating Release...
78
        Writing release notes to {release_notes_path}...
79
        Publishing release 0.0.2...
80
        Running: git add version.txt .bumpversion.cfg {release_notes_path}...
81
        Running: git commit --message="# 0.0.2 (2017-10-29) Icarus
82
        """.format(
83
            release_notes_path=release_notes_path,
84
        )
85
    ).splitlines()
86
87
    expected_release_notes_content = [
88
        'The first flight',
89
        '## Bug',
90
        '    ',
91
        '* #111 The title of the pull request',
92
        '    ',
93
    ]
94
95
    post = textwrap.dedent(
96
        """\
97
        "...
98
        Running: git tag 0.0.2...
99
        Running: git push --tags...
100
        Creating GitHub Releases...
101
        Published release 0.0.2...
102
        Verifying release 0.0.2...
103
        👍 Release verified...
104
        """
105
    ).splitlines()
106
107
    out, _ = capsys.readouterr()
108
109
    assert pre + expected_release_notes_content + post == out.splitlines()
110
111
    last_commit = git(shlex.split('show --name-only'))
112
    expected_files = [
113
        'version.txt',
114
        '.bumpversion.cfg',
115
        release_notes_path,
116
    ]
117
    assert [
118
        expected_file
119
        for expected_file in expected_files
120
        if str(expected_file) in last_commit
121
    ]
122
123
    # verify tag creation
124
    assert '0.0.2' in git(shlex.split('tag --list'))
125
126
    # verify remote pushed
127
128
129
    # patch releases api call
130
    # patch release api verification call
131