Add test for tweak with no node id
This commit is contained in:
parent
af5933524a
commit
7ec33d3fe0
1 changed files with 83 additions and 6 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from langflow.processing.process import process_tweaks
|
from langflow.processing.process import process_tweaks
|
||||||
from langflow.services.deps import get_session_service
|
from langflow.services.deps import get_session_service
|
||||||
|
|
||||||
|
|
@ -164,6 +165,70 @@ def test_multiple_tweaks():
|
||||||
assert result == expected_result
|
assert result == expected_result
|
||||||
|
|
||||||
|
|
||||||
|
# Test twekas that just pass the param and value but no node id.
|
||||||
|
# This is a new feature that was added to the process_tweaks function
|
||||||
|
def test_tweak_no_node_id():
|
||||||
|
graph_data = {
|
||||||
|
"data": {
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"id": "node1",
|
||||||
|
"data": {
|
||||||
|
"node": {
|
||||||
|
"template": {
|
||||||
|
"param1": {"value": 1},
|
||||||
|
"param2": {"value": 2},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "node2",
|
||||||
|
"data": {
|
||||||
|
"node": {
|
||||||
|
"template": {
|
||||||
|
"param1": {"value": 3},
|
||||||
|
"param2": {"value": 4},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tweaks = {"param1": 5}
|
||||||
|
expected_result = {
|
||||||
|
"data": {
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"id": "node1",
|
||||||
|
"data": {
|
||||||
|
"node": {
|
||||||
|
"template": {
|
||||||
|
"param1": {"value": 5},
|
||||||
|
"param2": {"value": 2},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "node2",
|
||||||
|
"data": {
|
||||||
|
"node": {
|
||||||
|
"template": {
|
||||||
|
"param1": {"value": 5},
|
||||||
|
"param2": {"value": 4},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = process_tweaks(graph_data, tweaks)
|
||||||
|
assert result == expected_result
|
||||||
|
|
||||||
|
|
||||||
def test_tweak_not_in_template():
|
def test_tweak_not_in_template():
|
||||||
graph_data = {
|
graph_data = {
|
||||||
"data": {
|
"data": {
|
||||||
|
|
@ -203,9 +268,13 @@ async def test_load_langchain_object_with_cached_session(client, basic_graph_dat
|
||||||
# Provide a non-existent session_id
|
# Provide a non-existent session_id
|
||||||
session_service = get_session_service()
|
session_service = get_session_service()
|
||||||
session_id1 = "non-existent-session-id"
|
session_id1 = "non-existent-session-id"
|
||||||
graph1, artifacts1 = await session_service.load_session(session_id1, basic_graph_data)
|
graph1, artifacts1 = await session_service.load_session(
|
||||||
|
session_id1, basic_graph_data
|
||||||
|
)
|
||||||
# Use the new session_id to get the langchain_object again
|
# Use the new session_id to get the langchain_object again
|
||||||
graph2, artifacts2 = await session_service.load_session(session_id1, basic_graph_data)
|
graph2, artifacts2 = await session_service.load_session(
|
||||||
|
session_id1, basic_graph_data
|
||||||
|
)
|
||||||
|
|
||||||
assert graph1 == graph2
|
assert graph1 == graph2
|
||||||
assert artifacts1 == artifacts2
|
assert artifacts1 == artifacts2
|
||||||
|
|
@ -217,11 +286,15 @@ async def test_load_langchain_object_with_no_cached_session(client, basic_graph_
|
||||||
session_service = get_session_service()
|
session_service = get_session_service()
|
||||||
session_id1 = "non-existent-session-id"
|
session_id1 = "non-existent-session-id"
|
||||||
session_id = session_service.build_key(session_id1, basic_graph_data)
|
session_id = session_service.build_key(session_id1, basic_graph_data)
|
||||||
graph1, artifacts1 = await session_service.load_session(session_id, basic_graph_data)
|
graph1, artifacts1 = await session_service.load_session(
|
||||||
|
session_id, basic_graph_data
|
||||||
|
)
|
||||||
# Clear the cache
|
# Clear the cache
|
||||||
session_service.clear_session(session_id)
|
session_service.clear_session(session_id)
|
||||||
# Use the new session_id to get the langchain_object again
|
# Use the new session_id to get the langchain_object again
|
||||||
graph2, artifacts2 = await session_service.load_session(session_id, basic_graph_data)
|
graph2, artifacts2 = await session_service.load_session(
|
||||||
|
session_id, basic_graph_data
|
||||||
|
)
|
||||||
|
|
||||||
assert id(graph1) != id(graph2)
|
assert id(graph1) != id(graph2)
|
||||||
# Since the cache was cleared, objects should be different
|
# Since the cache was cleared, objects should be different
|
||||||
|
|
@ -232,8 +305,12 @@ async def test_load_langchain_object_without_session_id(client, basic_graph_data
|
||||||
# Provide a non-existent session_id
|
# Provide a non-existent session_id
|
||||||
session_service = get_session_service()
|
session_service = get_session_service()
|
||||||
session_id1 = None
|
session_id1 = None
|
||||||
graph1, artifacts1 = await session_service.load_session(session_id1, basic_graph_data)
|
graph1, artifacts1 = await session_service.load_session(
|
||||||
|
session_id1, basic_graph_data
|
||||||
|
)
|
||||||
# Use the new session_id to get the langchain_object again
|
# Use the new session_id to get the langchain_object again
|
||||||
graph2, artifacts2 = await session_service.load_session(session_id1, basic_graph_data)
|
graph2, artifacts2 = await session_service.load_session(
|
||||||
|
session_id1, basic_graph_data
|
||||||
|
)
|
||||||
|
|
||||||
assert graph1 == graph2
|
assert graph1 == graph2
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue