Skip to content

Commit

Permalink
ADCM-6212: Add tests for Bundle/HostProvider/Host public API
Browse files Browse the repository at this point in the history
  • Loading branch information
Starovoitov committed Dec 20, 2024
1 parent caf36c3 commit c1ed50f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
6 changes: 2 additions & 4 deletions adcm_aio_client/core/objects/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,10 @@ class ClustersNode(PaginatedAccessor[Cluster]):
filtering = Filtering(FilterByName, FilterByBundle, FilterByStatus)

async def create(self: Self, bundle: Bundle, name: str, description: str = "") -> Cluster:
bundle_data = await self._requester.get("bundles", bundle.id)
response = await self._requester.post(
"clusters",
data={
"prototypeId": bundle_data.as_dict()["mainPrototype"]["id"],
"prototypeId": bundle._main_prototype_id,
"name": name,
"description": description,
},
Expand Down Expand Up @@ -380,11 +379,10 @@ class HostProvidersNode(PaginatedAccessor[HostProvider]):
filtering = Filtering(FilterByName, FilterByBundle)

async def create(self: Self, bundle: Bundle, name: str, description: str = "") -> HostProvider:
bundle_data = await self._requester.get("bundles", bundle.id)
response = await self._requester.post(
"hostproviders",
data={
"prototypeId": bundle_data.as_dict()["mainPrototype"]["id"],
"prototypeId": bundle._main_prototype_id,
"name": name,
"description": description,
},
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ python = "^3.12"
httpx = "^0.27.2"
asyncstdlib = "^3.13.0"
adcm-version = "^1.0.3"
pyyaml = "^6.0.2"

[tool.poetry.group.dev]
optional = true
Expand All @@ -27,6 +26,7 @@ optional = true
pytest = "^8.3.3"
pytest-asyncio = "^0.24.0"
testcontainers = "^4.8.2"
pyyaml = "^6.0.2"

[build-system]
requires = ["poetry-core"]
Expand Down
24 changes: 13 additions & 11 deletions tests/integration/test_bundle.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from pathlib import Path
from unittest.mock import AsyncMock, patch
from unittest.mock import AsyncMock
import os

import httpx
import pytest
import pytest_asyncio

from adcm_aio_client.core.client import ADCMClient
from adcm_aio_client.core.errors import ObjectDoesNotExistError
from adcm_aio_client.core.objects.cm import Bundle
from adcm_aio_client.core.requesters import BundleRetrieverInterface, DefaultRequester
from adcm_aio_client.core.types import UrlPath
from tests.integration.bundle import create_bundles_by_template, pack_bundle
from tests.integration.conftest import BUNDLES
Expand Down Expand Up @@ -47,7 +47,7 @@ async def _test_bundle_create_delete(adcm_client: ADCMClient, tmp_path: Path) ->

assert bundle.license.state == "accepted"

await _test_download_external_bundle_success(adcm_client)
await _test_download_external_bundle_success()


async def _test_bundle_accessors(adcm_client: ADCMClient) -> None:
Expand Down Expand Up @@ -95,16 +95,18 @@ async def _test_bundle_properties(adcm_client: ADCMClient) -> None:
assert bundle.license.state == "accepted"


async def _test_download_external_bundle_success(adcm_client: ADCMClient) -> None:
url = UrlPath("https://correctaddress.com")
async def _test_download_external_bundle_success() -> None:
mock_requester = AsyncMock(spec=DefaultRequester)
mock_retriever = AsyncMock(spec=BundleRetrieverInterface)
url = UrlPath("http://example.com/bundle.tar.gz")

with patch("httpx.AsyncClient.get", new_callable=AsyncMock) as mock_get:
mock_response = AsyncMock()
mock_response.ahref = httpx.Response(status_code=200, content=b"bundle content")
mock_get.return_value = mock_response
await adcm_client.bundles.create(source=url, accept_license=False)
mock_retriever.download_external_bundle = AsyncMock(return_value=b"bundle content")

mock_get.assert_called_once_with(str(url))
adcm_client = ADCMClient(requester=mock_requester, bundle_retriever=mock_retriever, adcm_version="1.0")

await adcm_client.bundles.create(source=url, accept_license=False)

mock_retriever.download_external_bundle.assert_awaited_once_with(url)


async def _test_pagination(adcm_client: ADCMClient, tmp_path: Path) -> None:
Expand Down

0 comments on commit c1ed50f

Please sign in to comment.