-
Notifications
You must be signed in to change notification settings - Fork 670
test(cli): improve basic CLI coverage #1721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
-r requirements.txt | ||
-r requirements-test.txt | ||
docker-compose==1.29.2 # prevent inconsistent .env behavior from system install | ||
pytest-console-scripts | ||
pytest-docker |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
coverage | ||
httmock | ||
mock | ||
pytest | ||
pytest-console-scripts==1.2.1 | ||
pytest-cov | ||
responses |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def test_dir(pytestconfig): | ||
return pytestconfig.rootdir / "tests" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import json | ||
|
||
from gitlab import __version__ | ||
|
||
|
||
def test_main_entrypoint(script_runner, gitlab_config): | ||
ret = script_runner.run("python", "-m", "gitlab", "--config-file", gitlab_config) | ||
assert ret.returncode == 2 | ||
|
||
|
||
def test_version(script_runner): | ||
ret = script_runner.run("gitlab", "--version") | ||
assert ret.stdout.strip() == __version__ | ||
|
||
|
||
def test_invalid_config(script_runner): | ||
ret = script_runner.run("gitlab", "--gitlab", "invalid") | ||
assert not ret.success | ||
assert not ret.stdout | ||
|
||
|
||
def test_invalid_config_prints_help(script_runner): | ||
ret = script_runner.run("gitlab", "--gitlab", "invalid", "--help") | ||
assert ret.success | ||
assert ret.stdout | ||
|
||
|
||
def test_invalid_api_version(script_runner, monkeypatch, fixture_dir): | ||
monkeypatch.setenv("PYTHON_GITLAB_CFG", str(fixture_dir / "invalid_version.cfg")) | ||
ret = script_runner.run("gitlab", "--gitlab", "test", "project", "list") | ||
assert not ret.success | ||
assert ret.stderr.startswith("Unsupported API version:") | ||
|
||
|
||
def test_invalid_auth_config(script_runner, monkeypatch, fixture_dir): | ||
monkeypatch.setenv("PYTHON_GITLAB_CFG", str(fixture_dir / "invalid_auth.cfg")) | ||
ret = script_runner.run("gitlab", "--gitlab", "test", "project", "list") | ||
assert not ret.success | ||
assert "401" in ret.stderr | ||
|
||
|
||
def test_fields(gitlab_cli, project_file): | ||
cmd = "-o", "json", "--fields", "default_branch", "project", "list" | ||
|
||
ret = gitlab_cli(cmd) | ||
assert ret.success | ||
|
||
content = json.loads(ret.stdout.strip()) | ||
assert ["default_branch" in item for item in content] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[test] | ||
url = https://gitlab.com | ||
private_token = abc123 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[test] | ||
api_version = 3 | ||
url = https://gitlab.example.com |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.