* refactor(base.py): refactor logic to find start_component_id based on multiple keywords for improved flexibility and readability * feat(schema.py): add WebhookInput component type to INPUT_COMPONENTS list for handling webhook inputs in the graph schema * refactor(base.py): refactor logic to determine start_component_id based on webhook or chat component presence in input vertices * refactor: prioritize webhook component for determining start_component_id * feat(utils.py): add function find_start_component_id to find component ID based on priority list of input types * refactor(graph/base.py): refactor logic to find start component id in Graph class for better readability and maintainability * test(test_webhook.py): override pytest fixture to check for OpenAI API key in environment variables before running tests * test(test_webhook.py): update webhook json * feat(schema.py): update WebhookInput component type name * refactor: log package run telemetry in simplified_run_flow * test: add test for webhook flow on run endpoint * refactor(graph/base.py): skip unbuilt vertices when getting vertex outputs in Graph class * refactor: simplify data_input assignment in LCTextSplitterComponent * refactor: remove unused build method in CharacterTextSplitterComponent * refactor: update imports in CharacterTextSplitter.py
59 lines
2 KiB
Python
59 lines
2 KiB
Python
import tempfile
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def check_openai_api_key_in_environment_variables():
|
|
pass
|
|
|
|
|
|
def test_webhook_endpoint(client, added_webhook_test):
|
|
# The test is as follows:
|
|
# 1. The flow when run will get a "path" from the payload and save a file with the path as the name.
|
|
# We will create a temporary file path and send it to the webhook endpoint, then check if the file exists.
|
|
# 2. we will delete the file, then send an invalid payload to the webhook endpoint and check if the file exists.
|
|
endpoint_name = added_webhook_test["endpoint_name"]
|
|
endpoint = f"api/v1/webhook/{endpoint_name}"
|
|
# Create a temporary file
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
file_path = Path(tmp) / "test_file.txt"
|
|
|
|
payload = {"path": str(file_path)}
|
|
|
|
response = client.post(endpoint, json=payload)
|
|
assert response.status_code == 202
|
|
assert file_path.exists()
|
|
|
|
assert not file_path.exists()
|
|
|
|
# Send an invalid payload
|
|
payload = {"invalid_key": "invalid_value"}
|
|
response = client.post(endpoint, json=payload)
|
|
assert response.status_code == 202
|
|
assert not file_path.exists()
|
|
|
|
|
|
def test_webhook_flow_on_run_endpoint(client, added_webhook_test, created_api_key):
|
|
endpoint_name = added_webhook_test["endpoint_name"]
|
|
endpoint = f"api/v1/run/{endpoint_name}?stream=false"
|
|
# Just test that "Random Payload" returns 202
|
|
# returns 202
|
|
payload = {
|
|
"output_type": "any",
|
|
}
|
|
response = client.post(endpoint, headers={"x-api-key": created_api_key.api_key}, json=payload)
|
|
assert response.status_code == 200, response.json()
|
|
|
|
|
|
def test_webhook_with_random_payload(client, added_webhook_test):
|
|
endpoint_name = added_webhook_test["endpoint_name"]
|
|
endpoint = f"api/v1/webhook/{endpoint_name}"
|
|
# Just test that "Random Payload" returns 202
|
|
# returns 202
|
|
response = client.post(
|
|
endpoint,
|
|
json="Random Payload",
|
|
)
|
|
assert response.status_code == 202
|