Skip to content

Commit

Permalink
fix(api/web): fix resource_version diff (TencentBlueKing#1081)
Browse files Browse the repository at this point in the history
* fix(api/web): fix resource_version diff
  • Loading branch information
Han-Ya-Jun authored and Carlmac committed Oct 30, 2024
1 parent ad3b71a commit 7c66564
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,12 @@ def get(self, request, *args, **kwargs):
source_resource_version_id = data.get("source_resource_version_id")
target_resource_version_id = data.get("target_resource_version_id")

# 如果 source_resource_version_id 为空,需要将 source_resource_data 置为空,相当于
# target_resource_data 和 空版本对比
source_resource_data = (
ResourceVersionHandler.get_data_by_id_or_new(request.gateway, source_resource_version_id)
if source_resource_version_id
else []
)
source_resource_data = []
# 如果 source_resource_version_id 和 target_resource_version_id 都不为空,则 source_resource_data数据不为空
if source_resource_version_id or target_resource_version_id:
source_resource_data = ResourceVersionHandler.get_data_by_id_or_new(
request.gateway, source_resource_version_id
)

target_resource_data = ResourceVersionHandler.get_data_by_id_or_new(
request.gateway, target_resource_version_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,39 @@ def test_release_with_hosts(
class TestReleaseAvailableResourceListApi:
def test_list(self, request_view, fake_gateway, fake_stage):
stage_1 = G(Stage, gateway=fake_gateway, name="prod", status=0)
resource_version = G(ResourceVersion, gateway=fake_gateway, _data=json.dumps([{
"id": 1,
"name": "test",
"method": "get",
"path": "/test/",
"description": "test...",
"description_en": "",
"match_subpath": "",
"is_public": True,
"allow_apply_permission": True,
"disabled_stages": [],
"contexts": {
"resource_auth": {
"config": json.dumps({
"app_verified_required": True,
"skip_auth_verification": True,
"auth_verified_required": True,
"resource_perm_required": True
})
}
},
"api_labels": "",
}]))
resource_version = G(
ResourceVersion,
gateway=fake_gateway,
_data=json.dumps(
[
{
"id": 1,
"name": "test",
"method": "get",
"path": "/test/",
"description": "test...",
"description_en": "",
"match_subpath": "",
"is_public": True,
"allow_apply_permission": True,
"disabled_stages": [],
"contexts": {
"resource_auth": {
"config": json.dumps(
{
"app_verified_required": True,
"skip_auth_verification": True,
"auth_verified_required": True,
"resource_perm_required": True,
}
)
}
},
"api_labels": "",
}
]
),
)

G(Release, gateway=fake_gateway, stage=stage_1, resource_version=resource_version)

Expand All @@ -130,9 +140,22 @@ def test_list(self, request_view, fake_gateway, fake_stage):
result = response.json()

assert response.status_code == 200
assert result == {'data': [{'id': 1, 'name': 'test', 'description': 'test...', 'method': 'get',
'path': '/test/', 'verified_user_required': False, 'verified_app_required': True,
'resource_perm_required': True, 'is_public': True, 'labels': []}]}
assert result == {
"data": [
{
"id": 1,
"name": "test",
"description": "test...",
"method": "get",
"path": "/test/",
"verified_user_required": False,
"verified_app_required": True,
"resource_perm_required": True,
"is_public": True,
"labels": [],
}
]
}


class TestReleaseResourceSchemaRetrieve:
Expand Down

0 comments on commit 7c66564

Please sign in to comment.