Refactor code and fix minor issues

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-01-26 09:45:33 -03:00
commit dbf0a2a920
7 changed files with 20 additions and 56 deletions

View file

@ -66,9 +66,7 @@ class NameTest(FastHttpUser):
result1, session_id = self.process(name, self.flow_id, payload1)
payload2 = {
"inputs": {
"text": "What is my name? Please, answer like this: Your name is <name>"
},
"inputs": {"text": "What is my name? Please, answer like this: Your name is <name>"},
"session_id": session_id,
"sync": False,
}
@ -88,9 +86,7 @@ class NameTest(FastHttpUser):
logged_in_headers = {"Authorization": f"Bearer {a_token}"}
print("Logged in")
with open(
Path(__file__).parent.parent
/ "data"
/ "BasicChatwithPromptandHistory.json",
Path(__file__).parent.parent / "data" / "BasicChatwithPromptandHistory.json",
"r",
) as f:
json_flow = f.read()
@ -115,11 +111,7 @@ class NameTest(FastHttpUser):
)
print(response.json())
user_id = next(
(
user["id"]
for user in response.json()["users"]
if user["username"] == "superuser"
),
(user["id"] for user in response.json()["users"] if user["username"] == "superuser"),
None,
)
# Create api key

View file

@ -6,9 +6,7 @@ from langflow.services.database.models.api_key import ApiKeyCreate
def api_key(client, logged_in_headers, active_user):
api_key = ApiKeyCreate(name="test-api-key")
response = client.post(
"api/v1/api_key", data=api_key.json(), headers=logged_in_headers
)
response = client.post("api/v1/api_key", data=api_key.json(), headers=logged_in_headers)
assert response.status_code == 200, response.text
return response.json()
@ -28,9 +26,7 @@ def test_get_api_keys(client, logged_in_headers, api_key):
def test_create_api_key(client, logged_in_headers):
api_key_name = "test-api-key"
response = client.post(
"api/v1/api_key", json={"name": api_key_name}, headers=logged_in_headers
)
response = client.post("api/v1/api_key", json={"name": api_key_name}, headers=logged_in_headers)
assert response.status_code == 200
data = response.json()
assert "name" in data and data["name"] == api_key_name

View file

@ -18,9 +18,7 @@ def test_python_function_tool():
with pytest.raises(SyntaxError):
code = pytest.CODE_WITH_SYNTAX_ERROR
func = get_function(code)
func = PythonFunctionTool(
name="Test", description="Testing", code=code, func=func
)
func = PythonFunctionTool(name="Test", description="Testing", code=code, func=func)
def test_python_function():

View file

@ -31,9 +31,7 @@ def test_websocket_endpoint(client: TestClient, active_user, logged_in_headers):
# Assuming your websocket_endpoint uses chat_service which caches data from stream_build
access_token = logged_in_headers["Authorization"].split(" ")[1]
with pytest.raises(WebSocketDisconnect):
with client.websocket_connect(
f"api/v1/chat/non_existing_client_id?token={access_token}"
) as websocket:
with client.websocket_connect(f"api/v1/chat/non_existing_client_id?token={access_token}") as websocket:
websocket.send_json({"type": "test"})
data = websocket.receive_json()
assert "Please, build the flow before sending messages" in data["message"]