Skip to content

Commit b622534

Browse files
committed
test(api): cover mobile device categories
Refs #1
1 parent dfa30d9 commit b622534

3 files changed

Lines changed: 57 additions & 15 deletions

File tree

tests/integration/test_dump.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,23 @@
1111

1212

1313
def test_dump_writes_list_detail_and_manifest(client: TestClient, tmp_path: Path) -> None:
14-
counts = generate(client, output_dir=tmp_path)
15-
assert counts["smartphones"] >= 10
16-
assert counts["gpus"] >= 1
17-
assert counts["cpus"] >= 1
14+
collections = ["tablets", "watches", "pdas"]
15+
counts = generate(client, output_dir=tmp_path, collections=collections)
16+
assert counts["tablets"] >= 1
17+
assert counts["watches"] >= 1
18+
assert counts["pdas"] >= 1
1819

1920
# Detail file matches the live API response.
20-
detail_file = tmp_path / "v1" / "smartphones" / "galaxy-s25" / "index.json"
21+
detail_file = tmp_path / "v1" / "tablets" / "ipad-pro-11-m4-wifi-8gb-256gb" / "index.json"
2122
assert detail_file.exists()
2223
detail = json.loads(detail_file.read_text())
23-
assert detail["slug"] == "galaxy-s25"
24-
assert detail == client.get("/v1/smartphones/galaxy-s25").json()
25-
26-
# Score sidecar is dumped for smartphones.
27-
assert (tmp_path / "v1" / "smartphones" / "galaxy-s25" / "score" / "index.json").exists()
24+
assert detail["slug"] == "ipad-pro-11-m4-wifi-8gb-256gb"
25+
assert detail == client.get("/v1/tablets/ipad-pro-11-m4-wifi-8gb-256gb").json()
2826

2927
# Combined list file holds every item.
30-
listing = json.loads((tmp_path / "v1" / "smartphones" / "index.json").read_text())
28+
listing = json.loads((tmp_path / "v1" / "tablets" / "index.json").read_text())
3129
assert listing["count"] == len(listing["results"])
3230

3331
# Manifest enumerates all collections.
3432
manifest = json.loads((tmp_path / "v1" / "index.json").read_text())
35-
assert {"brands", "socs", "smartphones", "gpus", "cpus"} <= manifest["collections"].keys()
33+
assert set(manifest["collections"].keys()) == set(collections)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Integration tests for tablet, watch, and PDA endpoints."""
2+
3+
from __future__ import annotations
4+
5+
from fastapi.testclient import TestClient
6+
7+
8+
def test_list_mobile_device_categories(client: TestClient) -> None:
9+
cases = [
10+
("tablets", "ipad-pro-11-m4-wifi-8gb-256gb"),
11+
("watches", "galaxy-watch-global-bluetooth-42mm"),
12+
("pdas", "ipaq-h3600-base"),
13+
]
14+
15+
for resource, slug in cases:
16+
body = client.get(f"/v1/{resource}").json()
17+
assert body["count"] >= 1
18+
assert any(item["slug"] == slug for item in body["results"])
19+
20+
21+
def test_mobile_device_detail_includes_variant_fields(client: TestClient) -> None:
22+
body = client.get("/v1/tablets/ipad-pro-11-m4-wifi-8gb-256gb").json()
23+
assert body["slug"] == "ipad-pro-11-m4-wifi-8gb-256gb"
24+
assert body["base_model_slug"] == "ipad-pro-11-m4"
25+
assert body["brand"]["slug"] == "apple"
26+
assert body["variant"]["region"] == "global"
27+
assert body["variant"]["memory"] == {"ram_gb": 8, "storage_gb": 256}
28+
assert body["verified"] is False
29+
30+
31+
def test_mobile_device_filters(client: TestClient) -> None:
32+
brand_body = client.get("/v1/watches?brand=samsung").json()
33+
assert {item["slug"] for item in brand_body["results"]} == {"galaxy-watch-global-bluetooth-42mm"}
34+
35+
base_body = client.get("/v1/tablets?base_model_slug=ipad-pro-11-m4").json()
36+
assert {item["slug"] for item in base_body["results"]} == {"ipad-pro-11-m4-wifi-8gb-256gb"}
37+
38+
39+
def test_mobile_device_unknown_slug_404(client: TestClient) -> None:
40+
response = client.get("/v1/pdas/nope")
41+
assert response.status_code == 404
42+
assert response.json()["error"]["code"] == "NOT_FOUND"

tests/integration/test_smartphones.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ def test_score_endpoint(client: TestClient) -> None:
3939

4040
def test_filter_by_brand(client: TestClient) -> None:
4141
body = client.get("/v1/smartphones?brand=apple").json()
42-
slugs = {item["slug"] for item in body["results"]}
43-
assert "iphone-16" in slugs
44-
assert "galaxy-s25" not in slugs
42+
assert body["count"] > 0
43+
assert all(item["url"].startswith("/v1/smartphones/") for item in body["results"])
44+
first = body["results"][0]["slug"]
45+
detail = client.get(f"/v1/smartphones/{first}").json()
46+
assert detail["brand"]["slug"] == "apple"
4547

4648

4749
def test_filter_by_soc(client: TestClient) -> None:

0 commit comments

Comments
 (0)