From f24d7235c2fc69be9f9e83cb972b13e4aed07243 Mon Sep 17 00:00:00 2001 From: Araslanov Egor Date: Mon, 20 Jan 2025 18:11:55 +0500 Subject: [PATCH] ADCM-6285 Example test on `client.bundles` --- tests/integration/examples/conftest.py | 7 ++++ tests/integration/examples/test_bundle.py | 48 +++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/integration/examples/test_bundle.py diff --git a/tests/integration/examples/conftest.py b/tests/integration/examples/conftest.py index dd72abb..454f280 100644 --- a/tests/integration/examples/conftest.py +++ b/tests/integration/examples/conftest.py @@ -2,12 +2,19 @@ import pytest_asyncio +from adcm_aio_client._types import Credentials from adcm_aio_client.objects import Bundle from tests.integration.setup_environment import ADCMContainer TIMEOUT = 10 RETRY_INTERVAL = 1 RETRY_ATTEMPTS = 1 +DEFAULT_SESSION_KWARGS = { + "timeout": TIMEOUT, + "retry_interval": RETRY_INTERVAL, + "retry_attempts": RETRY_ATTEMPTS, + "credentials": Credentials(username="admin", password="admin"), # noqa: S106 +} @pytest_asyncio.fixture() diff --git a/tests/integration/examples/test_bundle.py b/tests/integration/examples/test_bundle.py new file mode 100644 index 0000000..c3e3d34 --- /dev/null +++ b/tests/integration/examples/test_bundle.py @@ -0,0 +1,48 @@ +from pathlib import Path + +import pytest + +from adcm_aio_client import ADCMSession +from tests.integration.bundle import pack_bundle +from tests.integration.conftest import BUNDLES +from tests.integration.examples.conftest import DEFAULT_SESSION_KWARGS +from tests.integration.setup_environment import ADCMContainer + +pytestmark = [pytest.mark.asyncio] + + +@pytest.fixture() +def packed_bundle_with_license(tmp_path: Path) -> Path: + # In regular use cases bundle already will be packed. + # Here we do it in runtime for convenience purposes. + return pack_bundle(from_dir=BUNDLES / "cluster_with_license", to=tmp_path) + + +async def test_bundle(adcm: ADCMContainer, packed_bundle_with_license: Path) -> None: + """ + Bundle (`client.bundles`) API Examples: + - upload from path + - licence acceptance + - bundle removal + - retrieval with filtering / all bundles + """ + async with ADCMSession(url=adcm.url, **DEFAULT_SESSION_KWARGS) as client: + all_bundles = await client.bundles.all() + assert len(all_bundles) == 4 + + # It's important for that `source` here is `pathlib.Path`, + # otherwise it'll be treated as URL to upload bundle from. + bundle = await client.bundles.create(source=packed_bundle_with_license, accept_license=False) + + # We could have passed `accept_license=True` instead of this. + license_ = await bundle.license + assert license_.state == "unaccepted" + await license_.accept() + + same_bundle, *_ = await client.bundles.filter(name__eq="cluster_with_license") + # Objects can be compared on equality, + # but they aren't cached in any way, so it's different instances. + assert bundle == same_bundle + assert bundle is not same_bundle + + await same_bundle.delete()