]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/tests/test_crud.py
1 # pylint: disable=C0102
4 from typing
import NamedTuple
7 from jsonschema
import validate
9 from ..controllers
._crud
import ArrayHorizontalContainer
, \
10 ArrayVerticalContainer
, Form
, FormField
, HorizontalContainer
, SecretStr
, \
11 VerticalContainer
, serialize
14 def assertObjectEquals(a
, b
):
15 assert json
.dumps(a
) == json
.dumps(b
)
18 class NamedTupleMock(NamedTuple
):
23 class NamedTupleSecretMock(NamedTuple
):
29 @pytest.mark
.parametrize("inp,out", [
30 (["foo", "var"], ["foo", "var"]),
31 (NamedTupleMock(1, "test"), {"foo": 1, "var": "test"}),
32 (NamedTupleSecretMock(1, "test", "imaginethisisakey"), {"foo": 1, "var": "test",
33 "key": "***********"}),
34 ((1, 2, 3), [1, 2, 3]),
35 (set((1, 2, 3)), [1, 2, 3]),
37 def test_serialize(inp
, out
):
38 assertObjectEquals(serialize(inp
), out
)
42 form
= Form(path
='/cluster/user/create',
43 root_container
=VerticalContainer('Create user', key
='create_user', fields
=[
44 FormField('User entity', key
='user_entity', field_type
=str),
45 ArrayHorizontalContainer('Capabilities', key
='caps', fields
=[
46 FormField('left', field_type
=str, key
='left'),
47 FormField('right', key
='right', field_type
=str)
49 ArrayVerticalContainer('ah', key
='ah', fields
=[
50 FormField('top', key
='top', field_type
=str),
51 FormField('bottom', key
='bottom', field_type
=str)
53 HorizontalContainer('oh', key
='oh', fields
=[
54 FormField('left', key
='left', field_type
=str),
55 FormField('right', key
='right', field_type
=str)
57 VerticalContainer('ov', key
='ov', fields
=[
58 FormField('top', key
='top', field_type
=str),
59 FormField('bottom', key
='bottom', field_type
=bool)
62 form_dict
= form
.to_dict()
63 schema
= {'schema': form_dict
['control_schema'], 'layout': form_dict
['ui_schema']}
64 validate(instance
={'user_entity': 'foo',
65 'caps': [{'left': 'foo', 'right': 'foo2'}],
66 'ah': [{'top': 'foo', 'bottom': 'foo2'}],
67 'oh': {'left': 'foo', 'right': 'foo2'},
68 'ov': {'top': 'foo', 'bottom': True}}, schema
=schema
['schema'])