Spaces:
Paused

meloon / tests /test_dashboards.py
isold's picture
Feature: Add new applications
4a91ea9
Raw History Blame Contribute Delete
1.51 kB
from fastapi.testclient import TestClient
def test_create_dashboard(client: TestClient, normal_user_token_headers):
response = client.post(
"/api/v1/dashboards/",
headers=normal_user_token_headers,
json={"title": "My Dashboard", "description": "Sales stats"},
)
assert response.status_code == 201
assert response.json()["title"] == "My Dashboard"
return response.json()["id"]
def test_add_dashboard_item(client: TestClient, normal_user_token_headers):
# Setup dashboard
dashboard_id = test_create_dashboard(client, normal_user_token_headers)
# Setup Data Source
client.post(
"/api/v1/datasources/",
headers=normal_user_token_headers,
json={
"name": "Test DB",
"type": "mysql",
"host": "localhost",
"port": 3306,
"username": "root",
"password": "password",
"database_name": "test_db"
},
)
ds_id = client.get("/api/v1/datasources/", headers=normal_user_token_headers).json()[-1]["id"]
response = client.post(
f"/api/v1/dashboards/{dashboard_id}/items",
headers=normal_user_token_headers,
json={
"data_source_id": ds_id,
"sql_query": "SELECT * FROM sales",
"chart_type": "bar",
"chart_config": {"x": "date", "y": "amount"}
},
)
assert response.status_code == 201
assert response.json()["dashboard_id"] == dashboard_id