Spaces:
Configuration error
Configuration error
Download backend/tests/test_ner.py from Sivaneshakumar/sanjeevani-api: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/Sivaneshakumar/sanjeevani-api/resolve/main/backend/tests/test_ner.py
- Command line
-
hf download hf://spaces/Sivaneshakumar/sanjeevani-api/backend/tests/test_ner.py
-
curl -L -o test_ner.py https://huggingface.co/spaces/Sivaneshakumar/sanjeevani-api/resolve/main/backend/tests/test_ner.py
1.39 kB
| import pytest | |
| from httpx import AsyncClient | |
| async def test_ner_model_info(client: AsyncClient): | |
| response = await client.get("/api/v1/ner/model-info") | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert data["success"] is True | |
| assert data["data"]["name"] == "tner/roberta-large-bc5cdr" | |
| async def test_ner_analyze_endpoint(client: AsyncClient): | |
| payload = { | |
| "text": "The patient was prescribed metformin for type 2 diabetes mellitus." | |
| } | |
| response = await client.post("/api/v1/ner/analyze", json=payload) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert "request_id" in data | |
| assert data["model"]["name"] == "tner/roberta-large-bc5cdr" | |
| assert data["entity_count"] > 0 | |
| assert data["processing_time_ms"] >= 0 | |
| entity_texts = [e["text"].lower() for e in data["entities"]] | |
| labels = [e["label"] for e in data["entities"]] | |
| # Verify extracted entities | |
| assert any("metformin" in t for t in entity_texts) | |
| assert any("diabetes" in t for t in entity_texts) | |
| assert "CHEMICAL" in labels | |
| assert "DISEASE" in labels | |
| async def test_ner_empty_text_validation(client: AsyncClient): | |
| payload = {"text": ""} | |
| response = await client.post("/api/v1/ner/analyze", json=payload) | |
| assert response.status_code == 422 | |