diff --git a/src/dashboard/apigateway/apigateway/apis/web/resource_version/views.py b/src/dashboard/apigateway/apigateway/apis/web/resource_version/views.py index c6468a583..c96fd8c02 100644 --- a/src/dashboard/apigateway/apigateway/apis/web/resource_version/views.py +++ b/src/dashboard/apigateway/apigateway/apis/web/resource_version/views.py @@ -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 diff --git a/src/dashboard/apigateway/apigateway/tests/apis/web/release/test_views.py b/src/dashboard/apigateway/apigateway/tests/apis/web/release/test_views.py index 244946ae6..029ea7a2f 100644 --- a/src/dashboard/apigateway/apigateway/tests/apis/web/release/test_views.py +++ b/src/dashboard/apigateway/apigateway/tests/apis/web/release/test_views.py @@ -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) @@ -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: