diff options
author | Nejc Habjan <hab.nejc@gmail.com> | 2021-12-12 19:19:45 +0100 |
---|---|---|
committer | Nejc Habjan <hab.nejc@gmail.com> | 2021-12-13 01:11:15 +0100 |
commit | 92a893b8e230718436582dcad96175685425b1df (patch) | |
tree | abfa0a78a5bb5429cd0a7bbe28e58e665737e511 /tests/functional | |
parent | af33affa4888fa83c31557ae99d7bbd877e9a605 (diff) | |
download | gitlab-feat/cli-without-config-file.tar.gz |
feat(cli): do not require config file to run CLIfeat/cli-without-config-file
BREAKING CHANGE: A config file is no longer needed to run
the CLI. python-gitlab will default to https://gitlab.com
with no authentication if there is no config file provided.
python-gitlab will now also only look for configuration
in the provided PYTHON_GITLAB_CFG path, instead of merging
it with user- and system-wide config files. If the
environment variable is defined and the file cannot be
opened, python-gitlab will now explicitly fail.
Diffstat (limited to 'tests/functional')
-rw-r--r-- | tests/functional/cli/test_cli.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/functional/cli/test_cli.py b/tests/functional/cli/test_cli.py index c4e76a7..2384563 100644 --- a/tests/functional/cli/test_cli.py +++ b/tests/functional/cli/test_cli.py @@ -1,8 +1,24 @@ import json +import pytest +import responses + from gitlab import __version__ +@pytest.fixture +def resp_get_project(): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url="https://gitlab.com/api/v4/projects/1", + json={"name": "name", "path": "test-path", "id": 1}, + content_type="application/json", + status=200, + ) + yield rsps + + def test_main_entrypoint(script_runner, gitlab_config): ret = script_runner.run("python", "-m", "gitlab", "--config-file", gitlab_config) assert ret.returncode == 2 @@ -13,6 +29,29 @@ def test_version(script_runner): assert ret.stdout.strip() == __version__ +@pytest.mark.script_launch_mode("inprocess") +def test_defaults_to_gitlab_com(script_runner, resp_get_project): + # Runs in-process to intercept requests to gitlab.com + ret = script_runner.run("gitlab", "project", "get", "--id", "1") + assert ret.success + assert "id: 1" in ret.stdout + + +def test_env_config_missing_file_raises(script_runner, monkeypatch): + monkeypatch.setenv("PYTHON_GITLAB_CFG", "non-existent") + ret = script_runner.run("gitlab", "project", "list") + assert not ret.success + assert ret.stderr.startswith("Cannot read config from PYTHON_GITLAB_CFG") + + +def test_arg_config_missing_file_raises(script_runner): + ret = script_runner.run( + "gitlab", "--config-file", "non-existent", "project", "list" + ) + assert not ret.success + assert ret.stderr.startswith("Cannot read config from file") + + def test_invalid_config(script_runner): ret = script_runner.run("gitlab", "--gitlab", "invalid") assert not ret.success |