refactor: move langflow api tests into integration tests (#2469)

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-07-01 19:25:56 -03:00 committed by GitHub
commit 32e12cf72a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 90 additions and 114 deletions

View file

@ -640,22 +640,6 @@ def test_successful_run_with_input_type_any(client, starter_project, created_api
), any_input_outputs
@pytest.mark.api_key_required
def test_run_with_inputs_and_outputs(client, starter_project, created_api_key):
headers = {"x-api-key": created_api_key.api_key}
flow_id = starter_project["id"]
payload = {
"input_value": "value1",
"input_type": "text",
"output_type": "text",
"tweaks": {"parameter_name": "value"},
"stream": False,
}
response = client.post(f"/api/v1/run/{flow_id}", json=payload, headers=headers)
assert response.status_code == status.HTTP_200_OK, response.text
# Validate the response structure and content
def test_invalid_flow_id(client, created_api_key):
headers = {"x-api-key": created_api_key.api_key}
flow_id = "invalid-flow-id"
@ -666,88 +650,3 @@ def test_invalid_flow_id(client, created_api_key):
response = client.post(f"/api/v1/run/{flow_id}", headers=headers)
assert response.status_code == status.HTTP_404_NOT_FOUND, response.text
# Check if the error detail is as expected
@pytest.mark.api_key_required
def test_run_flow_with_caching_success(client: TestClient, starter_project, created_api_key):
flow_id = starter_project["id"]
headers = {"x-api-key": created_api_key.api_key}
payload = {
"input_value": "value1",
"input_type": "text",
"output_type": "text",
"tweaks": {"parameter_name": "value"},
"stream": False,
}
response = client.post(f"/api/v1/run/{flow_id}", json=payload, headers=headers)
assert response.status_code == status.HTTP_200_OK
data = response.json()
assert "outputs" in data
assert "session_id" in data
@pytest.mark.api_key_required
def test_run_flow_with_caching_invalid_flow_id(client: TestClient, created_api_key):
invalid_flow_id = uuid4()
headers = {"x-api-key": created_api_key.api_key}
payload = {"input_value": "", "input_type": "text", "output_type": "text", "tweaks": {}, "stream": False}
response = client.post(f"/api/v1/run/{invalid_flow_id}", json=payload, headers=headers)
assert response.status_code == status.HTTP_404_NOT_FOUND
data = response.json()
assert "detail" in data
assert f"Flow identifier {invalid_flow_id} not found" in data["detail"]
@pytest.mark.api_key_required
def test_run_flow_with_caching_invalid_input_format(client: TestClient, starter_project, created_api_key):
flow_id = starter_project["id"]
headers = {"x-api-key": created_api_key.api_key}
payload = {"input_value": {"key": "value"}, "input_type": "text", "output_type": "text", "tweaks": {}}
response = client.post(f"/api/v1/run/{flow_id}", json=payload, headers=headers)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
# @pytest.mark.api_key_required
# def test_run_flow_with_session_id(client, starter_project, created_api_key):
# headers = {"x-api-key": created_api_key.api_key}
# flow_id = starter_project["id"]
# payload = {
# "input_value": "value1",
# "input_type": "text",
# "output_type": "text",
# "session_id": "test-session-id",
# }
# response = client.post(f"/api/v1/run/{flow_id}", json=payload, headers=headers)
# assert response.status_code == status.HTTP_404_NOT_FOUND
# data = response.json()
# assert {"detail": "Session test-session-id not found"} == data
# def test_run_flow_with_invalid_session_id(client, starter_project, created_api_key):
# headers = {"x-api-key": created_api_key.api_key}
# flow_id = starter_project["id"]
# payload = {
# "input_value": "value1",
# "input_type": "text",
# "output_type": "text",
# "session_id": "invalid-session-id",
# }
# response = client.post(f"/api/v1/run/{flow_id}", json=payload, headers=headers)
# assert response.status_code == status.HTTP_404_NOT_FOUND
# data = response.json()
# assert "detail" in data
# assert f"Session {payload['session_id']} not found" in data["detail"]
@pytest.mark.api_key_required
def test_run_flow_with_invalid_tweaks(client, starter_project, created_api_key):
headers = {"x-api-key": created_api_key.api_key}
flow_id = starter_project["id"]
payload = {
"input_value": "value1",
"input_type": "text",
"output_type": "text",
"tweaks": {"invalid_tweak": "value"},
}
response = client.post(f"/api/v1/run/{flow_id}", json=payload, headers=headers)
assert response.status_code == status.HTTP_200_OK