Skip to content

Commit 7327f78

Browse files
nejchJohnVillalovos
authored andcommitted
test(cli): improve coverage for custom actions
1 parent 98ccc3c commit 7327f78

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ coverage
22
pytest==7.1.2
33
pytest-console-scripts==1.3.1
44
pytest-cov
5+
PyYaml>=5.2
56
responses

tests/functional/cli/test_cli.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import pytest
1010
import responses
11+
import yaml
1112

1213
from gitlab import __version__, config
1314
from gitlab.const import DEFAULT_URL
@@ -135,11 +136,36 @@ def test_invalid_auth_config(script_runner, monkeypatch, fixture_dir):
135136
assert "401" in ret.stderr
136137

137138

138-
def test_fields(gitlab_cli, project_file):
139-
cmd = "-o", "json", "--fields", "default_branch", "project", "list"
139+
format_matrix = [
140+
("json", json.loads),
141+
("yaml", yaml.safe_load),
142+
]
143+
144+
145+
@pytest.mark.parametrize("format,loader", format_matrix)
146+
def test_cli_display(gitlab_cli, project, format, loader):
147+
cmd = ["-o", format, "project", "get", "--id", project.id]
148+
149+
ret = gitlab_cli(cmd)
150+
assert ret.success
151+
152+
content = loader(ret.stdout.strip())
153+
assert content["id"] == project.id
154+
155+
156+
@pytest.mark.parametrize("format,loader", format_matrix)
157+
def test_cli_fields_in_list(gitlab_cli, project_file, format, loader):
158+
cmd = [
159+
"-o",
160+
format,
161+
"--fields",
162+
"default_branch",
163+
"project",
164+
"list",
165+
]
140166

141167
ret = gitlab_cli(cmd)
142168
assert ret.success
143169

144-
content = json.loads(ret.stdout.strip())
170+
content = loader(ret.stdout.strip())
145171
assert ["default_branch" in item for item in content]

tests/functional/cli/test_cli_projects.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def project_export(project):
4646
return export
4747

4848

49-
def test_project_export_download(gitlab_config, project_export):
49+
def test_project_export_download_custom_action(gitlab_config, project_export):
50+
"""Tests custom action on ProjectManager"""
5051
cmd = [
5152
"gitlab",
5253
"--config-file",
@@ -59,3 +60,10 @@ def test_project_export_download(gitlab_config, project_export):
5960

6061
export = subprocess.run(cmd, capture_output=True, check=True)
6162
assert export.returncode == 0
63+
64+
65+
def test_project_languages_custom_action(gitlab_cli, project, project_file):
66+
"""Tests custom action on Project/RESTObject"""
67+
cmd = ["project", "languages", "--id", project.id]
68+
ret = gitlab_cli(cmd)
69+
assert ret.success

0 commit comments

Comments
 (0)