Skip to content

Commit

Permalink
ref: Fix unused args in tests (langflow-ai#4156)
Browse files Browse the repository at this point in the history
Fix unused args in tests
  • Loading branch information
cbornet authored and diogocabral committed Nov 26, 2024
1 parent 152b3d8 commit 5de710a
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 63 deletions.
48 changes: 28 additions & 20 deletions src/backend/tests/unit/api/v1/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand All @@ -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"] = ""

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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"

Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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")
Expand All @@ -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)

Expand All @@ -171,15 +177,17 @@ 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)

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)
Expand Down
3 changes: 2 additions & 1 deletion src/backend/tests/unit/base/tools/test_component_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/backend/tests/unit/graph/edge/test_edge_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/tests/unit/graph/graph/test_callback_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def call_log_method(self) -> Message:
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())
Expand Down
6 changes: 4 additions & 2 deletions src/backend/tests/unit/test_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/backend/tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Loading

0 comments on commit 5de710a

Please sign in to comment.