def test_main_function(mock_env, mock_config, monkeypatch): """ GIVEN a valid patch_rebaser configuration and environment WHEN main() is called THEN GitRepo.rebase_to_hash is called with the correct parameters AND GitRepo.git.push is called AND the git tag pushed contains the version from the branch name """ branch_name = 'test-16.1-patches' commit_to_rebase_to = '123456a' repo = MagicMock() with monkeypatch.context() as m: m.setattr(patch_rebaser.patch_rebaser, 'GitRepo', Mock(return_value=repo)) m.setattr(patch_rebaser.patch_rebaser, 'get_patches_repo', Mock()) m.setattr(patch_rebaser.patch_rebaser, 'get_patches_branch', Mock(return_value=branch_name)) main() repo.branch.rebase_to_hash.assert_called_once_with(branch_name, commit_to_rebase_to) repo.git.push.assert_called() # Check version in tag assert repo.git.push.mock_calls[0].args[2].startswith( 'private-rebaser-16.1-') is True
def test_packages_to_process_skips_packages_not_in_the_list( mock_env, mock_config_with_pkgs_to_process, monkeypatch): """ GIVEN a valid patch_rebaser configuration and environment WITH packages_to_process set to a list of package names WHEN main() is called AND the package name given by DLRN is not in packages_to_process THEN the Rebaser is not called and the script ends early """ mock_gitrepo = Mock() with monkeypatch.context() as m: m.setattr(patch_rebaser.patch_rebaser, 'GitRepo', mock_gitrepo) main() mock_gitrepo.assert_not_called()
def test_rebaser_missing_patches_branch_create( mock_env, mock_config_with_create_patches_branch, monkeypatch): """ GIVEN a valid patch_rebaser configuration and environment WHEN main() is called AND the -patches branch is missing AND create_patches_branch is set to true THEN create_patches_branch is called """ repo = MagicMock() with monkeypatch.context() as m: m.setattr(patch_rebaser.patch_rebaser, 'GitRepo', Mock(return_value=repo)) m.setattr(patch_rebaser.patch_rebaser, 'get_patches_repo', Mock()) m.setattr(patch_rebaser.patch_rebaser, 'get_patches_branch', Mock(return_value=None)) patch_rebaser.patch_rebaser.create_patches_branch = MagicMock() main() assert patch_rebaser.patch_rebaser.create_patches_branch.called is True
def test_main_function(mock_env, mock_config, monkeypatch): """ GIVEN a valid patch_rebaser configuration and environment WHEN main() is called THEN GitRepo.rebase_to_hash is called with the correct parameters AND GitRepo.git.push is called """ branch_name = 'test_branch' commit_to_rebase_to = '123456a' repo = MagicMock() with monkeypatch.context() as m: m.setattr(patch_rebaser.patch_rebaser, 'GitRepo', Mock(return_value=repo)) m.setattr(patch_rebaser.patch_rebaser, 'get_patches_repo', Mock()) m.setattr(patch_rebaser.patch_rebaser, 'get_patches_branch', Mock(return_value=branch_name)) main() repo.branch.rebase_to_hash.assert_called_once_with(branch_name, commit_to_rebase_to) repo.git.push.assert_called()