Download tests/test_dashboards.py from isold/meloon: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/spaces/isold/meloon/resolve/main/tests/test_dashboards.py
- Command line
-
hf download hf://spaces/isold/meloon/tests/test_dashboards.py
-
curl -L -o test_dashboards.py https://huggingface.co/spaces/isold/meloon/resolve/main/tests/test_dashboards.py
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 | |