Add tests for custom component validation and
template generation
This commit is contained in:
parent
327cd0b462
commit
e3a1f39c87
1 changed files with 20 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ from fastapi import HTTPException
|
||||||
from langflow.interface.custom.base import CustomComponent
|
from langflow.interface.custom.base import CustomComponent
|
||||||
from langflow.interface.custom.code_parser import CodeParser, CodeSyntaxError
|
from langflow.interface.custom.code_parser import CodeParser, CodeSyntaxError
|
||||||
from langflow.interface.custom.component import Component, ComponentCodeNullError
|
from langflow.interface.custom.component import Component, ComponentCodeNullError
|
||||||
|
from langflow.interface.types import build_langchain_template_custom_component, create_and_validate_component
|
||||||
from langflow.services.database.models.flow import Flow, FlowCreate
|
from langflow.services.database.models.flow import Flow, FlowCreate
|
||||||
|
|
||||||
code_default = """
|
code_default = """
|
||||||
|
|
@ -529,3 +530,22 @@ def test_build_config_field_value_keys(component):
|
||||||
config = component.build_config()
|
config = component.build_config()
|
||||||
field_values = config["fields"].values()
|
field_values = config["fields"].values()
|
||||||
assert all("type" in value for value in field_values)
|
assert all("type" in value for value in field_values)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_and_validate_component_valid_code(test_component_code):
|
||||||
|
component = create_and_validate_component(test_component_code)
|
||||||
|
assert isinstance(component, CustomComponent)
|
||||||
|
|
||||||
|
|
||||||
|
def test_build_langchain_template_custom_component_valid_code(test_component_code):
|
||||||
|
component = create_and_validate_component(test_component_code)
|
||||||
|
frontend_node = build_langchain_template_custom_component(component)
|
||||||
|
assert isinstance(frontend_node, dict)
|
||||||
|
template = frontend_node["template"]
|
||||||
|
assert isinstance(template, dict)
|
||||||
|
assert "param" in template
|
||||||
|
param_options = template["param"]["options"]
|
||||||
|
# Now run it again with an update field
|
||||||
|
frontend_node = build_langchain_template_custom_component(component, update_field="param")
|
||||||
|
new_param_options = frontend_node["template"]["param"]["options"]
|
||||||
|
assert param_options != new_param_options
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue