diff --git a/README.rst b/README.rst index 3f7f00a30..b872317c0 100644 --- a/README.rst +++ b/README.rst @@ -141,6 +141,18 @@ Export Linode API token as `LINODE_TOKEN` before running integration tests:: export LINODE_TOKEN = $(your_token) +Integration tests use ``LINODE_URL`` for the unversioned API base URL +(default: ``https://api.linode.com``) and ``LINODE_API_VERSION`` for the API +version (default: ``v4beta``), matching linodego and the Terraform provider. +The base URL accepts an optional trailing slash. For example:: + + export LINODE_URL="https://api.linode.com" + export LINODE_API_VERSION="v4beta" + +``LINODE_API_URL`` is no longer read by the integration tests. Replace a +versioned value such as ``https://api.linode.com/v4beta`` with the two variables +above. + Running the tests ^^^^^^^^^^^^^^^^^ Run the tests locally using the make command. Run the entire test suite using command below:: 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]