test: add unit tests for routes (#4249)
This commit is contained in:
parent
a88fd9bbb0
commit
fadb20115d
23 changed files with 623 additions and 272 deletions
64
src/backend/tests/unit/api/v1/test_api_key.py
Normal file
64
src/backend/tests/unit/api/v1/test_api_key.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
from fastapi import status
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
async def test_create_folder(client: AsyncClient, logged_in_headers):
|
||||
response = await client.get("api/v1/api_key/", headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "api_keys" in result, "The dictionary must contain a key called 'api_keys'"
|
||||
assert "user_id" in result, "The dictionary must contain a key called 'user_id'"
|
||||
assert "total_count" in result, "The dictionary must contain a key called 'total_count'"
|
||||
|
||||
|
||||
async def test_create_api_key_route(client: AsyncClient, logged_in_headers, active_user):
|
||||
basic_case = {
|
||||
"name": "string",
|
||||
"total_uses": 0,
|
||||
"is_active": True,
|
||||
"api_key": "string",
|
||||
"user_id": str(active_user.id),
|
||||
}
|
||||
response = await client.post("api/v1/api_key/", json=basic_case, headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "api_key" in result, "The dictionary must contain a key called 'api_key'"
|
||||
assert "id" in result, "The dictionary must contain a key called 'id'"
|
||||
assert "is_active" in result, "The dictionary must contain a key called 'is_active'"
|
||||
assert "last_used_at" in result, "The dictionary must contain a key called 'last_used_at'"
|
||||
assert "name" in result, "The dictionary must contain a key called 'name'"
|
||||
assert "total_uses" in result, "The dictionary must contain a key called 'total_uses'"
|
||||
assert "user_id" in result, "The dictionary must contain a key called 'user_id'"
|
||||
|
||||
|
||||
async def test_delete_api_key_route(client: AsyncClient, logged_in_headers, active_user):
|
||||
basic_case = {
|
||||
"name": "string",
|
||||
"total_uses": 0,
|
||||
"is_active": True,
|
||||
"api_key": "string",
|
||||
"user_id": str(active_user.id),
|
||||
}
|
||||
_response = await client.post("api/v1/api_key/", json=basic_case, headers=logged_in_headers)
|
||||
_id = _response.json()["id"]
|
||||
|
||||
response = await client.delete(f"api/v1/api_key/{_id}", headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "detail" in result, "The dictionary must contain a key called 'detail'"
|
||||
|
||||
|
||||
async def test_save_store_api_key(client: AsyncClient, logged_in_headers):
|
||||
basic_case = {"api_key": "string"}
|
||||
response = await client.post("api/v1/api_key/store", json=basic_case, headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "detail" in result, "The dictionary must contain a key called 'detail'"
|
||||
36
src/backend/tests/unit/api/v1/test_endpoints.py
Normal file
36
src/backend/tests/unit/api/v1/test_endpoints.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
from fastapi import status
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
async def test_get_version(client: AsyncClient):
|
||||
response = await client.get("api/v1/version")
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "version" in result, "The dictionary must contain a key called 'version'"
|
||||
assert "main_version" in result, "The dictionary must contain a key called 'main_version'"
|
||||
assert "package" in result, "The dictionary must contain a key called 'package'"
|
||||
|
||||
|
||||
async def test_get_config(client: AsyncClient):
|
||||
response = await client.get("api/v1/config")
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "frontend_timeout" in result, "The dictionary must contain a key called 'frontend_timeout'"
|
||||
assert "auto_saving" in result, "The dictionary must contain a key called 'auto_saving'"
|
||||
assert "health_check_max_retries" in result, "The dictionary must contain a 'health_check_max_retries' key"
|
||||
assert "max_file_size_upload" in result, "The dictionary must contain a key called 'max_file_size_upload'"
|
||||
|
||||
|
||||
async def test_get_sidebar_components(client: AsyncClient):
|
||||
response = await client.get("api/v1/sidebar_categories")
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "categories" in result, "The dictionary must contain a key called 'categories'"
|
||||
assert len(result["categories"]) > 0, "The categories list must not be empty"
|
||||
assert isinstance(result["categories"], list), "The categories must be a list"
|
||||
172
src/backend/tests/unit/api/v1/test_flows.py
Normal file
172
src/backend/tests/unit/api/v1/test_flows.py
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
from fastapi import status
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
async def test_create_flow(client: AsyncClient, logged_in_headers):
|
||||
basic_case = {
|
||||
"name": "string",
|
||||
"description": "string",
|
||||
"icon": "string",
|
||||
"icon_bg_color": "#ff00ff",
|
||||
"gradient": "string",
|
||||
"data": {},
|
||||
"is_component": False,
|
||||
"webhook": False,
|
||||
"endpoint_name": "string",
|
||||
"tags": ["string"],
|
||||
"user_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
||||
"folder_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
||||
}
|
||||
response = await client.post("api/v1/flows/", json=basic_case, headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "data" in result, "The result must have a 'data' key"
|
||||
assert "description" in result, "The result must have a 'description' key"
|
||||
assert "endpoint_name" in result, "The result must have a 'endpoint_name' key"
|
||||
assert "folder_id" in result, "The result must have a 'folder_id' key"
|
||||
assert "gradient" in result, "The result must have a 'gradient' key"
|
||||
assert "icon" in result, "The result must have a 'icon' key"
|
||||
assert "icon_bg_color" in result, "The result must have a 'icon_bg_color' key"
|
||||
assert "id" in result, "The result must have a 'id' key"
|
||||
assert "is_component" in result, "The result must have a 'is_component' key"
|
||||
assert "name" in result, "The result must have a 'name' key"
|
||||
assert "tags" in result, "The result must have a 'tags' key"
|
||||
assert "updated_at" in result, "The result must have a 'updated_at' key"
|
||||
assert "user_id" in result, "The result must have a 'user_id' key"
|
||||
assert "webhook" in result, "The result must have a 'webhook' key"
|
||||
|
||||
|
||||
async def test_read_flows(client: AsyncClient, logged_in_headers):
|
||||
params = {
|
||||
"remove_example_flows": False,
|
||||
"components_only": False,
|
||||
"get_all": True,
|
||||
"header_flows": False,
|
||||
"page": 1,
|
||||
"size": 50,
|
||||
}
|
||||
response = await client.get("api/v1/flows/", params=params, headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, list), "The result must be a list"
|
||||
|
||||
|
||||
async def test_read_flow(client: AsyncClient, logged_in_headers):
|
||||
basic_case = {
|
||||
"name": "string",
|
||||
"description": "string",
|
||||
"icon": "string",
|
||||
"icon_bg_color": "#ff00ff",
|
||||
"gradient": "string",
|
||||
"data": {},
|
||||
"is_component": False,
|
||||
"webhook": False,
|
||||
"endpoint_name": "string",
|
||||
"tags": ["string"],
|
||||
"user_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
||||
"folder_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
||||
}
|
||||
_response = await client.post("api/v1/flows/", json=basic_case, headers=logged_in_headers)
|
||||
_id = _response.json()["id"]
|
||||
response = await client.get(f"api/v1/flows/{_id}", headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "data" in result, "The result must have a 'data' key"
|
||||
assert "description" in result, "The result must have a 'description' key"
|
||||
assert "endpoint_name" in result, "The result must have a 'endpoint_name' key"
|
||||
assert "folder_id" in result, "The result must have a 'folder_id' key"
|
||||
assert "gradient" in result, "The result must have a 'gradient' key"
|
||||
assert "icon" in result, "The result must have a 'icon' key"
|
||||
assert "icon_bg_color" in result, "The result must have a 'icon_bg_color' key"
|
||||
assert "id" in result, "The result must have a 'id' key"
|
||||
assert "is_component" in result, "The result must have a 'is_component' key"
|
||||
assert "name" in result, "The result must have a 'name' key"
|
||||
assert "tags" in result, "The result must have a 'tags' key"
|
||||
assert "updated_at" in result, "The result must have a 'updated_at' key"
|
||||
assert "user_id" in result, "The result must have a 'user_id' key"
|
||||
assert "webhook" in result, "The result must have a 'webhook' key"
|
||||
|
||||
|
||||
async def test_update_flow(client: AsyncClient, logged_in_headers):
|
||||
name = "first_name"
|
||||
updated_name = "second_name"
|
||||
basic_case = {
|
||||
"description": "string",
|
||||
"icon": "string",
|
||||
"icon_bg_color": "#ff00ff",
|
||||
"gradient": "string",
|
||||
"data": {},
|
||||
"is_component": False,
|
||||
"webhook": False,
|
||||
"endpoint_name": "string",
|
||||
"tags": ["string"],
|
||||
"user_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
||||
"folder_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
||||
}
|
||||
basic_case["name"] = name
|
||||
_response = await client.post("api/v1/flows/", json=basic_case, headers=logged_in_headers)
|
||||
_id = _response.json()["id"]
|
||||
|
||||
basic_case["name"] = updated_name
|
||||
response = await client.patch(f"api/v1/flows/{_id}", json=basic_case, headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "data" in result, "The result must have a 'data' key"
|
||||
assert "description" in result, "The result must have a 'description' key"
|
||||
assert "endpoint_name" in result, "The result must have a 'endpoint_name' key"
|
||||
assert "folder_id" in result, "The result must have a 'folder_id' key"
|
||||
assert "gradient" in result, "The result must have a 'gradient' key"
|
||||
assert "icon" in result, "The result must have a 'icon' key"
|
||||
assert "icon_bg_color" in result, "The result must have a 'icon_bg_color' key"
|
||||
assert "id" in result, "The result must have a 'id' key"
|
||||
assert "is_component" in result, "The result must have a 'is_component' key"
|
||||
assert "name" in result, "The result must have a 'name' key"
|
||||
assert "tags" in result, "The result must have a 'tags' key"
|
||||
assert "updated_at" in result, "The result must have a 'updated_at' key"
|
||||
assert "user_id" in result, "The result must have a 'user_id' key"
|
||||
assert "webhook" in result, "The result must have a 'webhook' key"
|
||||
assert result["name"] == updated_name, "The name must be updated"
|
||||
|
||||
|
||||
async def test_create_flows(client: AsyncClient, logged_in_headers):
|
||||
amount_flows = 10
|
||||
basic_case = {
|
||||
"description": "string",
|
||||
"icon": "string",
|
||||
"icon_bg_color": "#ff00ff",
|
||||
"gradient": "string",
|
||||
"data": {},
|
||||
"is_component": False,
|
||||
"webhook": False,
|
||||
"tags": ["string"],
|
||||
"user_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
||||
"folder_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
||||
}
|
||||
cases = []
|
||||
for i in range(amount_flows):
|
||||
case = basic_case.copy()
|
||||
case["name"] = f"string_{i}"
|
||||
case["endpoint_name"] = f"string_{i}"
|
||||
cases.append(case)
|
||||
|
||||
response = await client.post("api/v1/flows/batch/", json={"flows": cases}, headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
assert isinstance(result, list), "The result must be a list"
|
||||
assert len(result) == amount_flows, "The result must have the same amount of flows"
|
||||
|
||||
|
||||
async def test_read_basic_examples(client: AsyncClient, logged_in_headers):
|
||||
response = await client.get("api/v1/flows/basic_examples/", headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, list), "The result must be a list"
|
||||
assert len(result) > 0, "The result must have at least one flow"
|
||||
64
src/backend/tests/unit/api/v1/test_folders.py
Normal file
64
src/backend/tests/unit/api/v1/test_folders.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import pytest
|
||||
from fastapi import status
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def basic_case():
|
||||
return {
|
||||
"name": "New Folder",
|
||||
"description": "",
|
||||
"flows_list": [],
|
||||
"components_list": [],
|
||||
}
|
||||
|
||||
|
||||
async def test_create_folder(client: AsyncClient, logged_in_headers, basic_case):
|
||||
response = await client.post("api/v1/folders/", json=basic_case, headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "name" in result, "The dictionary must contain a key called 'name'"
|
||||
assert "description" in result, "The dictionary must contain a key called 'description'"
|
||||
assert "id" in result, "The dictionary must contain a key called 'id'"
|
||||
assert "parent_id" in result, "The dictionary must contain a key called 'parent_id'"
|
||||
|
||||
|
||||
async def test_read_folders(client: AsyncClient, logged_in_headers):
|
||||
response = await client.get("api/v1/folders/", headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, list), "The result must be a list"
|
||||
assert len(result) > 0, "The list must not be empty"
|
||||
|
||||
|
||||
async def test_read_folder(client: AsyncClient, logged_in_headers, basic_case):
|
||||
_response = await client.post("api/v1/folders/", json=basic_case, headers=logged_in_headers)
|
||||
_id = _response.json()["id"]
|
||||
response = await client.get(f"api/v1/folders/{_id}", headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "name" in result, "The dictionary must contain a key called 'name'"
|
||||
assert "description" in result, "The dictionary must contain a key called 'description'"
|
||||
assert "id" in result, "The dictionary must contain a key called 'id'"
|
||||
assert "parent_id" in result, "The dictionary must contain a key called 'parent_id'"
|
||||
|
||||
|
||||
async def test_update_folder(client: AsyncClient, logged_in_headers, basic_case):
|
||||
update_case = basic_case.copy()
|
||||
update_case["name"] = "Updated Folder"
|
||||
_response = await client.post("api/v1/folders/", json=basic_case, headers=logged_in_headers)
|
||||
_id = _response.json()["id"]
|
||||
response = await client.patch(f"api/v1/folders/{_id}", json=update_case, headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "name" in result, "The dictionary must contain a key called 'name'"
|
||||
assert "description" in result, "The dictionary must contain a key called 'description'"
|
||||
assert "id" in result, "The dictionary must contain a key called 'id'"
|
||||
assert "parent_id" in result, "The dictionary must contain a key called 'parent_id'"
|
||||
10
src/backend/tests/unit/api/v1/test_starter_projects.py
Normal file
10
src/backend/tests/unit/api/v1/test_starter_projects.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
from fastapi import status
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
async def test_get_starter_projects(client: AsyncClient, logged_in_headers):
|
||||
response = await client.get("api/v1/starter-projects/", headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, list), "The result must be a list"
|
||||
12
src/backend/tests/unit/api/v1/test_store.py
Normal file
12
src/backend/tests/unit/api/v1/test_store.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from fastapi import status
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
async def test_check_if_store_is_enabled(client: AsyncClient):
|
||||
response = await client.get("api/v1/store/check/")
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The variable must be a dictionary"
|
||||
assert "enabled" in result, "The dictionary must contain a key called 'enabled'"
|
||||
assert isinstance(result["enabled"], bool), "There must be a boolean value for the key 'enabled' in the dictionary"
|
||||
98
src/backend/tests/unit/api/v1/test_users.py
Normal file
98
src/backend/tests/unit/api/v1/test_users.py
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
from fastapi import status
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
async def test_add_user(client: AsyncClient):
|
||||
basic_case = {"username": "string", "password": "string"}
|
||||
response = await client.post("api/v1/users/", json=basic_case)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "id" in result, "The result must have an 'id' key"
|
||||
assert "is_active" in result, "The result must have an 'is_active' key"
|
||||
assert "is_superuser" in result, "The result must have an 'is_superuser' key"
|
||||
assert "last_login_at" in result, "The result must have an 'last_login_at' key"
|
||||
assert "profile_image" in result, "The result must have an 'profile_image' key"
|
||||
assert "store_api_key" in result, "The result must have an 'store_api_key' key"
|
||||
assert "updated_at" in result, "The result must have an 'updated_at' key"
|
||||
assert "username" in result, "The result must have an 'username' key"
|
||||
|
||||
|
||||
async def test_read_current_user(client: AsyncClient, logged_in_headers):
|
||||
response = await client.get("api/v1/users/whoami", headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "id" in result, "The result must have an 'id' key"
|
||||
assert "is_active" in result, "The result must have an 'is_active' key"
|
||||
assert "is_superuser" in result, "The result must have an 'is_superuser' key"
|
||||
assert "last_login_at" in result, "The result must have an 'last_login_at' key"
|
||||
assert "profile_image" in result, "The result must have an 'profile_image' key"
|
||||
assert "store_api_key" in result, "The result must have an 'store_api_key' key"
|
||||
assert "updated_at" in result, "The result must have an 'updated_at' key"
|
||||
assert "username" in result, "The result must have an 'username' key"
|
||||
|
||||
|
||||
async def test_read_all_users(client: AsyncClient, logged_in_headers_super_user):
|
||||
response = await client.get("api/v1/users/", headers=logged_in_headers_super_user)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "total_count" in result, "The result must have an 'total_count' key"
|
||||
assert "users" in result, "The result must have an 'users' key"
|
||||
|
||||
|
||||
async def test_patch_user(client: AsyncClient, logged_in_headers_super_user):
|
||||
name = "string"
|
||||
updated_name = "string2"
|
||||
basic_case = {"username": name, "password": "string"}
|
||||
_response = await client.post("api/v1/users/", json=basic_case)
|
||||
_id = _response.json()["id"]
|
||||
basic_case["username"] = updated_name
|
||||
response = await client.patch(f"api/v1/users/{_id}", json=basic_case, headers=logged_in_headers_super_user)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "id" in result, "The result must have an 'id' key"
|
||||
assert "is_active" in result, "The result must have an 'is_active' key"
|
||||
assert "is_superuser" in result, "The result must have an 'is_superuser' key"
|
||||
assert "last_login_at" in result, "The result must have an 'last_login_at' key"
|
||||
assert "profile_image" in result, "The result must have an 'profile_image' key"
|
||||
assert "store_api_key" in result, "The result must have an 'store_api_key' key"
|
||||
assert "updated_at" in result, "The result must have an 'updated_at' key"
|
||||
assert "username" in result, "The result must have an 'username' key"
|
||||
assert result["username"] == updated_name, "The username must be updated"
|
||||
|
||||
|
||||
async def test_reset_password(client: AsyncClient, logged_in_headers, active_user):
|
||||
_id = str(active_user.id)
|
||||
basic_case = {"username": "string", "password": "new_password"}
|
||||
response = await client.patch(f"api/v1/users/{_id}/reset-password", json=basic_case, headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "id" in result, "The result must have an 'id' key"
|
||||
assert "is_active" in result, "The result must have an 'is_active' key"
|
||||
assert "is_superuser" in result, "The result must have an 'is_superuser' key"
|
||||
assert "last_login_at" in result, "The result must have an 'last_login_at' key"
|
||||
assert "profile_image" in result, "The result must have an 'profile_image' key"
|
||||
assert "store_api_key" in result, "The result must have an 'store_api_key' key"
|
||||
assert "updated_at" in result, "The result must have an 'updated_at' key"
|
||||
assert "username" in result, "The result must have an 'username' key"
|
||||
|
||||
|
||||
async def test_delete_user(client: AsyncClient, logged_in_headers_super_user):
|
||||
basic_case = {"username": "string", "password": "string"}
|
||||
_response = await client.post("api/v1/users/", json=basic_case)
|
||||
_id = _response.json()["id"]
|
||||
response = await client.delete(f"api/v1/users/{_id}", headers=logged_in_headers_super_user)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "detail" in result, "The result must have an 'detail' key"
|
||||
56
src/backend/tests/unit/api/v1/test_validate.py
Normal file
56
src/backend/tests/unit/api/v1/test_validate.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
from fastapi import status
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
async def test_post_validate_code(client: AsyncClient):
|
||||
good_code = """
|
||||
from pprint import pprint
|
||||
var = {"a": 1, "b": 2}
|
||||
pprint(var)
|
||||
"""
|
||||
response = await client.post("api/v1/validate/code", json={"code": good_code})
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "imports" in result, "The result must have an 'imports' key"
|
||||
assert "function" in result, "The result must have a 'function' key"
|
||||
|
||||
|
||||
async def test_post_validate_prompt(client: AsyncClient):
|
||||
basic_case = {
|
||||
"name": "string",
|
||||
"template": "string",
|
||||
"custom_fields": {},
|
||||
"frontend_node": {
|
||||
"template": {},
|
||||
"description": "string",
|
||||
"icon": "string",
|
||||
"is_input": True,
|
||||
"is_output": True,
|
||||
"is_composition": True,
|
||||
"base_classes": ["string"],
|
||||
"name": "",
|
||||
"display_name": "",
|
||||
"documentation": "",
|
||||
"custom_fields": {},
|
||||
"output_types": [],
|
||||
"full_path": "string",
|
||||
"pinned": False,
|
||||
"conditional_paths": [],
|
||||
"frozen": False,
|
||||
"outputs": [],
|
||||
"field_order": [],
|
||||
"beta": False,
|
||||
"error": "string",
|
||||
"edited": False,
|
||||
"metadata": {},
|
||||
},
|
||||
}
|
||||
response = await client.post("api/v1/validate/prompt", json=basic_case)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert isinstance(result, dict), "The result must be a dictionary"
|
||||
assert "frontend_node" in result, "The result must have a 'frontend_node' key"
|
||||
assert "input_variables" in result, "The result must have an 'input_variables' key"
|
||||
Loading…
Add table
Add a link
Reference in a new issue