|
12 | 12 | NoAnswersError,
|
13 | 13 | NoCommitBackupError,
|
14 | 14 | NotAGitProjectError,
|
| 15 | + NotAllowed, |
15 | 16 | NothingToCommitError,
|
16 | 17 | )
|
17 | 18 |
|
@@ -109,6 +110,51 @@ def test_commit_command_with_dry_run_option(config, mocker: MockFixture):
|
109 | 110 | commit_cmd()
|
110 | 111 |
|
111 | 112 |
|
| 113 | +@pytest.mark.usefixtures("staging_is_clean") |
| 114 | +def test_commit_command_with_write_message_to_file_option( |
| 115 | + config, tmp_path, mocker: MockFixture |
| 116 | +): |
| 117 | + tmp_file = tmp_path / "message" |
| 118 | + |
| 119 | + prompt_mock = mocker.patch("questionary.prompt") |
| 120 | + prompt_mock.return_value = { |
| 121 | + "prefix": "feat", |
| 122 | + "subject": "user created", |
| 123 | + "scope": "", |
| 124 | + "is_breaking_change": False, |
| 125 | + "body": "", |
| 126 | + "footer": "", |
| 127 | + } |
| 128 | + |
| 129 | + commit_mock = mocker.patch("commitizen.git.commit") |
| 130 | + commit_mock.return_value = cmd.Command("success", "", b"", b"", 0) |
| 131 | + success_mock = mocker.patch("commitizen.out.success") |
| 132 | + |
| 133 | + commands.Commit(config, {"write_message_to_file": tmp_file})() |
| 134 | + success_mock.assert_called_once() |
| 135 | + assert tmp_file.exists() |
| 136 | + assert tmp_file.read_text() == "feat: user created" |
| 137 | + |
| 138 | + |
| 139 | +@pytest.mark.usefixtures("staging_is_clean") |
| 140 | +def test_commit_command_with_invalid_write_message_to_file_option( |
| 141 | + config, tmp_path, mocker: MockFixture |
| 142 | +): |
| 143 | + prompt_mock = mocker.patch("questionary.prompt") |
| 144 | + prompt_mock.return_value = { |
| 145 | + "prefix": "feat", |
| 146 | + "subject": "user created", |
| 147 | + "scope": "", |
| 148 | + "is_breaking_change": False, |
| 149 | + "body": "", |
| 150 | + "footer": "", |
| 151 | + } |
| 152 | + |
| 153 | + with pytest.raises(NotAllowed): |
| 154 | + commit_cmd = commands.Commit(config, {"write_message_to_file": tmp_path}) |
| 155 | + commit_cmd() |
| 156 | + |
| 157 | + |
112 | 158 | @pytest.mark.usefixtures("staging_is_clean")
|
113 | 159 | def test_commit_command_with_signoff_option(config, mocker: MockFixture):
|
114 | 160 | prompt_mock = mocker.patch("questionary.prompt")
|
|
0 commit comments