Skip to content

Commit

Permalink
style(test-changelog): change to direct fixture reference & improve c…
Browse files Browse the repository at this point in the history
…larity
  • Loading branch information
codejedi365 committed Mar 2, 2024
1 parent db4eb8e commit ff082fa
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions tests/command_line/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,27 @@
from tests.fixtures.example_project import ExProjectDir, UseReleaseNotesTemplateFn


changelog_subcmd = changelog.name or changelog.__name__
changelog_subcmd = changelog.name or changelog.__name__ # type: ignore


@pytest.mark.parametrize(
"repo,tag",
[
(lazy_fixture("repo_with_no_tags_angular_commits"), None),
(lazy_fixture("repo_with_single_branch_angular_commits"), "v0.1.1"),
(lazy_fixture(repo_with_no_tags_angular_commits.__name__), None),
(lazy_fixture(repo_with_single_branch_angular_commits.__name__), "v0.1.1"),
(
lazy_fixture("repo_with_single_branch_and_prereleases_angular_commits"),
lazy_fixture(repo_with_single_branch_and_prereleases_angular_commits.__name__),
"v0.2.0",
),
(
lazy_fixture(
"repo_w_github_flow_w_feature_release_channel_angular_commits"
repo_w_github_flow_w_feature_release_channel_angular_commits.__name__
),
"v0.2.0",
),
(lazy_fixture("repo_with_git_flow_angular_commits"), "v1.0.0"),
(lazy_fixture(repo_with_git_flow_angular_commits.__name__), "v1.0.0"),
(
lazy_fixture("repo_with_git_flow_and_release_channels_angular_commits"),
lazy_fixture(repo_with_git_flow_and_release_channels_angular_commits.__name__),
"v1.1.0-alpha.3",
),
],
Expand Down Expand Up @@ -119,7 +119,7 @@ def test_changelog_noop_is_noop(
main, ["--noop", changelog_subcmd, *args]
)

assert result.exit_code == 0
assert 0 == result.exit_code

dcmp = filecmp.dircmp(str(example_project_dir.resolve()), tempdir)

Expand Down Expand Up @@ -187,7 +187,7 @@ def test_changelog_content_regenerated(


# Just need to test that it works for "a" project, not all
@pytest.mark.usefixtures("repo_with_single_branch_and_prereleases_angular_commits")
@pytest.mark.usefixtures(repo_with_single_branch_and_prereleases_angular_commits.__name__)
@pytest.mark.parametrize(
"args", [("--post-to-release-tag", "v1.99.91910000000000000000000000000")]
)
Expand All @@ -202,11 +202,12 @@ def test_changelog_release_tag_not_in_history(
shutil.copytree(src=str(example_project_dir.resolve()), dst=tempdir)

result = cli_runner.invoke(main, [changelog_subcmd, *args])
assert result.exit_code == 2

assert 2 == result.exit_code
assert "not in release history" in result.stderr.lower()


@pytest.mark.usefixtures("repo_with_single_branch_and_prereleases_angular_commits")
@pytest.mark.usefixtures(repo_with_single_branch_and_prereleases_angular_commits.__name__)
@pytest.mark.parametrize("args", [("--post-to-release-tag", "v0.1.0")])
def test_changelog_post_to_release(
args: list[str],
Expand All @@ -232,6 +233,12 @@ def test_changelog_post_to_release(
session.mount("http://", mock_adapter)
session.mount("https://", mock_adapter)

expected_request_url = "https://{api_url}/repos/{owner}/{repo_name}/releases".format(
api_url=Github.DEFAULT_API_DOMAIN,
owner=EXAMPLE_REPO_OWNER,
repo_name=EXAMPLE_REPO_NAME,
)

# Patch out env vars that affect changelog URLs but only get set in e.g.
# Github actions
with mock.patch(
Expand All @@ -242,17 +249,12 @@ def test_changelog_post_to_release(
m.delenv("CI_PROJECT_NAMESPACE", raising=False)
result = cli_runner.invoke(main, [changelog_subcmd, *args])

assert result.exit_code == 0
assert 0 == result.exit_code

assert mocker.called
assert mock_adapter.called and mock_adapter.last_request is not None
assert mock_adapter.last_request.url == (
"https://{api_url}/repos/{owner}/{repo_name}/releases".format(
api_url=Github.DEFAULT_API_DOMAIN,
owner=EXAMPLE_REPO_OWNER,
repo_name=EXAMPLE_REPO_NAME,
)
)
assert mock_adapter.called
assert mock_adapter.last_request is not None
assert expected_request_url == mock_adapter.last_request.url


def test_custom_release_notes_template(
Expand Down Expand Up @@ -285,10 +287,11 @@ def test_custom_release_notes_template(
).render(version=version, release=release) + '\n'

# Assert
assert resp.exit_code == 0, (
assert 0 == resp.exit_code, (
"Unexpected failure in command "
f"'semantic-release {changelog_subcmd} --post-to-release-tag {tag}': "
+ resp.stderr
)
assert post_mocker.call_count == 1 and post_mocker.last_request is not None
assert 1 == post_mocker.call_count
assert post_mocker.last_request is not None
assert expected_release_notes == post_mocker.last_request.json()["body"]

0 comments on commit ff082fa

Please sign in to comment.