Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit09a973e

Browse files
authored
Merge pull request#1721 from python-gitlab/test/cli-coverage
test(cli): improve basic CLI coverage
2 parents93a3893 +381c748 commit09a973e

File tree

15 files changed

+104
-34
lines changed

15 files changed

+104
-34
lines changed

‎gitlab/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def _parse_value(v: Any) -> Any:
178178
returnv
179179

180180

181-
defdocs()->argparse.ArgumentParser:
181+
defdocs()->argparse.ArgumentParser:# pragma: no cover
182182
"""
183183
Provide a statically generated parser for sphinx only, so we don't need
184184
to provide dummy gitlab config for readthedocs.
@@ -208,15 +208,15 @@ def main() -> None:
208208
sys.exit(0)
209209
sys.exit(e)
210210
# We only support v4 API at this time
211-
ifconfig.api_versionnotin ("4",):
211+
ifconfig.api_versionnotin ("4",):# dead code # pragma: no cover
212212
raiseModuleNotFoundError(name=f"gitlab.v{config.api_version}.cli")
213213

214214
# Now we build the entire set of subcommands and do the complete parsing
215215
parser=_get_parser()
216216
try:
217217
importargcomplete# type: ignore
218218

219-
argcomplete.autocomplete(parser)
219+
argcomplete.autocomplete(parser)# pragma: no cover
220220
exceptException:
221221
pass
222222
args=parser.parse_args()

‎pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ files = "."
1212
module = [
1313
"docs.*",
1414
"docs.ext.*",
15+
"tests.*",
1516
"tests.functional.*",
1617
"tests.functional.api.*",
1718
"tests.unit.*",

‎requirements-docker.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
-r requirements.txt
22
-r requirements-test.txt
33
docker-compose==1.29.2 # prevent inconsistent .env behavior from system install
4-
pytest-console-scripts
54
pytest-docker

‎requirements-test.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
coverage
22
httmock
3-
mock
43
pytest
4+
pytest-console-scripts==1.2.1
55
pytest-cov
66
responses

‎tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
importpytest
2+
3+
4+
@pytest.fixture(scope="session")
5+
deftest_dir(pytestconfig):
6+
returnpytestconfig.rootdir/"tests"

‎tests/functional/api/test_users.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,17 @@
33
https://docs.gitlab.com/ee/api/users.html
44
https://docs.gitlab.com/ee/api/users.html#delete-authentication-identity-from-user
55
"""
6-
importpytest
76
importrequests
87

98

10-
@pytest.fixture(scope="session")
11-
defavatar_path(test_dir):
12-
returntest_dir/"fixtures"/"avatar.png"
13-
14-
15-
deftest_create_user(gl,avatar_path):
9+
deftest_create_user(gl,fixture_dir):
1610
user=gl.users.create(
1711
{
1812
"email":"foo@bar.com",
1913
"username":"foo",
2014
"name":"foo",
2115
"password":"foo_password",
22-
"avatar":open(avatar_path,"rb"),
16+
"avatar":open(fixture_dir/"avatar.png","rb"),
2317
}
2418
)
2519

@@ -29,7 +23,7 @@ def test_create_user(gl, avatar_path):
2923

3024
avatar_url=user.avatar_url.replace("gitlab.test","localhost:8080")
3125
uploaded_avatar=requests.get(avatar_url).content
32-
assertuploaded_avatar==open(avatar_path,"rb").read()
26+
assertuploaded_avatar==open(fixture_dir/"avatar.png","rb").read()
3327

3428

3529
deftest_block_user(gl,user):

‎tests/functional/cli/test_cli.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
importjson
2+
3+
fromgitlabimport__version__
4+
5+
6+
deftest_main_entrypoint(script_runner,gitlab_config):
7+
ret=script_runner.run("python","-m","gitlab","--config-file",gitlab_config)
8+
assertret.returncode==2
9+
10+
11+
deftest_version(script_runner):
12+
ret=script_runner.run("gitlab","--version")
13+
assertret.stdout.strip()==__version__
14+
15+
16+
deftest_invalid_config(script_runner):
17+
ret=script_runner.run("gitlab","--gitlab","invalid")
18+
assertnotret.success
19+
assertnotret.stdout
20+
21+
22+
deftest_invalid_config_prints_help(script_runner):
23+
ret=script_runner.run("gitlab","--gitlab","invalid","--help")
24+
assertret.success
25+
assertret.stdout
26+
27+
28+
deftest_invalid_api_version(script_runner,monkeypatch,fixture_dir):
29+
monkeypatch.setenv("PYTHON_GITLAB_CFG",str(fixture_dir/"invalid_version.cfg"))
30+
ret=script_runner.run("gitlab","--gitlab","test","project","list")
31+
assertnotret.success
32+
assertret.stderr.startswith("Unsupported API version:")
33+
34+
35+
deftest_invalid_auth_config(script_runner,monkeypatch,fixture_dir):
36+
monkeypatch.setenv("PYTHON_GITLAB_CFG",str(fixture_dir/"invalid_auth.cfg"))
37+
ret=script_runner.run("gitlab","--gitlab","test","project","list")
38+
assertnotret.success
39+
assert"401"inret.stderr
40+
41+
42+
deftest_fields(gitlab_cli,project_file):
43+
cmd="-o","json","--fields","default_branch","project","list"
44+
45+
ret=gitlab_cli(cmd)
46+
assertret.success
47+
48+
content=json.loads(ret.stdout.strip())
49+
assert ["default_branch"initemforitemincontent]

‎tests/functional/conftest.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
importgitlab
1010

1111

12+
@pytest.fixture(scope="session")
13+
deffixture_dir(test_dir):
14+
returntest_dir/"functional"/"fixtures"
15+
16+
1217
defreset_gitlab(gl):
1318
# previously tools/reset_gitlab.py
1419
forprojectingl.projects.list():
@@ -26,8 +31,8 @@ def reset_gitlab(gl):
2631
user.delete(hard_delete=True)
2732

2833

29-
defset_token(container,rootdir):
30-
set_token_rb=rootdir/"fixtures"/"set_token.rb"
34+
defset_token(container,fixture_dir):
35+
set_token_rb=fixture_dir/"set_token.rb"
3136

3237
withopen(set_token_rb,"r")asf:
3338
set_token_command=f.read().strip()
@@ -68,13 +73,8 @@ def temp_dir():
6873

6974

7075
@pytest.fixture(scope="session")
71-
deftest_dir(pytestconfig):
72-
returnpytestconfig.rootdir/"tests"/"functional"
73-
74-
75-
@pytest.fixture(scope="session")
76-
defdocker_compose_file(test_dir):
77-
returntest_dir/"fixtures"/"docker-compose.yml"
76+
defdocker_compose_file(fixture_dir):
77+
returnfixture_dir/"docker-compose.yml"
7878

7979

8080
@pytest.fixture(scope="session")
@@ -129,15 +129,15 @@ def _wait(timeout=30, step=0.5):
129129

130130

131131
@pytest.fixture(scope="session")
132-
defgitlab_config(check_is_alive,docker_ip,docker_services,temp_dir,test_dir):
132+
defgitlab_config(check_is_alive,docker_ip,docker_services,temp_dir,fixture_dir):
133133
config_file=temp_dir/"python-gitlab.cfg"
134134
port=docker_services.port_for("gitlab",80)
135135

136136
docker_services.wait_until_responsive(
137137
timeout=200,pause=5,check=lambda:check_is_alive("gitlab-test")
138138
)
139139

140-
token=set_token("gitlab-test",rootdir=test_dir)
140+
token=set_token("gitlab-test",fixture_dir=fixture_dir)
141141

142142
config=f"""[global]
143143
default = local
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[test]
2+
url = https://gitlab.com
3+
private_token = abc123
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[test]
2+
api_version = 3
3+
url = https://gitlab.example.com

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp