Spaces:
Sleeping
Sleeping
File size: 1,871 Bytes
896a559 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | """
Basic tests for the extraction pipeline and API.
Run with: pytest tests/ -v (from repo root, with src/ on PYTHONPATH)
"""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from fastapi.testclient import TestClient
from api import app
from rules_extractor import extract_attributes_rules
client = TestClient(app)
def test_health():
r = client.get("/health")
assert r.status_code == 200
assert r.json()["status"] == "ok"
def test_extract_basic():
r = client.post("/extract", json={
"text": "Lace mermaid wedding dress with long sleeves and scalloped hem"
})
assert r.status_code == 200
body = r.json()
attrs = body["attributes"]
assert "mermaid" in attrs["silhouette"]
assert "lace" in attrs["fabric"]
assert "long sleeves" in attrs["sleeve"]
assert "wedding dress" in attrs["category"]
def test_extract_empty_text_rejected():
r = client.post("/extract", json={"text": ""})
assert r.status_code == 422
def test_extract_invalid_mode():
r = client.post("/extract", json={"text": "a dress", "mode": "bogus"})
assert r.status_code == 400
def test_extract_multi_color():
r = client.post("/extract", json={
"text": "Floor length chiffon bridesmaid dress with pleated bodice and V neckline available in sage and dusty blue"
})
attrs = r.json()["attributes"]
assert set(["sage", "dusty blue"]).issubset(set(attrs["color"]))
assert attrs["length"] == ["floor length"]
def test_rules_extractor_directly():
result = extract_attributes_rules(
"Velvet winter formal dress with square neckline and puff sleeves"
)
assert result["fabric"] == ["velvet"]
assert result["neckline"] == ["square neckline"]
assert result["sleeve"] == ["puff sleeves"]
assert result["category"] == ["formal dress"]
|