Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADCM-6285 Example test on client.bundles #80

Merged
merged 1 commit into from
Jan 21, 2025
Merged
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
7 changes: 7 additions & 0 deletions tests/integration/examples/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
48 changes: 48 additions & 0 deletions tests/integration/examples/test_bundle.py
Original file line number Diff line number Diff line change
@@ -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()