Skip to content

Commit 60686a9

Browse files
committed
feat(http-api): add device profile download support
1 parent 65e872e commit 60686a9

5 files changed

Lines changed: 85 additions & 1 deletion

File tree

src/enapter/cli/http/api/blueprint_command.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from .blueprint_download_command import BlueprintDownloadCommand
66
from .blueprint_get_command import BlueprintGetCommand
7+
from .blueprint_profiles_command import BlueprintProfilesCommand
78
from .blueprint_upload_command import BlueprintUploadCommand
89
from .blueprint_validate_command import BlueprintValidateCommand
910

@@ -19,6 +20,7 @@ def register(parent: cli.Subparsers) -> None:
1920
for command in [
2021
BlueprintDownloadCommand,
2122
BlueprintGetCommand,
23+
BlueprintProfilesCommand,
2224
BlueprintUploadCommand,
2325
BlueprintValidateCommand,
2426
]:
@@ -31,9 +33,11 @@ async def run(args: argparse.Namespace) -> None:
3133
await BlueprintDownloadCommand.run(args)
3234
case "get":
3335
await BlueprintGetCommand.run(args)
36+
case "profiles":
37+
await BlueprintProfilesCommand.run(args)
3438
case "upload":
3539
await BlueprintUploadCommand.run(args)
3640
case "validate":
3741
await BlueprintValidateCommand.run(args)
3842
case _:
39-
raise NotImplementedError(args.command_command)
43+
raise NotImplementedError(args.blueprint_command)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import argparse
2+
3+
from enapter import cli
4+
5+
from .blueprint_profiles_download_command import BlueprintProfilesDownloadCommand
6+
7+
8+
class BlueprintProfilesCommand(cli.Command):
9+
10+
@staticmethod
11+
def register(parent: cli.Subparsers) -> None:
12+
parser = parent.add_parser(
13+
"profiles", formatter_class=argparse.ArgumentDefaultsHelpFormatter
14+
)
15+
subparsers = parser.add_subparsers(
16+
dest="blueprint_profiles_command", required=True
17+
)
18+
for command in [
19+
BlueprintProfilesDownloadCommand,
20+
]:
21+
command.register(subparsers)
22+
23+
@staticmethod
24+
async def run(args: argparse.Namespace) -> None:
25+
match args.blueprint_profiles_command:
26+
case "download":
27+
await BlueprintProfilesDownloadCommand.run(args)
28+
case _:
29+
raise NotImplementedError(args.blueprint_profiles_command)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import argparse
2+
import logging
3+
import pathlib
4+
5+
from enapter import cli, http
6+
7+
LOGGER = logging.getLogger(__name__)
8+
9+
10+
class BlueprintProfilesDownloadCommand(cli.Command):
11+
12+
@staticmethod
13+
def register(parent: cli.Subparsers) -> None:
14+
parser = parent.add_parser(
15+
"download", formatter_class=argparse.ArgumentDefaultsHelpFormatter
16+
)
17+
parser.add_argument(
18+
"-o",
19+
"--output",
20+
type=pathlib.Path,
21+
help="Output directory path",
22+
default=pathlib.Path.cwd(),
23+
)
24+
25+
@staticmethod
26+
async def run(args: argparse.Namespace) -> None:
27+
async with http.api.Client(http.api.Config.from_env()) as client:
28+
content = await client.blueprints.download_device_profiles()
29+
output_path = args.output / "device_profiles.zip"
30+
with output_path.open("wb") as f:
31+
f.write(content)

src/enapter/http/api/blueprints/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ async def download(
4343
await api.check_error(response)
4444
return response.content
4545

46+
async def download_device_profiles(self) -> bytes:
47+
url = "v3/blueprints/device_profiles/download"
48+
response = await self._client.get(url)
49+
await api.check_error(response)
50+
return response.content
51+
4652
async def validate_file(self, path: pathlib.Path) -> None:
4753
with path.open("rb") as file:
4854
data = file.read()

tests/unit/test_http/test_api/test_blueprints/test_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ async def test_download_blueprint_compiled(blueprints_client, mock_client):
149149
)
150150

151151

152+
@pytest.mark.asyncio
153+
async def test_download_device_profiles(blueprints_client, mock_client):
154+
"""Test downloading device profiles."""
155+
mock_response = MagicMock(spec=httpx.Response)
156+
mock_response.status_code = 200
157+
mock_response.content = b"device profiles zip content"
158+
mock_client.get = AsyncMock(return_value=mock_response)
159+
160+
content = await blueprints_client.download_device_profiles()
161+
162+
assert content == b"device profiles zip content"
163+
mock_client.get.assert_called_once_with("v3/blueprints/device_profiles/download")
164+
165+
152166
@pytest.mark.asyncio
153167
async def test_validate_blueprint(blueprints_client, mock_client):
154168
"""Test validating a blueprint from bytes."""

0 commit comments

Comments
 (0)