diff --git a/test/integration/conftest.py b/test/integration/conftest.py index 394eb0284..9c845f117 100644 --- a/test/integration/conftest.py +++ b/test/integration/conftest.py @@ -36,7 +36,8 @@ from linode_api4.objects import Capability, Region ENV_TOKEN_NAME = "LINODE_TOKEN" -ENV_API_URL_NAME = "LINODE_API_URL" +ENV_API_URL_NAME = "LINODE_URL" +ENV_API_VERSION_NAME = "LINODE_API_VERSION" ENV_REGION_OVERRIDE = "LINODE_TEST_REGION_OVERRIDE" ENV_API_CA_NAME = "LINODE_API_CA" RUN_LONG_TESTS = "RUN_LONG_TESTS" @@ -57,7 +58,9 @@ def get_token(): def get_api_url(): - return os.environ.get(ENV_API_URL_NAME, "https://api.linode.com/v4beta") + api_url = os.environ.get(ENV_API_URL_NAME, "https://api.linode.com") + api_version = os.environ.get(ENV_API_VERSION_NAME, "v4beta") + return f"{api_url.rstrip('/')}/{api_version}" def get_regions( diff --git a/test/integration/linode_client/test_linode_client.py b/test/integration/linode_client/test_linode_client.py index b4fe95787..b5eed4771 100644 --- a/test/integration/linode_client/test_linode_client.py +++ b/test/integration/linode_client/test_linode_client.py @@ -1,6 +1,6 @@ import re import time -from test.integration.conftest import get_region +from test.integration.conftest import get_api_url, get_region from test.integration.helpers import get_test_label, wait_for_condition import pytest @@ -14,6 +14,60 @@ ) +@pytest.mark.parametrize( + "environment, expected_url", + [ + ({}, "https://api.linode.com/v4beta"), + ( + {"LINODE_URL": "https://api.example.test"}, + "https://api.example.test/v4beta", + ), + ( + {"LINODE_URL": "https://api.example.test/"}, + "https://api.example.test/v4beta", + ), + ( + {"LINODE_API_VERSION": "v4"}, + "https://api.linode.com/v4", + ), + ( + { + "LINODE_URL": "https://api.example.test/", + "LINODE_API_VERSION": "v4", + }, + "https://api.example.test/v4", + ), + ( + { + "LINODE_URL": "http://localhost:8080/proxy///", + "LINODE_API_VERSION": "v4beta", + }, + "http://localhost:8080/proxy/v4beta", + ), + ( + {"LINODE_API_URL": "https://legacy.example.test/v4"}, + "https://api.linode.com/v4beta", + ), + ( + { + "LINODE_API_URL": "https://legacy.example.test/v4", + "LINODE_URL": "https://api.example.test", + "LINODE_API_VERSION": "v4", + }, + "https://api.example.test/v4", + ), + ], +) +def test_api_url_environment(monkeypatch, environment, expected_url): + for name in ("LINODE_URL", "LINODE_API_VERSION", "LINODE_API_URL"): + monkeypatch.delenv(name, raising=False) + + for name, value in environment.items(): + monkeypatch.setenv(name, value) + + assert get_api_url() == expected_url + + def is_tag_created(client, tag_label): tags = client.tags() tag_label_list = [i.label for i in tags]