-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from jpower432/feat/custom-pull-request-title
test: adds test for custom PR title and fixes test for default value
- Loading branch information
Showing
1 changed file
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,7 +368,65 @@ def test_run_with_provider(tmp_repo: Tuple[str, Repo]) -> None: | |
repo_name="repo", | ||
head_branch="test", | ||
base_branch="main", | ||
title="Automatic updates from trestlebot", | ||
title="Automatic updates from bot", | ||
body="", | ||
) | ||
mock_push.assert_called_once_with(refspec="HEAD:test") | ||
|
||
clean(repo_path, repo) | ||
|
||
|
||
def test_run_with_provider_with_custom_pr_title(tmp_repo: Tuple[str, Repo]) -> None: | ||
"""Test bot run with customer pull request title""" | ||
repo_path, repo = tmp_repo | ||
|
||
# Create a test file | ||
test_file_path = os.path.join(repo_path, "test.txt") | ||
with open(test_file_path, "w") as f: | ||
f.write("Test content") | ||
|
||
mock = Mock(spec=GitProvider) | ||
mock.create_pull_request.return_value = "10" | ||
mock.parse_repository.return_value = ("ns", "repo") | ||
|
||
repo.create_remote("origin", url="git.test.com/test/repo.git") | ||
|
||
with patch("git.remote.Remote.push") as mock_push: | ||
mock_push.return_value = "Mocked result" | ||
|
||
# Test running the bot | ||
commit_sha = bot.run( | ||
working_dir=repo_path, | ||
branch="test", | ||
commit_name="Test User", | ||
commit_email="[email protected]", | ||
commit_message="Test commit message", | ||
author_name="The Author", | ||
author_email="[email protected]", | ||
patterns=["*.txt"], | ||
git_provider=mock, | ||
target_branch="main", | ||
pull_request_title="Test", | ||
dry_run=False, | ||
) | ||
assert commit_sha != "" | ||
|
||
# Verify that the commit is made | ||
commit = next(repo.iter_commits()) | ||
assert commit.message.strip() == "Test commit message" | ||
assert commit.author.name == "The Author" | ||
assert commit.author.email == "[email protected]" | ||
|
||
# Verify that the file is tracked by the commit | ||
assert os.path.basename(test_file_path) in commit.stats.files | ||
|
||
# Verify that the method was called with the expected arguments | ||
mock.create_pull_request.assert_called_once_with( | ||
ns="ns", | ||
repo_name="repo", | ||
head_branch="test", | ||
base_branch="main", | ||
title="Test", | ||
body="", | ||
) | ||
mock_push.assert_called_once_with(refspec="HEAD:test") | ||
|