Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Commit e4f0d2f

Browse files
author
Thiago C. D'Ávila
authored
Merge pull request #103 from staticdev/enhancement-git-commands
Enhancement Git Commands
2 parents 1ade09f + 2a564fb commit e4f0d2f

File tree

5 files changed

+213
-113
lines changed

5 files changed

+213
-113
lines changed

mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ warn_unreachable = True
1919
warn_unused_configs = True
2020
warn_unused_ignores = True
2121

22+
[mypy-_pytest.*]
23+
ignore_missing_imports = True
24+
2225
[mypy-inquirer]
2326
ignore_missing_imports = True
2427

src/git_portfolio/__main__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ def checkout(args: Tuple[str]) -> Union[res.ResponseFailure, res.ResponseSuccess
6464
)
6565

6666

67+
@main.command("commit", context_settings={"ignore_unknown_options": True})
68+
@click.argument("args", nargs=-1)
69+
@git_command
70+
def commit(args: Tuple[str]) -> Union[res.ResponseFailure, res.ResponseSuccess]:
71+
"""CLI `git commit` command."""
72+
return guc.GitUseCase().execute(
73+
CONFIG_MANAGER.config.github_selected_repos, "commit", args
74+
)
75+
76+
6777
@main.command("pull")
6878
@click.argument("args", nargs=-1)
6979
@git_command
@@ -74,7 +84,7 @@ def pull(args: Tuple[str]) -> Union[res.ResponseFailure, res.ResponseSuccess]:
7484
)
7585

7686

77-
@main.command("push")
87+
@main.command("push", context_settings={"ignore_unknown_options": True})
7888
@click.argument("args", nargs=-1)
7989
@git_command
8090
def push(args: Tuple[str]) -> Union[res.ResponseFailure, res.ResponseSuccess]:

tests/test_config_manager.py

Lines changed: 79 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,91 @@
11
"""Test cases for the config manager module."""
2-
from unittest.mock import Mock
3-
from unittest.mock import patch
4-
52
import pytest
3+
from _pytest.tmpdir import Path
4+
from pytest_mock import MockerFixture
65

76
from git_portfolio import config_manager as cm
87

98

10-
@patch("os.path.join")
11-
class TestConfigManager:
12-
"""ConfigManager test class."""
9+
@pytest.fixture
10+
def mock_os_join_path(mocker: MockerFixture) -> MockerFixture:
11+
"""Fixture for mocking os.path.join."""
12+
return mocker.patch("os.path.join")
13+
14+
15+
@pytest.fixture
16+
def mock_yaml_dump(mocker: MockerFixture) -> MockerFixture:
17+
"""Fixture for mocking yaml.dump."""
18+
return mocker.patch("yaml.dump")
1319

14-
def test_init_invalid_config(self, os_join_path: Mock, tmp_path: Mock) -> None:
15-
"""It trucantes the file."""
16-
filename = "config1.yaml"
17-
d = tmp_path
18-
p = d / filename
19-
p.write_text("in:valid")
20-
os_join_path.side_effect = [str(d), str(p)]
21-
cm.ConfigManager()
22-
# os_truncate.assert_called_once_with(0)
2320

24-
def test_save_invalid_yaml(self, os_join_path: Mock, tmp_path: Mock) -> None:
25-
"""It trucantes the file."""
26-
filename = "config.yaml"
27-
content = (
28-
"github_access_token: aaaaabbbbbccccc12345"
29-
"github_hostname: ''"
30-
"github_selected_repos:"
31-
" - staticdev/test"
32-
)
33-
d = tmp_path
34-
p = d / filename
35-
p.write_text(content)
36-
os_join_path.side_effect = [str(d), str(p)]
37-
cm.ConfigManager()
38-
# os_truncate.assert_called_once_with(0)
21+
def test_init_invalid_config(tmp_path: Path, mock_os_join_path: MockerFixture) -> None:
22+
"""It trucantes the file."""
23+
filename = "config1.yaml"
24+
d = tmp_path
25+
p = d / filename
26+
p.write_text("in:valid")
27+
mock_os_join_path.side_effect = [str(d), str(p)]
28+
cm.ConfigManager()
29+
# os_truncate.assert_called_once_with(0)
3930

40-
def test_save_config_no_file(self, os_join_path: Mock, tmp_path: Mock) -> None:
41-
"""It raises AttributeError."""
42-
d = tmp_path
43-
os_join_path.side_effect = [str(d), str(d / "config.yaml")]
44-
manager = cm.ConfigManager()
45-
with pytest.raises(AttributeError):
46-
manager.save_config()
4731

48-
def test_save_config_empty_file(self, os_join_path: Mock, tmp_path: Mock) -> None:
49-
"""It raises AttributeError."""
50-
filename = "config2.yaml"
51-
d = tmp_path
52-
p = d / filename
53-
p.write_text("")
54-
os_join_path.side_effect = [str(d), str(p)]
55-
manager = cm.ConfigManager(filename)
56-
with pytest.raises(AttributeError):
57-
manager.save_config()
32+
def test_save_invalid_yaml(tmp_path: Path, mock_os_join_path: MockerFixture) -> None:
33+
"""It trucantes the file."""
34+
filename = "config.yaml"
35+
content = (
36+
"github_access_token: aaaaabbbbbccccc12345"
37+
"github_hostname: ''"
38+
"github_selected_repos:"
39+
" - staticdev/test"
40+
)
41+
d = tmp_path
42+
p = d / filename
43+
p.write_text(content)
44+
mock_os_join_path.side_effect = [str(d), str(p)]
45+
cm.ConfigManager()
46+
# os_truncate.assert_called_once_with(0)
5847

59-
@patch("yaml.dump")
60-
def test_save_config_success(
61-
self, yaml_dump: Mock, os_join_path: Mock, tmp_path: Mock
62-
) -> None:
63-
"""It dumps yaml config file."""
64-
filename = "config.yaml"
65-
content = (
66-
"github_access_token: aaaaabbbbbccccc12345\n"
67-
"github_hostname: ''\n"
68-
"github_selected_repos:\n"
69-
" - staticdev/test\n"
70-
)
71-
d = tmp_path
72-
p = d / filename
73-
p.write_text(content)
74-
os_join_path.side_effect = [str(d), str(p)]
75-
manager = cm.ConfigManager()
48+
49+
def test_save_config_no_file(tmp_path: Path, mock_os_join_path: MockerFixture) -> None:
50+
"""It raises AttributeError."""
51+
d = tmp_path
52+
mock_os_join_path.side_effect = [str(d), str(d / "config.yaml")]
53+
manager = cm.ConfigManager()
54+
with pytest.raises(AttributeError):
7655
manager.save_config()
77-
yaml_dump.assert_called_once()
56+
57+
58+
def test_save_config_empty_file(
59+
tmp_path: Path, mock_os_join_path: MockerFixture
60+
) -> None:
61+
"""It raises AttributeError."""
62+
filename = "config2.yaml"
63+
d = tmp_path
64+
p = d / filename
65+
p.write_text("")
66+
mock_os_join_path.side_effect = [str(d), str(p)]
67+
manager = cm.ConfigManager(filename)
68+
with pytest.raises(AttributeError):
69+
manager.save_config()
70+
71+
72+
def test_save_config_success(
73+
tmp_path: Path,
74+
mock_yaml_dump: MockerFixture,
75+
mock_os_join_path: MockerFixture,
76+
) -> None:
77+
"""It dumps yaml config file."""
78+
filename = "config.yaml"
79+
content = (
80+
"github_access_token: aaaaabbbbbccccc12345\n"
81+
"github_hostname: ''\n"
82+
"github_selected_repos:\n"
83+
" - staticdev/test\n"
84+
)
85+
d = tmp_path
86+
p = d / filename
87+
p.write_text(content)
88+
mock_os_join_path.side_effect = [str(d), str(p)]
89+
manager = cm.ConfigManager()
90+
manager.save_config()
91+
mock_yaml_dump.assert_called_once()

tests/test_github_manager.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
# from git_portfolio import config_manager as cm
66

77

8-
class TestGithubManager:
9-
"""GithubManager test class."""
10-
11-
def test_config_repos_dont_select(self) -> None:
12-
"""It does nothing."""
13-
# config = Mock()
14-
# github_manager = ghm.GithubManager(config)
15-
# github_manager.config_repos(["staticdev/omg"])
16-
pass
8+
def test_config_repos_dont_select() -> None:
9+
"""It does nothing."""
10+
# config = Mock()
11+
# github_manager = ghm.GithubManager(config)
12+
# github_manager.config_repos(["staticdev/omg"])
13+
pass

0 commit comments

Comments
 (0)