Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
7 changes: 5 additions & 2 deletions test/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(
Expand Down
56 changes: 55 additions & 1 deletion test/integration/linode_client/test_linode_client.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand Down
Loading