Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api/web/resource_version): fix stage plugins #817

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@
# We undertake not to change the open source license (MIT license) applicable
# to the current version of the project delivered to anyone in the future.
#
import copy

from rest_framework import serializers

from apigateway.apps.plugin.constants import PluginBindingScopeEnum
@@ -78,7 +80,7 @@ def get_proxy(self, obj):
return proxy

def get_plugins(self, obj):
plugins = self.context.get("stage_plugins", {})
plugins = copy.deepcopy(self.context.get("stage_plugins", {}))

# v2 才有plugin数据
if not self.context["is_schema_v2"]:
Original file line number Diff line number Diff line change
@@ -221,3 +221,53 @@ def test_to_representation_v2(
"created_by": fake_resource_version_v2.created_by,
}
assert slz.data == expected_data

def test_to_representation_v2_with_resources(
self,
fake_backend,
fake_stage,
fake_gateway,
fake_resource2,
echo_plugin_resource_binding,
fake_resource_version_v2,
echo_plugin_stage_binding,
):
stage_plugin_bindings = PluginBindingHandler.get_stage_plugin_bindings(fake_gateway.id, fake_stage.id)
stage_plugins = {}
for plugin_type, plugin_binding in stage_plugin_bindings.items():
plugin_config = plugin_binding.snapshot()
plugin_config["binding_type"] = PluginBindingScopeEnum.STAGE.value
stage_plugins[plugin_type] = plugin_config
slz = serializers.ResourceVersionRetrieveOutputSLZ(
instance=fake_resource_version_v2,
context={
"resource_backends": BackendHandler.get_id_to_instance(fake_gateway.id),
"resource_backend_configs": BackendHandler.get_backend_configs_by_stage(
fake_gateway.id, fake_stage.id
),
"is_schema_v2": fake_resource_version_v2.is_schema_v2,
"stage_plugins": stage_plugins,
"resource_doc_updated_time": {},
},
)
for resource in slz.data["resources"]:
if resource["name"] == fake_resource2.name:
assert resource["plugins"] == [
{
"id": echo_plugin_stage_binding.id,
"type": echo_plugin_stage_binding.get_type(),
"name": echo_plugin_stage_binding.config.type.name,
"config": echo_plugin_stage_binding.get_config(),
"binding_type": echo_plugin_stage_binding.scope_type,
},
]
else:
assert resource["plugins"] == [
{
"id": echo_plugin_resource_binding.id,
"type": echo_plugin_resource_binding.get_type(),
"name": echo_plugin_resource_binding.config.type.name,
"config": echo_plugin_resource_binding.get_config(),
"binding_type": echo_plugin_resource_binding.scope_type,
},
]