Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /pfun-health_pfun-cma-model /tests /test_app.py
| import pfun_path_helper as pph | |
| pph.append_path(path=pph.get_lib_path("pfun_cma_model")) # noqa: E402 | |
| from . import test_base | |
| test_base.setup_test_environment() | |
| import json | |
| from unittest.mock import MagicMock, patch | |
| import pandas as pd | |
| import pytest | |
| from fastapi import Request, status | |
| from fastapi.responses import Response | |
| from fastapi.testclient import TestClient | |
| from pfun_cma_model.app import app | |
| from pfun_cma_model.data import read_sample_data | |
| client = TestClient(app, base_url="http://localhost", client=("127.0.0.1", 50000)) | |
| def fake_request(): | |
| # Minimal mock for FastAPI Request | |
| return MagicMock(spec=Request) | |
| def sample_df(): | |
| return pd.DataFrame( | |
| [ | |
| {"a": 1, "b": 2}, | |
| {"a": 3, "b": 4}, | |
| {"a": 5, "b": 6}, | |
| ] | |
| ) | |
| def get_sample_dataset(fake_request, nrows=None): | |
| response = client.get("/data/sample/download", params={"nrows": nrows} if nrows is not None else {}) | |
| return response | |
| def test_get_sample_dataset_route_integration(mock_read_sample_data, sample_df): | |
| # Integration test using TestClient | |
| mock_read_sample_data.return_value = sample_df | |
| response = client.get("/data/sample/download?nrows=2&media_type=json") | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert isinstance(data, list) | |
| assert len(data) == 2 | |
| def test_get_sample_dataset_route_invalid_nrows(mock_read_sample_data, sample_df): | |
| mock_read_sample_data.return_value = sample_df | |
| response = client.get("/data/sample/download?nrows=-5") | |
| assert response.status_code == 400 | |
| assert "nrows" in response.text | |
Xet Storage Details
- Size:
- 1.78 kB
- Xet hash:
- 5f48c729cef7d506860f2d6dc0df635db4a56b418c0ea8cd2d1411de803ca408
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.