Skip to content

Commit

Permalink
ADCM-6125 Use prepared responses for test_config
Browse files Browse the repository at this point in the history
  • Loading branch information
Sealwing committed Nov 21, 2024
1 parent 764dc16 commit 58521c3
Show file tree
Hide file tree
Showing 7 changed files with 444 additions and 46 deletions.
6 changes: 3 additions & 3 deletions adcm_aio_client/core/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def set(self: Self, value: InnerType) -> Self:
class _ParametersGroup:
def __init__(self: Self, spec: dict, callbacks: Callbacks, previous_levels: LevelNames = ()) -> None:
# for now we assume it's always there
self._spec = spec["parameters"]
self._spec = spec["properties"]
self._previous_levels = previous_levels
self._callbacks = callbacks
self._names_mapping: dict[ParameterDisplayName, ParameterName] = {}
Expand Down Expand Up @@ -165,7 +165,7 @@ def _initialize_wrapper(self: Self, name: ParameterName) -> "ParameterWrapper":
level_data = value
previous_levels = (*self._previous_levels, name)

is_activatable = spec["adcmMeta"].get("activation", {}).get("isAllowChange")
is_activatable = (spec["adcmMeta"].get("activation") or {}).get("isAllowChange")
if is_activatable:
return ActivatableGroupWrapper(
config_level_data=level_data, spec=spec, callbacks=self._callbacks, previous_levels=previous_levels
Expand Down Expand Up @@ -282,7 +282,7 @@ def _convert_payload_formated_json_fields_inplace(
self._json_fields.add(level_names)
elif isinstance(value, dict) and self._parameter_is_group(parameter_spec):
self._convert_payload_formated_json_fields_inplace(
parameters_spec=parameters_spec[key]["parameters"], data=value, prefix=level_names
parameters_spec=parameters_spec[key]["properties"], data=value, prefix=level_names
)

def _convert_json_fields_to_payload_format_inplace(self: Self, data: dict) -> None:
Expand Down
70 changes: 70 additions & 0 deletions tests/bundles/config_example_v1/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
- type: cluster
name: Cluster With Config Example
version: 1
description: |
This bundle is designed to provide sample of config,
not nessesary including all config types or combinations.
Don't change configs of existing objects in it,
add new service / component if you need.
- type: service
name: with_json_fields_and_groups
version: 1.0

config:
- name: root_int
display_name: Integer At Root
type: integer
default: 100
- name: root_list
display_name: List At Root
type: list
default: ["first", "second", "third"]
- name: root_dict
display_name: Map At Root
type: map
default: {"k1": "v1", "k2": "v2"}
required: false
- name: duplicate
display_name: Duplicate
type: string
default: "hehe"
- name: root_json
display_name: JSON At Root
type: json
default: {}
- name: main
display_name: Main Section
type: group
subs:
- name: inner_str
display_name: String In Group
type: string
default: "evil"
- name: inner_dict
display_name: Map In Group
type: map
default: {"a": "b"}
- name: inner_json
display_name: JSON In Group
type: json
default: {"complex": [], "jsonfield": 23, "server": "bestever"}
- name: duplicate
display_name: Integer In Group
type: integer
default: 44
- name: optional_group
display_name: Optional Section
type: group
activatable: true
active: false
subs:
- name: param
display_name: Param In Activatable Group
type: float
default: 44.44
required: false
- name: root_str
display_name: String At Root
type: string
required: false
3 changes: 3 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import pytest
from pathlib import Path

from tests.unit.mocks.requesters import QueueRequester

FILES = Path(__file__).parent / "files"
RESPONSES = FILES / "responses"

@pytest.fixture()
def queue_requester() -> QueueRequester:
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/files/responses/.description
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This directory have samples of responses from ADCM
to use them as mock responses in unit tests.
37 changes: 37 additions & 0 deletions tests/unit/files/responses/test_config_example_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"id": 3,
"isCurrent": true,
"creationTime": "2024-11-21T06:38:58.517310Z",
"config": {
"main": {
"duplicate": 44,
"inner_str": "evil",
"inner_dict": {
"a": "b"
},
"inner_json": "{\"server\": \"bestever\", \"complex\": [], \"jsonfield\": 23}"
},
"root_int": 100,
"root_str": null,
"duplicate": "hehe",
"root_dict": {
"k1": "v1",
"k2": "v2"
},
"root_json": "{}",
"root_list": [
"first",
"second",
"third"
],
"optional_group": {
"param": 44.44
}
},
"adcmMeta": {
"/optional_group": {
"isActive": false
}
},
"description": "init"
}
Loading

0 comments on commit 58521c3

Please sign in to comment.