mirror of
https://github.com/datahub-project/datahub.git
synced 2025-07-09 02:02:12 +00:00

Deprecates get_url_and_token() in favor of a more complete option: load_graph_config() that returns a full DatahubClientConfig. This change was then propagated across previous usages of get_url_and_token so that connections to DataHub server from the client respect the full breadth of configuration specified by DatahubClientConfig. I.e: You can now specify disable_ssl_verification: true in your ~/.datahubenv file so that all cli functions to the server work when ssl certification is disabled. Fixes #9705
84 lines
2.5 KiB
Python
84 lines
2.5 KiB
Python
import os
|
|
from unittest import mock
|
|
|
|
from datahub.cli import cli_utils
|
|
from datahub.ingestion.graph.client import get_details_from_env
|
|
|
|
|
|
def test_first_non_null():
|
|
assert cli_utils.first_non_null([]) is None
|
|
assert cli_utils.first_non_null([None]) is None
|
|
assert cli_utils.first_non_null([None, "1"]) == "1"
|
|
assert cli_utils.first_non_null([None, "1", "2"]) == "1"
|
|
assert cli_utils.first_non_null(["3", "1", "2"]) == "3"
|
|
assert cli_utils.first_non_null(["", "1", "2"]) == "1"
|
|
assert cli_utils.first_non_null([" ", "1", "2"]) == "1"
|
|
|
|
|
|
@mock.patch.dict(os.environ, {"DATAHUB_GMS_HOST": "http://localhost:9092"})
|
|
def test_correct_url_when_gms_host_in_old_format():
|
|
assert get_details_from_env() == ("http://localhost:9092", None)
|
|
|
|
|
|
@mock.patch.dict(
|
|
os.environ, {"DATAHUB_GMS_HOST": "localhost", "DATAHUB_GMS_PORT": "8080"}
|
|
)
|
|
def test_correct_url_when_gms_host_and_port_set():
|
|
assert get_details_from_env() == ("http://localhost:8080", None)
|
|
|
|
|
|
@mock.patch.dict(
|
|
os.environ,
|
|
{
|
|
"DATAHUB_GMS_URL": "https://example.com",
|
|
"DATAHUB_GMS_HOST": "localhost",
|
|
"DATAHUB_GMS_PORT": "8080",
|
|
},
|
|
)
|
|
def test_correct_url_when_gms_host_port_url_set():
|
|
assert get_details_from_env() == ("http://localhost:8080", None)
|
|
|
|
|
|
@mock.patch.dict(
|
|
os.environ,
|
|
{
|
|
"DATAHUB_GMS_URL": "https://example.com",
|
|
"DATAHUB_GMS_HOST": "localhost",
|
|
"DATAHUB_GMS_PORT": "8080",
|
|
"DATAHUB_GMS_PROTOCOL": "https",
|
|
},
|
|
)
|
|
def test_correct_url_when_gms_host_port_url_protocol_set():
|
|
assert get_details_from_env() == ("https://localhost:8080", None)
|
|
|
|
|
|
@mock.patch.dict(
|
|
os.environ,
|
|
{
|
|
"DATAHUB_GMS_URL": "https://example.com",
|
|
},
|
|
)
|
|
def test_correct_url_when_url_set():
|
|
assert get_details_from_env() == ("https://example.com", None)
|
|
|
|
|
|
def test_fixup_gms_url():
|
|
assert cli_utils.fixup_gms_url("http://localhost:8080") == "http://localhost:8080"
|
|
assert cli_utils.fixup_gms_url("http://localhost:8080/") == "http://localhost:8080"
|
|
assert cli_utils.fixup_gms_url("http://abc.acryl.io") == "https://abc.acryl.io/gms"
|
|
|
|
|
|
def test_guess_frontend_url_from_gms_url():
|
|
assert (
|
|
cli_utils.guess_frontend_url_from_gms_url("http://localhost:8080")
|
|
== "http://localhost:9002"
|
|
)
|
|
assert (
|
|
cli_utils.guess_frontend_url_from_gms_url("http://localhost:8080/")
|
|
== "http://localhost:9002"
|
|
)
|
|
assert (
|
|
cli_utils.guess_frontend_url_from_gms_url("https://abc.acryl.io/gms")
|
|
== "https://abc.acryl.io"
|
|
)
|