ref: Fix unused args in tests (#4156)

Fix unused args in tests
This commit is contained in:
Christophe Bornet 2024-10-15 17:05:19 +02:00 committed by GitHub
commit 3c6ec0cf9e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 94 additions and 63 deletions

View file

@ -16,7 +16,8 @@ async def body():
}
async def test_create_variable(client: AsyncClient, body, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_create_variable(client: AsyncClient, body, logged_in_headers):
response = await client.post("api/v1/variables/", json=body, headers=logged_in_headers)
result = response.json()
@ -28,7 +29,8 @@ async def test_create_variable(client: AsyncClient, body, active_user, logged_in
assert body["value"] != result["value"]
async def test_create_variable__variable_name_already_exists(client: AsyncClient, body, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_create_variable__variable_name_already_exists(client: AsyncClient, body, logged_in_headers):
await client.post("api/v1/variables/", json=body, headers=logged_in_headers)
response = await client.post("api/v1/variables/", json=body, headers=logged_in_headers)
@ -38,9 +40,8 @@ async def test_create_variable__variable_name_already_exists(client: AsyncClient
assert "Variable name already exists" in result["detail"]
async def test_create_variable__variable_name_and_value_cannot_be_empty(
client: AsyncClient, body, active_user, logged_in_headers
):
@pytest.mark.usefixtures("active_user")
async def test_create_variable__variable_name_and_value_cannot_be_empty(client: AsyncClient, body, logged_in_headers):
body["name"] = ""
body["value"] = ""
@ -51,9 +52,8 @@ async def test_create_variable__variable_name_and_value_cannot_be_empty(
assert "Variable name and value cannot be empty" in result["detail"]
async def test_create_variable__variable_name_cannot_be_empty(
client: AsyncClient, body, active_user, logged_in_headers
):
@pytest.mark.usefixtures("active_user")
async def test_create_variable__variable_name_cannot_be_empty(client: AsyncClient, body, logged_in_headers):
body["name"] = ""
response = await client.post("api/v1/variables/", json=body, headers=logged_in_headers)
@ -63,9 +63,8 @@ async def test_create_variable__variable_name_cannot_be_empty(
assert "Variable name cannot be empty" in result["detail"]
async def test_create_variable__variable_value_cannot_be_empty(
client: AsyncClient, body, active_user, logged_in_headers
):
@pytest.mark.usefixtures("active_user")
async def test_create_variable__variable_value_cannot_be_empty(client: AsyncClient, body, logged_in_headers):
body["value"] = ""
response = await client.post("api/v1/variables/", json=body, headers=logged_in_headers)
@ -75,7 +74,8 @@ async def test_create_variable__variable_value_cannot_be_empty(
assert "Variable value cannot be empty" in result["detail"]
async def test_create_variable__HTTPException(client: AsyncClient, body, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_create_variable__HTTPException(client: AsyncClient, body, logged_in_headers):
status_code = 418
generic_message = "I'm a teapot"
@ -88,7 +88,8 @@ async def test_create_variable__HTTPException(client: AsyncClient, body, active_
assert generic_message in result["detail"]
async def test_create_variable__Exception(client: AsyncClient, body, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_create_variable__Exception(client: AsyncClient, body, logged_in_headers):
generic_message = "Generic error message"
with mock.patch("langflow.services.auth.utils.encrypt_api_key") as m:
@ -100,7 +101,8 @@ async def test_create_variable__Exception(client: AsyncClient, body, active_user
assert generic_message in result["detail"]
async def test_read_variables(client: AsyncClient, body, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_read_variables(client: AsyncClient, body, logged_in_headers):
names = ["test_variable1", "test_variable2", "test_variable3"]
for name in names:
body["name"] = name
@ -113,7 +115,8 @@ async def test_read_variables(client: AsyncClient, body, active_user, logged_in_
assert all(name in [r["name"] for r in result] for name in names)
async def test_read_variables__empty(client: AsyncClient, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_read_variables__empty(client: AsyncClient, logged_in_headers):
all_variables = await client.get("api/v1/variables/", headers=logged_in_headers)
all_variables = all_variables.json()
for variable in all_variables:
@ -126,7 +129,8 @@ async def test_read_variables__empty(client: AsyncClient, active_user, logged_in
assert [] == result
async def test_read_variables__(client: AsyncClient, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_read_variables__(client: AsyncClient, logged_in_headers):
generic_message = "Generic error message"
with pytest.raises(Exception) as exc:
@ -142,7 +146,8 @@ async def test_read_variables__(client: AsyncClient, active_user, logged_in_head
assert generic_message in str(exc.value)
async def test_update_variable(client: AsyncClient, body, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_update_variable(client: AsyncClient, body, logged_in_headers):
saved = await client.post("api/v1/variables/", json=body, headers=logged_in_headers)
saved = saved.json()
body["id"] = saved.get("id")
@ -160,7 +165,8 @@ async def test_update_variable(client: AsyncClient, body, active_user, logged_in
assert saved["default_fields"] != result["default_fields"]
async def test_update_variable__Exception(client: AsyncClient, body, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_update_variable__Exception(client: AsyncClient, body, logged_in_headers):
wrong_id = uuid4()
body["id"] = str(wrong_id)
@ -171,7 +177,8 @@ async def test_update_variable__Exception(client: AsyncClient, body, active_user
assert "Variable not found" in result["detail"]
async def test_delete_variable(client: AsyncClient, body, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_delete_variable(client: AsyncClient, body, logged_in_headers):
response = await client.post("api/v1/variables/", json=body, headers=logged_in_headers)
saved = response.json()
response = await client.delete(f"api/v1/variables/{saved.get('id')}", headers=logged_in_headers)
@ -179,7 +186,8 @@ async def test_delete_variable(client: AsyncClient, body, active_user, logged_in
assert status.HTTP_204_NO_CONTENT == response.status_code
async def test_delete_variable__Exception(client: AsyncClient, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_delete_variable__Exception(client: AsyncClient, logged_in_headers):
wrong_id = uuid4()
response = await client.delete(f"api/v1/variables/{wrong_id}", headers=logged_in_headers)

View file

@ -87,7 +87,8 @@ def test_component_tool():
@pytest.mark.api_key_required
def test_component_tool_with_api_key(client, add_toolkit_output):
@pytest.mark.usefixtures("add_toolkit_output")
def test_component_tool_with_api_key():
chat_output = ChatOutput()
openai_llm = OpenAIModelComponent()
openai_llm.set(api_key=os.environ["OPENAI_API_KEY"])

View file

@ -118,7 +118,7 @@ def test_update_build_config_keep_alive(component):
"langchain_community.chat_models.ChatOllama",
return_value=ChatOllama(base_url="http://localhost:11434", model="llama3.1"),
)
def test_build_model(mock_chat_ollama, component):
def test_build_model(_mock_chat_ollama, component):
component.base_url = "http://localhost:11434"
component.model_name = "llama3.1"
component.mirostat = "Mirostat 2.0"

View file

@ -12,7 +12,7 @@ def client():
pass
def test_edge_raises_error_on_invalid_target_handle(client):
def test_edge_raises_error_on_invalid_target_handle():
template = """Answer the user as if you were a pirate.
User: {user_input}

View file

@ -30,7 +30,7 @@ class LogComponent(Component):
def test_callback_graph():
logs: list[tuple[str, dict]] = []
def mock_callback(manager, event_type: str, data: dict):
def mock_callback(manager, event_type: str, data: dict): # noqa: ARG001
logs.append((event_type, data))
event_manager = EventManager(queue=asyncio.Queue())

View file

@ -13,7 +13,8 @@ async def api_key(client, logged_in_headers, active_user):
return response.json()
async def test_get_api_keys(client: AsyncClient, logged_in_headers, api_key):
@pytest.mark.usefixtures("api_key")
async def test_get_api_keys(client: AsyncClient, logged_in_headers):
response = await client.get("api/v1/api_key/", headers=logged_in_headers)
assert response.status_code == 200, response.text
data = response.json()
@ -34,7 +35,8 @@ async def test_create_api_key(client: AsyncClient, logged_in_headers):
assert "**" not in data["api_key"]
async def test_delete_api_key(client, logged_in_headers, active_user, api_key):
@pytest.mark.usefixtures("active_user")
async def test_delete_api_key(client, logged_in_headers, api_key):
api_key_id = api_key["id"]
response = await client.delete(f"api/v1/api_key/{api_key_id}", headers=logged_in_headers)
assert response.status_code == 200

View file

@ -12,7 +12,7 @@ def default_settings():
]
def test_components_path(runner, client, default_settings, tmp_path):
def test_components_path(runner, default_settings, tmp_path):
# create a "components" folder
temp_dir = tmp_path / "components"
@ -25,7 +25,8 @@ def test_components_path(runner, client, default_settings, tmp_path):
assert str(temp_dir) in settings_service.settings.components_path
def test_superuser(runner, client, session):
@pytest.mark.usefixtures("session")
def test_superuser(runner):
result = runner.invoke(app, ["superuser"], input="admin\nadmin\n")
assert result.exit_code == 0, result.stdout
assert "Superuser created successfully." in result.stdout

View file

@ -31,7 +31,8 @@ def json_style():
)
async def test_create_flow(client: TestClient, json_flow: str, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_create_flow(client: TestClient, json_flow: str, logged_in_headers):
flow = orjson.loads(json_flow)
data = flow["data"]
flow = FlowCreate(name=str(uuid4()), description="description", data=data)
@ -47,7 +48,8 @@ async def test_create_flow(client: TestClient, json_flow: str, active_user, logg
assert response.json()["data"] == flow.data
async def test_read_flows(client: TestClient, json_flow: str, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_read_flows(client: TestClient, json_flow: str, logged_in_headers):
flow_data = orjson.loads(json_flow)
data = flow_data["data"]
flow = FlowCreate(name=str(uuid4()), description="description", data=data)
@ -67,7 +69,8 @@ async def test_read_flows(client: TestClient, json_flow: str, active_user, logge
assert len(response.json()) > 0
async def test_read_flows_pagination(client: TestClient, json_flow: str, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_read_flows_pagination(client: TestClient, logged_in_headers):
response = await client.get("api/v1/flows/", headers=logged_in_headers)
assert response.status_code == 200
assert response.json()["page"] == 1
@ -77,7 +80,8 @@ async def test_read_flows_pagination(client: TestClient, json_flow: str, active_
assert len(response.json()["items"]) == 0
async def test_read_flows_pagination_with_params(client: TestClient, json_flow: str, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_read_flows_pagination_with_params(client: TestClient, logged_in_headers):
response = await client.get("api/v1/flows/", headers=logged_in_headers, params={"page": 3, "size": 10})
assert response.status_code == 200
assert response.json()["page"] == 3
@ -87,7 +91,8 @@ async def test_read_flows_pagination_with_params(client: TestClient, json_flow:
assert len(response.json()["items"]) == 0
async def test_read_flows_components_only(client: TestClient, flow_component: dict, logged_in_headers):
@pytest.mark.usefixtures("flow_component")
async def test_read_flows_components_only(client: TestClient, logged_in_headers):
response = await client.get(
"api/v1/flows/", headers=logged_in_headers, params={"components_only": True, "get_all": True}
)
@ -113,7 +118,8 @@ async def test_read_flow(client: TestClient, json_flow: str, logged_in_headers):
assert response.json()["data"] == flow.data
async def test_update_flow(client: TestClient, json_flow: str, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_update_flow(client: TestClient, json_flow: str, logged_in_headers):
flow = orjson.loads(json_flow)
data = flow["data"]
@ -134,7 +140,8 @@ async def test_update_flow(client: TestClient, json_flow: str, active_user, logg
# assert response.json()["data"] == updated_flow.data
async def test_delete_flow(client: TestClient, json_flow: str, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_delete_flow(client: TestClient, json_flow: str, logged_in_headers):
flow = orjson.loads(json_flow)
data = flow["data"]
flow = FlowCreate(name="Test Flow", description="description", data=data)
@ -145,7 +152,8 @@ async def test_delete_flow(client: TestClient, json_flow: str, active_user, logg
assert response.json()["message"] == "Flow deleted successfully"
async def test_delete_flows(client: TestClient, json_flow: str, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_delete_flows(client: TestClient, logged_in_headers):
# Create ten flows
number_of_flows = 10
flows = [FlowCreate(name=f"Flow {i}", description="description", data={}) for i in range(number_of_flows)]
@ -161,9 +169,8 @@ async def test_delete_flows(client: TestClient, json_flow: str, active_user, log
@pytest.mark.asyncio
async def test_delete_flows_with_transaction_and_build(
client: TestClient, json_flow: str, active_user, logged_in_headers
):
@pytest.mark.usefixtures("active_user")
async def test_delete_flows_with_transaction_and_build(client: TestClient, logged_in_headers):
# Create ten flows
number_of_flows = 10
flows = [FlowCreate(name=f"Flow {i}", description="description", data={}) for i in range(number_of_flows)]
@ -221,9 +228,8 @@ async def test_delete_flows_with_transaction_and_build(
@pytest.mark.asyncio
async def test_delete_folder_with_flows_with_transaction_and_build(
client: TestClient, json_flow: str, active_user, logged_in_headers
):
@pytest.mark.usefixtures("active_user")
async def test_delete_folder_with_flows_with_transaction_and_build(client: TestClient, logged_in_headers):
# Create a new folder
folder_name = f"Test Folder {uuid4()}"
folder = FolderCreate(name=folder_name, description="Test folder description", components_list=[], flows_list=[])
@ -335,7 +341,8 @@ async def test_get_flows_from_folder_pagination_with_params(client: TestClient,
assert len(response.json()["flows"]["items"]) == 0
async def test_create_flows(client: TestClient, session: Session, json_flow: str, logged_in_headers):
@pytest.mark.usefixtures("session")
async def test_create_flows(client: TestClient, json_flow: str, logged_in_headers):
flow = orjson.loads(json_flow)
data = flow["data"]
# Create test data
@ -362,7 +369,8 @@ async def test_create_flows(client: TestClient, session: Session, json_flow: str
assert response_data[1]["data"] == data
async def test_upload_file(client: TestClient, session: Session, json_flow: str, logged_in_headers):
@pytest.mark.usefixtures("session")
async def test_upload_file(client: TestClient, json_flow: str, logged_in_headers):
flow = orjson.loads(json_flow)
data = flow["data"]
# Create test data
@ -436,19 +444,22 @@ async def test_download_file(
assert "attachment; filename=" in response.headers["Content-Disposition"]
async def test_create_flow_with_invalid_data(client: TestClient, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_create_flow_with_invalid_data(client: TestClient, logged_in_headers):
flow = {"name": "a" * 256, "data": "Invalid flow data"}
response = await client.post("api/v1/flows/", json=flow, headers=logged_in_headers)
assert response.status_code == 422
async def test_get_nonexistent_flow(client: TestClient, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_get_nonexistent_flow(client: TestClient, logged_in_headers):
uuid = uuid4()
response = await client.get(f"api/v1/flows/{uuid}", headers=logged_in_headers)
assert response.status_code == 404
async def test_update_flow_idempotency(client: TestClient, json_flow: str, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_update_flow_idempotency(client: TestClient, json_flow: str, logged_in_headers):
flow_data = orjson.loads(json_flow)
data = flow_data["data"]
flow_data = FlowCreate(name="Test Flow", description="description", data=data)
@ -460,7 +471,8 @@ async def test_update_flow_idempotency(client: TestClient, json_flow: str, activ
assert response1.json() == response2.json()
async def test_update_nonexistent_flow(client: TestClient, json_flow: str, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_update_nonexistent_flow(client: TestClient, json_flow: str, logged_in_headers):
flow_data = orjson.loads(json_flow)
data = flow_data["data"]
uuid = uuid4()
@ -473,13 +485,15 @@ async def test_update_nonexistent_flow(client: TestClient, json_flow: str, activ
assert response.status_code == 404, response.text
async def test_delete_nonexistent_flow(client: TestClient, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_delete_nonexistent_flow(client: TestClient, logged_in_headers):
uuid = uuid4()
response = await client.delete(f"api/v1/flows/{uuid}", headers=logged_in_headers)
assert response.status_code == 404
async def test_read_only_starter_projects(client: TestClient, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_read_only_starter_projects(client: TestClient, logged_in_headers):
response = await client.get("api/v1/flows/basic_examples/", headers=logged_in_headers)
starter_projects = load_starter_projects()
assert response.status_code == 200
@ -487,7 +501,7 @@ async def test_read_only_starter_projects(client: TestClient, active_user, logge
@pytest.mark.load_flows
async def test_load_flows(client: TestClient, load_flows_dir):
async def test_load_flows(client: TestClient):
response = await client.get("api/v1/flows/c54f9130-f2fa-4a3e-b22a-3856d946351b")
assert response.status_code == 200
assert response.json()["name"] == "BasicExample"

View file

@ -59,7 +59,7 @@ async def files_client_fixture(session: Session, monkeypatch, request, load_flow
db_path.unlink()
async def test_upload_file(files_client, mock_storage_service, created_api_key, flow):
async def test_upload_file(files_client, created_api_key, flow):
headers = {"x-api-key": created_api_key.api_key}
response = await files_client.post(
@ -77,21 +77,21 @@ async def test_upload_file(files_client, mock_storage_service, created_api_key,
assert file_path_pattern.match(response_json["file_path"])
async def test_download_file(files_client, mock_storage_service, created_api_key, flow):
async def test_download_file(files_client, created_api_key, flow):
headers = {"x-api-key": created_api_key.api_key}
response = await files_client.get(f"api/v1/files/download/{flow.id}/test.txt", headers=headers)
assert response.status_code == 200
assert response.content == b"file content"
async def test_list_files(files_client, mock_storage_service, created_api_key, flow):
async def test_list_files(files_client, created_api_key, flow):
headers = {"x-api-key": created_api_key.api_key}
response = await files_client.get(f"api/v1/files/list/{flow.id}", headers=headers)
assert response.status_code == 200
assert response.json() == {"files": ["file1.txt", "file2.jpg"]}
async def test_delete_file(files_client, mock_storage_service, created_api_key, flow):
async def test_delete_file(files_client, created_api_key, flow):
headers = {"x-api-key": created_api_key.api_key}
response = await files_client.delete(f"api/v1/files/delete/{flow.id}/test.txt", headers=headers)

View file

@ -44,7 +44,7 @@ def test_template_field_defaults(sample_template_field: Input):
assert sample_template_field.password is None
def test_template_to_dict(sample_template: Template, sample_template_field: Input):
def test_template_to_dict(sample_template: Template):
template_dict = sample_template.to_dict()
assert template_dict["_type"] == "test_template"
assert len(template_dict) == 2 # _type and test_field

View file

@ -81,7 +81,8 @@ async def test_delete_messages_session(client: AsyncClient, created_messages, lo
# Successfully update session ID for all messages with the old session ID
async def test_successfully_update_session_id(client, session, logged_in_headers, created_messages):
@pytest.mark.usefixtures("session")
async def test_successfully_update_session_id(client, logged_in_headers, created_messages):
old_session_id = "session_id2"
new_session_id = "new_session_id"
@ -107,7 +108,8 @@ async def test_successfully_update_session_id(client, session, logged_in_headers
# No messages found with the given session ID
async def test_no_messages_found_with_given_session_id(client, session, logged_in_headers):
@pytest.mark.usefixtures("session")
async def test_no_messages_found_with_given_session_id(client, logged_in_headers):
old_session_id = "non_existent_session_id"
new_session_id = "new_session_id"

View file

@ -264,7 +264,7 @@ def test_tweak_not_in_template():
@pytest.mark.asyncio
async def test_load_langchain_object_with_cached_session(client, basic_graph_data):
async def test_load_langchain_object_with_cached_session(basic_graph_data):
# Provide a non-existent session_id
session_service = get_session_service()
session_id1 = "non-existent-session-id"

View file

@ -99,7 +99,8 @@ async def test_deactivated_user_cannot_login(client: AsyncClient, deactivated_us
assert response.json()["detail"] == "Inactive user", response.text
async def test_deactivated_user_cannot_access(client: AsyncClient, deactivated_user, logged_in_headers):
@pytest.mark.usefixtures("deactivated_user")
async def test_deactivated_user_cannot_access(client: AsyncClient, logged_in_headers):
# Assuming the headers for deactivated_user
response = await client.get("api/v1/users/", headers=logged_in_headers)
assert response.status_code == 403, response.status_code
@ -152,7 +153,7 @@ async def test_inactive_user(client: AsyncClient):
@pytest.mark.api_key_required
async def test_add_user(client: AsyncClient, test_user):
async def test_add_user(test_user):
assert test_user["username"] == "testuser"
@ -221,7 +222,8 @@ async def test_patch_reset_password(client: AsyncClient, active_user, logged_in_
@pytest.mark.api_key_required
async def test_patch_user_wrong_id(client: AsyncClient, active_user, logged_in_headers):
@pytest.mark.usefixtures("active_user")
async def test_patch_user_wrong_id(client: AsyncClient, logged_in_headers):
user_id = "wrong_id"
update_data = UserUpdate(
username="newname",
@ -245,7 +247,8 @@ async def test_delete_user(client: AsyncClient, test_user, super_user_headers):
@pytest.mark.api_key_required
async def test_delete_user_wrong_id(client: AsyncClient, test_user, super_user_headers):
@pytest.mark.usefixtures("test_user")
async def test_delete_user_wrong_id(client: AsyncClient, super_user_headers):
user_id = "wrong_id"
response = await client.delete(f"/api/v1/users/{user_id}", headers=super_user_headers)
assert response.status_code == 422