Skip to content

Commit

Permalink
fix: 补充资源反向拉取单元测试 & 存量单元测试修复
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud committed Nov 9, 2023
1 parent e6c9301 commit bcd71d4
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 43 deletions.
32 changes: 25 additions & 7 deletions tests/contrib/django/dispatcher/test_dispatchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"},
}
)
Expand All @@ -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",
)
Expand All @@ -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"},
}

Expand All @@ -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"},
}
)
Expand All @@ -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",
)
Expand All @@ -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"},
}

Expand Down
209 changes: 173 additions & 36 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -130,26 +164,89 @@ 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",
"system_name": "another_system_name",
"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",
Expand All @@ -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",
Expand All @@ -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"
}
]
],
]
}
],
},
],
]
}
]
}

0 comments on commit bcd71d4

Please sign in to comment.