Skip to content

Commit 3acd8ce

Browse files
gpongelliLee-W
authored andcommitted
fix(test): set git to work with gpg
1 parent 049a194 commit 3acd8ce

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

tests/commands/test_bump_command.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def test_bump_minor_increment_annotated(commit_msg, mocker):
7171

7272

7373
@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file"))
74-
@pytest.mark.usefixtures("tmp_commitizen_project")
75-
def test_bump_minor_increment_annotated(commit_msg, mocker):
74+
@pytest.mark.usefixtures("tmp_commitizen_project_with_gpg")
75+
def test_bump_minor_increment_signed(commit_msg, mocker):
7676
create_file_and_commit(commit_msg)
7777
testargs = ["cz", "bump", "--yes", "--signed-tag"]
7878
mocker.patch.object(sys, "argv", testargs)
@@ -107,9 +107,9 @@ def test_bump_minor_increment_annotated_config_file(
107107

108108
@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file"))
109109
def test_bump_minor_increment_signed_config_file(
110-
commit_msg, mocker, tmp_commitizen_project
110+
commit_msg, mocker, tmp_commitizen_project_with_gpg
111111
):
112-
tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml")
112+
tmp_commitizen_cfg_file = tmp_commitizen_project_with_gpg.join("pyproject.toml")
113113
tmp_commitizen_cfg_file.write(
114114
f"{tmp_commitizen_cfg_file.read()}\n" f"signed_tag = 1"
115115
)

tests/conftest.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22

3+
import re
34
import pytest
45

56
from commitizen import cmd, defaults
@@ -23,6 +24,31 @@ def tmp_commitizen_project(tmp_git_project):
2324
yield tmp_git_project
2425

2526

27+
@pytest.fixture(scope="function")
28+
def tmp_commitizen_project_with_gpg(tmp_commitizen_project):
29+
_gpg_file = tmp_commitizen_project.join('gpg_setup')
30+
with open(_gpg_file, "w", newline='') as f:
31+
f.write("Key-Type: default" + os.linesep)
32+
f.write("Subkey-Type: default" + os.linesep)
33+
f.write("Name-Real: Joe Tester" + os.linesep)
34+
f.write("Name-Comment: with stupid passphrase" + os.linesep)
35+
f.write("Name-Email: joe@foo.bar" + os.linesep)
36+
f.write("Expire-Date: 0" + os.linesep)
37+
f.write("Passphrase: abc" + os.linesep)
38+
39+
cmd.run(f"gpg --batch --generate-key {_gpg_file}")
40+
41+
_new_key = cmd.run(f"gpg --list-secret-keys joe@foo.bar")
42+
_m = re.search(f"[a-zA-Z0-9 \[\]-_]*{os.linesep}[ ]*([0-9A-Za-z]*){os.linesep}[{os.linesep}a-zA-Z0-9 \[\]-_<>@]*",
43+
_new_key.out)
44+
if _m:
45+
_key_id = _m.group(1)
46+
cmd.run("git config --global commit.gpgsign true")
47+
cmd.run(f"git config --global user.signingkey {_key_id}")
48+
49+
yield tmp_commitizen_project
50+
51+
2652
@pytest.fixture()
2753
def config():
2854
_config = BaseConfig()

0 commit comments

Comments
 (0)