11from subprocess import CalledProcessError
22from unittest .mock import (
33 MagicMock ,
4- patch ,
4+ patch , call ,
55)
66
77import pytest
1010 ReleaseError ,
1111 _trigger_release ,
1212)
13+ from exasol .toolbox .util .version import Version
14+ import noxconfig
1315
1416
1517@pytest .fixture (scope = "class" )
1618def mock_from_poetry ():
1719 with patch (
18- "exasol.toolbox.nox._release.Version.from_poetry" , return_value = "0.3.0"
20+ "exasol.toolbox.nox._release.Version.from_poetry" , return_value = Version ( major = 0 , minor = 3 , patch = 0 )
1921 ) as mock_obj :
2022 yield mock_obj
2123
@@ -40,6 +42,45 @@ def simulate_pass(args, **kwargs):
4042 result = _trigger_release ()
4143 assert result == mock_from_poetry .return_value
4244
45+
46+ def test_creates_major_version_tag (self , mock_from_poetry ):
47+ def simulate_pass (args , ** kwargs ):
48+ return self ._get_subprocess_run_mock (args )
49+
50+ with patch ("subprocess.run" , side_effect = simulate_pass ) as subprocess_mock :
51+ result = _trigger_release ()
52+ assert subprocess_mock .mock_calls == [call (('git' , 'remote' , 'show' , 'origin' ), capture_output = True , text = True , check = True ),
53+ call (('git' , 'checkout' , 'main' ), capture_output = True , text = True , check = True ),
54+ call (('git' , 'pull' ), capture_output = True , text = True , check = True ),
55+ call (('git' , 'tag' , '--list' ), capture_output = True , text = True , check = True ),
56+ call (('gh' , 'release' , 'list' ), capture_output = True , text = True , check = True ),
57+ call (('git' , 'tag' , '0.3.0' ), capture_output = True , text = True , check = True ),
58+ call (('git' , 'push' , 'origin' , '0.3.0' ), capture_output = True , text = True , check = True ),
59+ call (('git' , 'tag' , '-f' , 'v0' ), capture_output = True , text = True , check = True ),
60+ call (('git' , 'push' , '-f' , 'origin' , 'v0' ), capture_output = True , text = True , check = True )]
61+ assert result == mock_from_poetry .return_value
62+
63+ @pytest .fixture
64+ def mock_project_config (self , monkeypatch ):
65+ class DummyConfig :
66+ pass
67+ monkeypatch .setattr (noxconfig , "PROJECT_CONFIG" , DummyConfig ())
68+
69+ def test_not_creates_major_version_tag (self , mock_from_poetry , mock_project_config ):
70+ def simulate_pass (args , ** kwargs ):
71+ return self ._get_subprocess_run_mock (args )
72+
73+ with patch ("subprocess.run" , side_effect = simulate_pass ) as subprocess_mock :
74+ result = _trigger_release ()
75+ assert subprocess_mock .mock_calls == [call (('git' , 'remote' , 'show' , 'origin' ), capture_output = True , text = True , check = True ),
76+ call (('git' , 'checkout' , 'main' ), capture_output = True , text = True , check = True ),
77+ call (('git' , 'pull' ), capture_output = True , text = True , check = True ),
78+ call (('git' , 'tag' , '--list' ), capture_output = True , text = True , check = True ),
79+ call (('gh' , 'release' , 'list' ), capture_output = True , text = True , check = True ),
80+ call (('git' , 'tag' , '0.3.0' ), capture_output = True , text = True , check = True ),
81+ call (('git' , 'push' , 'origin' , '0.3.0' ), capture_output = True , text = True , check = True )]
82+ assert result == mock_from_poetry .return_value
83+
4384 @pytest .mark .parametrize (
4485 "error_cmd" ,
4586 [
0 commit comments