Skip to content

Commit

Permalink
my own pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vilit1 committed Oct 10, 2024
1 parent bab0896 commit 54ab2bf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
28 changes: 22 additions & 6 deletions azext_edge/edge/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,15 +1189,23 @@ def load_iotops_help():
https://github.com/delta-io/delta/blob/master/PROTOCOL.md#column-mapping and
https://learn.microsoft.com/en-us/fabric/data-engineering/lakehouse-and-delta-tables. (#TODO AKA.ms)
examples:
- name: Create a schema called 'myschema' in the registry 'myregistry' with minimum inputs. Schema version 1 will be created for this schema.
- name: Create a schema called 'myschema' in the registry 'myregistry' with minimum inputs. Schema version 1 will be created for this schema with the file content.
text: >
az iot ops schema create -n myschema -g myresourcegroup --registry myregistry
--format json --type message --version-content '{\"hello\": 3}'
- name: Create a schema called 'myschema' with additional customization. Schema version 14 will be created for this schema.
--format json --type message --version-content myschema.json
- name: Create a schema called 'myschema' with additional customization. Schema version 14 will be created for this schema. The inline content is a powershell syntax example.
text: >
az iot ops schema create -n myschema -g myresourcegroup --registry myregistry
--format delta --type message --desc "Schema for Assets" --display-name myassetschema
--version-content '{\"hello\": 3}' --ver 14 --vd "14th version"
--version-content '{\\\"hello\\\": \\\"world\\\"}' --ver 14 --vd "14th version"
- name: Create a schema called 'myschema'. Schema version 1 will be created for this schema. The inline content is a cmd syntax example.
text: >
az iot ops schema create -n myschema -g myresourcegroup --registry myregistry
--format json --type message --version-content "{\\\"hello\\\": \\\"world\\\"}"
- name: Create a schema called 'myschema'. Schema version 1 will be created for this schema. The inline content is a bash syntax example.
text: >
az iot ops schema create -n myschema -g myresourcegroup --registry myregistry
--format json --type message --version-content '{"hello": "world"}'
"""

helps[
Expand Down Expand Up @@ -1328,9 +1336,17 @@ def load_iotops_help():
https://learn.microsoft.com/en-us/fabric/data-engineering/lakehouse-and-delta-tables. (#TODO AKA.ms)
examples:
- name: Add a schema version 1 to a schema called 'myschema' within the registry 'myregistry' with
minimum inputs. The content is inline json.
minimum inputs. The content is inline json (powershell syntax example).
text: >
az iot ops schema version add -n 1 -g myresourcegroup --registry myregistry --schema myschema --content '{\\\"hello\\\": \\\"world\\\"}'
- name: Add a schema version 1 to a schema called 'myschema' within the registry 'myregistry' with
minimum inputs. The content is inline json (cmd syntax example).
text: >
az iot ops schema version add -n 1 -g myresourcegroup --registry myregistry --schema myschema --content "{\\\"hello\\\": \\\"world\\\"}"
- name: Add a schema version 1 to a schema called 'myschema' within the registry 'myregistry' with
minimum inputs. The content is inline json (bash syntax example).
text: >
az iot ops schema version add -n 1 -g myresourcegroup --registry myregistry --schema myschema --content '{\"hello\": 3}'
az iot ops schema version add -n 1 -g myresourcegroup --registry myregistry --schema myschema --content '{"hello": "world"}'
- name: Add a schema version 2 to a schema called 'myschema' within the registry 'myregistry' with
a description. The file should contain the schema content.
text: >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from typing import TYPE_CHECKING, Iterable, Optional

from azure.cli.core.azclierror import ValidationError, FileOperationError, ForbiddenError
from azure.cli.core.azclierror import ValidationError, FileOperationError, ForbiddenError, InvalidArgumentValueError
from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
from knack.log import get_logger
from rich.console import Console
Expand Down Expand Up @@ -248,17 +248,19 @@ def delete(

def add_version(
self,
name: str,
name: int,
schema_name: str,
schema_registry_name: str,
resource_group_name: str,
schema_content: str,
description: Optional[str] = None,
current_console: Optional[Console] = None,
) -> dict:
# TODO: have the schema_content support files too
from ....util import read_file_content

if name < 0:
raise InvalidArgumentValueError("Version must be a positive number")

try:
logger.debug("Processing schema content.")
schema_content = read_file_content(schema_content)
Expand Down
13 changes: 13 additions & 0 deletions azext_edge/tests/edge/orchestration/resources/test_schema_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,16 @@ def test_version_add(mocked_cmd, mocked_responses: responses, description: Optio

assert create_payload["properties"]["schemaContent"] == schema_content
assert create_payload["properties"]["description"] == description


def test_version_add_error(mocked_cmd):
from azure.cli.core.azclierror import InvalidArgumentValueError
with pytest.raises(InvalidArgumentValueError):
add_version(
cmd=mocked_cmd,
version_name=-1,
schema_name=generate_random_string(),
schema_registry_name=generate_random_string(),
schema_content=generate_random_string(),
resource_group_name=generate_random_string()
)

0 comments on commit 54ab2bf

Please sign in to comment.