diff --git a/tests/contrib/django/dispatcher/test_dispatchers.py b/tests/contrib/django/dispatcher/test_dispatchers.py index 2de3188..90dc994 100644 --- a/tests/contrib/django/dispatcher/test_dispatchers.py +++ b/tests/contrib/django/dispatcher/test_dispatchers.py @@ -119,7 +119,7 @@ def test_basic_resource_api_dispatcher__dispatch__json_load_fail(): assert resp["code"] == 400 assert resp["result"] is False assert resp["data"] is None - assert resp["message"] == "reqeust body is not a valid json" + assert resp["message"] == "request body is not a valid json" assert "X-Request-Id" in resp @@ -369,7 +369,13 @@ def fetch_resource_type_schema(self, **options): { "method": "list_instance", "type": "spy", - "filter": {"parent": "parent", "search": "search", "resource_type_chain": "resource_type_chain"}, + "filter": { + "parent": "parent", + "search": "search", + "ancestors": "ancestors", + "action": "action", + "resource_type_chain": "resource_type_chain" + }, "page": {"limit": "limit", "offset": "offset"}, } ) @@ -378,7 +384,13 @@ def fetch_resource_type_schema(self, **options): resp = dispatcher._dispatch(list_instance_req) provider.pre_list_instance.assert_called_once_with( - {"parent": "parent", "search": "search", "resource_type_chain": "resource_type_chain"}, + { + "parent": "parent", + "search": "search", + "ancestors": "ancestors", + "resource_type_chain": "resource_type_chain", + "action": "action", + }, {"limit": "limit", "offset": "offset"}, language="en", ) @@ -389,7 +401,13 @@ def fetch_resource_type_schema(self, **options): assert "message" in resp assert provider.list_instance_spy == { "options": {"language": "en"}, - "filter": {"parent": "parent", "search": "search", "resource_type_chain": "resource_type_chain"}, + "filter": { + "parent": "parent", + "search": "search", + "ancestors": "ancestors", + "resource_type_chain": "resource_type_chain", + "action": "action" + }, "page": {"limit": "limit", "offset": "offset"}, } @@ -399,7 +417,7 @@ def fetch_resource_type_schema(self, **options): { "method": "search_instance", "type": "spy", - "filter": {"parent": "parent", "keyword": "keyword"}, + "filter": {"parent": "parent", "keyword": "keyword", "action": "action", "ancestors": "ancestors"}, "page": {"limit": "limit", "offset": "offset"}, } ) @@ -408,7 +426,7 @@ def fetch_resource_type_schema(self, **options): resp = dispatcher._dispatch(search_instance_req) provider.pre_search_instance.assert_called_once_with( - {"parent": "parent", "keyword": "keyword"}, + {"parent": "parent", "keyword": "keyword", "action": "action", "ancestors": "ancestors"}, {"limit": "limit", "offset": "offset"}, language="en", ) @@ -419,7 +437,7 @@ def fetch_resource_type_schema(self, **options): assert "message" in resp assert provider.search_instance_spy == { "options": {"language": "en"}, - "filter": {"parent": "parent", "keyword": "keyword"}, + "filter": {"parent": "parent", "keyword": "keyword", "action": "action", "ancestors": "ancestors"}, "page": {"limit": "limit", "offset": "offset"}, } diff --git a/tests/test_utils.py b/tests/test_utils.py index 866e718..bea28de 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -65,6 +65,7 @@ def get_resource_name(system, resource): "module": "module_type", }, "another_system": {"r4": "r4_type"}, + "bk_cmdb": {"biz": "biz", "set": "set", "module": "module"} }[system][resource] with patch("iam.utils.meta.get_system_name", MagicMock(side_effect=get_system_name)): @@ -90,7 +91,6 @@ def get_resource_name(system, resource): ) # assert data - # TODO: fix dict compare assert data == { "system_id": "test_system", "system_name": "test_system_name", @@ -105,21 +105,55 @@ def get_resource_name(system, resource): "type": "r3", "type_name": "r3_type", "instances": [ - [{"type": "r1", "type_name": "r1_type", "id": "r1id", "name": "r1n"}], - [{"type": "r2", "type_name": "r2_type", "id": "r2id", "name": ""}], - [{"type": "r3", "type_name": "r3_type", "id": "r3id", "name": ""}], - ], + [ + { + "type": "r1", + "type_name": "r1_type", + "id": "r1id", + "name": "r1n" + } + ], + [ + { + "type": "r2", + "type_name": "r2_type", + "id": "r2id", + "name": "" + } + ], + [ + { + "type": "r3", + "type_name": "r3_type", + "id": "r3id", + "name": "" + } + ] + ] }, { "system_id": "another_system", "system_name": "another_system_name", "type": "r4", "type_name": "r4_type", - "instances": [[{"type": "r4", "type_name": "r4_type", "id": "r4id", "name": "r4n"}]], - }, - ], + "instances": [ + [ + { + "type": "r4", + "type_name": "r4_type", + "id": "r4id", + "name": "r4n" + } + ] + ] + } + ] + }, + { + "id": "action2", + "name": "action2_name", + "related_resource_types": [] }, - {"id": "action2", "name": "action2_name", "related_resource_types": []}, { "id": "action3", "name": "action3_name", @@ -130,13 +164,55 @@ def get_resource_name(system, resource): "type": "r3", "type_name": "r3_type", "instances": [ - [{"type": "r1", "type_name": "r1_type", "id": "r1id", "name": "r1n"}], - [{"type": "r3", "type_name": "r3_type", "id": "r3id", "name": ""}], - [{"type": "r1", "type_name": "r1_type", "id": "r1id", "name": "r1n"}], - [{"type": "r3", "type_name": "r3_type", "id": "r3id", "name": ""}], - [{"type": "r2", "type_name": "r2_type", "id": "r2id", "name": ""}], - [{"type": "r3", "type_name": "r3_type", "id": "r3id", "name": ""}], - ], + [ + { + "type": "r1", + "type_name": "r1_type", + "id": "r1id", + "name": "r1n" + } + ], + [ + { + "type": "r3", + "type_name": "r3_type", + "id": "r3id", + "name": "" + } + ], + [ + { + "type": "r1", + "type_name": "r1_type", + "id": "r1id", + "name": "r1n" + } + ], + [ + { + "type": "r3", + "type_name": "r3_type", + "id": "r3id", + "name": "" + } + ], + [ + { + "type": "r2", + "type_name": "r2_type", + "id": "r2id", + "name": "" + } + ], + [ + { + "type": "r3", + "type_name": "r3_type", + "id": "r3id", + "name": "" + } + ] + ] }, { "system_id": "another_system", @@ -144,12 +220,33 @@ def get_resource_name(system, resource): "type": "r4", "type_name": "r4_type", "instances": [ - [{"type": "r4", "type_name": "r4_type", "id": "r4id", "name": "r4n"}], - [{"type": "r4", "type_name": "r4_type", "id": "r4id", "name": "r4n"}], - [{"type": "r4", "type_name": "r4_type", "id": "r5id", "name": "r5n"}], - ], - }, - ], + [ + { + "type": "r4", + "type_name": "r4_type", + "id": "r4id", + "name": "r4n" + } + ], + [ + { + "type": "r4", + "type_name": "r4_type", + "id": "r4id", + "name": "r4n" + } + ], + [ + { + "type": "r4", + "type_name": "r4_type", + "id": "r5id", + "name": "r5n" + } + ] + ] + } + ] }, { "id": "action4", @@ -162,14 +259,34 @@ def get_resource_name(system, resource): "type_name": "r6_type", "instances": [ [ - {"type": "biz", "type_name": "biz_type", "id": "1", "name": "biz,1"}, - {"type": "set", "type_name": "set_type", "id": "2", "name": "set,2"}, - {"type": "module", "type_name": "module_type", "id": "3", "name": "module,3"}, - {"type": "r6", "type_name": "r6_type", "id": "r6id", "name": "r6n"}, + { + "type": "biz", + "type_name": "biz_type", + "id": "1", + "name": "biz,1" + }, + { + "type": "set", + "type_name": "set_type", + "id": "2", + "name": "set,2" + }, + { + "type": "module", + "type_name": "module_type", + "id": "3", + "name": "module,3" + }, + { + "type": "r6", + "type_name": "r6_type", + "id": "r6id", + "name": "r6n" + } ] - ], + ] } - ], + ] }, { "id": "action4", @@ -182,14 +299,34 @@ def get_resource_name(system, resource): "type_name": "r7_type", "instances": [ [ - {"type": "biz", "type_name": "biz_type", "id": "1", "name": "biz,1"}, - {"type": "set", "type_name": "set_type", "id": "2", "name": "set,2"}, - {"type": "module", "type_name": "module_type", "id": "3", "name": "module,3"}, - {"type": "r7", "type_name": "r7_type", "id": "r7id", "name": "r7n"}, + { + "type": "biz", + "type_name": "biz", + "id": "1", + "name": "biz,1" + }, + { + "type": "set", + "type_name": "set", + "id": "2", + "name": "set,2" + }, + { + "type": "module", + "type_name": "module", + "id": "3", + "name": "module,3" + }, + { + "type": "r7", + "type_name": "r7_type", + "id": "r7id", + "name": "r7n" + } ] - ], + ] } - ], - }, - ], + ] + } + ] }