summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorNejc Habjan <hab.nejc@gmail.com>2021-02-12 00:47:32 +0100
committerJohn Villalovos <john@sodarock.com>2022-01-02 14:35:39 -0800
commitca58008607385338aaedd14a58adc347fa1a41a0 (patch)
tree3597e79d38ad47a0841c5a773950897863a87490 /tests/unit
parente19e4d7cdf9cd04359cd3e95036675c81f4e1dc5 (diff)
downloadgitlab-ca58008607385338aaedd14a58adc347fa1a41a0.tar.gz
feat(cli): allow options from args and environment variables
BREAKING-CHANGE: The gitlab CLI will now accept CLI arguments and environment variables for its global options in addition to configuration file options. This may change behavior for some workflows such as running inside GitLab CI and with certain environment variables configured.
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/test_config.py2
-rw-r--r--tests/unit/test_gitlab_auth.py114
2 files changed, 115 insertions, 1 deletions
diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py
index 6874e94..7ba312b 100644
--- a/tests/unit/test_config.py
+++ b/tests/unit/test_config.py
@@ -150,7 +150,7 @@ def test_default_config(mock_clean_env, monkeypatch):
assert cp.retry_transient_errors is False
assert cp.ssl_verify is True
assert cp.timeout == 60
- assert cp.url == const.DEFAULT_URL
+ assert cp.url is None
assert cp.user_agent == const.USER_AGENT
diff --git a/tests/unit/test_gitlab_auth.py b/tests/unit/test_gitlab_auth.py
index 314fbed..8d6677f 100644
--- a/tests/unit/test_gitlab_auth.py
+++ b/tests/unit/test_gitlab_auth.py
@@ -2,6 +2,7 @@ import pytest
import requests
from gitlab import Gitlab
+from gitlab.config import GitlabConfigParser
def test_invalid_auth_args():
@@ -83,3 +84,116 @@ def test_http_auth():
assert isinstance(gl._http_auth, requests.auth.HTTPBasicAuth)
assert gl.headers["PRIVATE-TOKEN"] == "private_token"
assert "Authorization" not in gl.headers
+
+
+@pytest.mark.parametrize(
+ "options,config,expected_private_token,expected_oauth_token,expected_job_token",
+ [
+ (
+ {
+ "private_token": "options-private-token",
+ "oauth_token": "options-oauth-token",
+ "job_token": "options-job-token",
+ },
+ {
+ "private_token": "config-private-token",
+ "oauth_token": "config-oauth-token",
+ "job_token": "config-job-token",
+ },
+ "options-private-token",
+ None,
+ None,
+ ),
+ (
+ {
+ "private_token": None,
+ "oauth_token": "options-oauth-token",
+ "job_token": "options-job-token",
+ },
+ {
+ "private_token": "config-private-token",
+ "oauth_token": "config-oauth-token",
+ "job_token": "config-job-token",
+ },
+ "config-private-token",
+ None,
+ None,
+ ),
+ (
+ {
+ "private_token": None,
+ "oauth_token": None,
+ "job_token": "options-job-token",
+ },
+ {
+ "private_token": "config-private-token",
+ "oauth_token": "config-oauth-token",
+ "job_token": "config-job-token",
+ },
+ "config-private-token",
+ None,
+ None,
+ ),
+ (
+ {
+ "private_token": None,
+ "oauth_token": None,
+ "job_token": None,
+ },
+ {
+ "private_token": "config-private-token",
+ "oauth_token": "config-oauth-token",
+ "job_token": "config-job-token",
+ },
+ "config-private-token",
+ None,
+ None,
+ ),
+ (
+ {
+ "private_token": None,
+ "oauth_token": None,
+ "job_token": None,
+ },
+ {
+ "private_token": None,
+ "oauth_token": "config-oauth-token",
+ "job_token": "config-job-token",
+ },
+ None,
+ "config-oauth-token",
+ None,
+ ),
+ (
+ {
+ "private_token": None,
+ "oauth_token": None,
+ "job_token": None,
+ },
+ {
+ "private_token": None,
+ "oauth_token": None,
+ "job_token": "config-job-token",
+ },
+ None,
+ None,
+ "config-job-token",
+ ),
+ ],
+)
+def test_merge_auth(
+ options,
+ config,
+ expected_private_token,
+ expected_oauth_token,
+ expected_job_token,
+):
+ cp = GitlabConfigParser()
+ cp.private_token = config["private_token"]
+ cp.oauth_token = config["oauth_token"]
+ cp.job_token = config["job_token"]
+
+ private_token, oauth_token, job_token = Gitlab._merge_auth(options, cp)
+ assert private_token == expected_private_token
+ assert oauth_token == expected_oauth_token
+ assert job_token == expected_job_token