Skip to content

Commit

Permalink
Test: Prepare with conventional commits
Browse files Browse the repository at this point in the history
  • Loading branch information
y0urself committed Aug 30, 2021
1 parent cac2c5d commit 85d0b48
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
7 changes: 4 additions & 3 deletions pontos/release/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ def prepare(
project=project,
config=args.cc_config,
)
changelog_builder = changelog.ChangelogBuilder(
changelog_builder = changelog_module.ChangelogBuilder(
shell_cmd_runner=shell_cmd_runner,
args=cargs,
)

output_file = changelog_builder.create_changelog_file()
ok(f"Created changelog {output}")
commit_msg = f'Changelog created for release to {release_version}'
Expand All @@ -112,7 +113,7 @@ def prepare(
git_signing_key=git_signing_key,
)
changelog_bool = False
# Try to get the unreleased section of the specific version
# Remove the header for the release text
changelog_text = output_file.read_text().replace(
"# Changelog\n\n"
"All notable changes to this project "
Expand All @@ -137,7 +138,7 @@ def prepare(
)

if not updated:
# Try to get unversioned unrlease section
# Try to get unversioned unrelease section
updated, changelog_text = changelog_module.update(
change_log_path.read_text(),
release_version,
Expand Down
49 changes: 48 additions & 1 deletion tests/release/test_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from dataclasses import dataclass
from pathlib import Path
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch

import requests

Expand Down Expand Up @@ -199,3 +199,50 @@ def test_not_release_when_updating_version_fails(self):
args=args,
)
self.assertFalse(released)

@patch('pontos.changelog.changelog')
def test_prepare_coventional_commits(self, changelog_mock):
# fake_path_class = MagicMock(spec=Path)
fake_requests = MagicMock(spec=requests)
fake_version = MagicMock(spec=version)
fake_version.main.return_value = (True, 'MyProject.conf')

own_path = Path(__file__).absolute().parent
release_file = own_path.parent.parent / '.release.md'

builder = changelog_mock.ChangelogBuilder.return_value
builder.create_changelog_file.return_value = own_path / 'v1.2.3.md'

args = [
'prepare',
'--release-version',
'1.2.3',
'-CC',
]
runner = lambda x: StdOutput('')
released = release.main(
shell_cmd_runner=runner,
_path=Path,
_requests=fake_requests,
_version=fake_version,
_changelog=changelog_mock,
leave=False,
args=args,
)
self.assertTrue(released)

expected_release_content = """## [21.8.1] - 2021-08-23
## Added
* Need for commits. [1234567](https://github.com/foo/bar/commit/1234567)
## Changed
* fooooo. [1234568](https://github.com/foo/bar/commit/1234568)
[21.8.1]: https://github.com/y0urself/test_workflows/compare/21.8.0...21.8.1"""

self.assertEqual(release_file.read_text(), expected_release_content)

release_file.unlink()
15 changes: 15 additions & 0 deletions tests/release/v1.2.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

All notable changes to this project will be documented in this file.

## [21.8.1] - 2021-08-23

## Added

* Need for commits. [1234567](https://github.com/foo/bar/commit/1234567)

## Changed

* fooooo. [1234568](https://github.com/foo/bar/commit/1234568)

[21.8.1]: https://github.com/y0urself/test_workflows/compare/21.8.0...21.8.1

0 comments on commit 85d0b48

Please sign in to comment.