spb/company-atlas
Public
Python 66.3%
TypeScript 22.7%
JavaScript 8.6%
HTML 1.4%
CSS 0.7%
1"""Companies: list/filters/pagination, detail, sub-resources, compare, events feed and event detail."""2from __future__ import annotations34import pytest5import test_api_support as support67client = support.client8fixture_data = support.fixture_data910pytestmark = pytest.mark.asyncio(loop_scope="session")11V = "/api/v1"12CARD_KEYS = {"id", "slug", "display_name", "legal_name", "canonical_domain", "website", "description", "industries", "industry_primary", "country", "hq_city", "hq_region",13 "public_company", "ticker", "exchange", "founded_year", "employees_band", "logo_url", "status", "onboarding_status", "importance", "tier", "metrics", "counts",14 "last_event_at", "last_observed_at"}151617async def test_list_filters_sort_pagination(client, fixture_data): # type: ignore[no-untyped-def]18 r = await client.get(f"{V}/companies", params={"country": "ZZ", "per_page": 1, "page": 1, "sort": "activity", "sparkline": 1})19 body = r.json()20 assert r.status_code == 200 and set(body) == {"items", "page", "per_page", "total", "pages"}21 assert body["total"] == 2 and body["pages"] == 2 and len(body["items"]) == 122 card = body["items"][0]23 assert CARD_KEYS <= set(card) and card["slug"] == fixture_data["alpha_slug"]24 assert card["metrics"]["activity_score"] == 72.3 and card["metrics"]["open_jobs"] == 2 and card["metrics"]["hiring_momentum_30d"] == 12.525 assert card["counts"] == {"sensors": 2, "observations": 11, "changes": 1, "events": 3, "jobs_open": 2}26 assert len(card["sparkline"]) == 1027 page2 = (await client.get(f"{V}/companies", params={"country": "ZZ", "per_page": 1, "page": 2})).json()28 assert page2["items"][0]["slug"] == fixture_data["beta_slug"]29 hiring = (await client.get(f"{V}/companies", params={"country": "ZZ", "sort": "hiring"})).json()["items"]30 assert [c["slug"] for c in hiring] == [fixture_data["alpha_slug"], fixture_data["beta_slug"]]31 name = (await client.get(f"{V}/companies", params={"industry": fixture_data["industry"], "sort": "name"})).json()["items"]32 assert [c["slug"] for c in name] == [fixture_data["alpha_slug"], fixture_data["beta_slug"]]33 q = (await client.get(f"{V}/companies", params={"q": f"ztest beta {fixture_data['suffix']}"})).json()["items"]34 assert q and q[0]["slug"] == fixture_data["beta_slug"]35 assert (await client.get(f"{V}/companies", params={"country": "ZZ", "public": "true"})).json()["total"] == 036 assert (await client.get(f"{V}/companies", params={"country": "ZZ", "has_events": "1", "tier": 2})).json()["total"] == 237 assert (await client.get(f"{V}/companies", params={"per_page": 999})).status_code == 422383940async def test_detail_by_slug_and_id(client, fixture_data): # type: ignore[no-untyped-def]41 for key in (fixture_data["alpha_slug"], fixture_data["alpha"]):42 r = await client.get(f"{V}/companies/{key}")43 assert r.status_code == 200, key44 body = r.json()45 for k in ("aliases", "domains", "relationships", "metrics_detail", "sensors_by_surface", "coverage", "signals", "sparklines", "sparkline"):46 assert k in body, k47 assert body["aliases"] == [f"Alphaz {fixture_data['suffix']}"]48 assert body["relationships"][0]["kind"] == "PARTNER_OF" and body["relationships"][0]["company"]["slug"] == fixture_data["beta_slug"]49 assert body["sensors_by_surface"] == {"pricing": 1, "careers": 1}50 assert body["coverage"]["days_observed"] == 1 and body["coverage"]["sensor_uptime"] == 1.0 and body["coverage"]["historical_coverage"] is None51 assert len(body["sparklines"]["activity_30d"]) == 10 and body["sparklines"]["hiring_90d"] == []52 assert body["signals"][0]["kind"] == "hiring_surge"53 md = {m["metric"]: m for m in body["metrics_detail"]}54 assert md["activity_score"]["value"] == 72.3 and md["activity_score"]["formula_version"] == "metrics-v1" and md["activity_score"]["inputs"] == {"events": 3}55 r = await client.get(f"{V}/companies/does-not-exist")56 assert r.status_code == 404 and r.json() == {"detail": "company not found"}575859async def test_events_timeline_metrics(client, fixture_data): # type: ignore[no-untyped-def]60 s = fixture_data["alpha_slug"]61 r = await client.get(f"{V}/companies/{s}/events")62 body = r.json()63 assert r.status_code == 200 and body["total"] == 3 and [e["event_type"] for e in body["items"]] == ["PRICING", "HIRING", "PRODUCT"]64 imp = (await client.get(f"{V}/companies/{s}/events?sort=importance")).json()["items"]65 assert imp[0]["event_type"] == "PRICING"66 assert (await client.get(f"{V}/companies/{s}/events?event_type=HIRING")).json()["total"] == 167 assert (await client.get(f"{V}/companies/{s}/events?surface=careers")).json()["total"] == 168 assert (await client.get(f"{V}/companies/{s}/events?min_importance=0.75")).json()["total"] == 169 tl = (await client.get(f"{V}/companies/{s}/timeline?filter=pricing")).json()70 assert [e["event_type"] for e in tl["items"]] == ["PRICING"] and tl["items"][0]["day"] == tl["days"][0]["day"] and tl["days"][0]["count"] == 171 tl_all = (await client.get(f"{V}/companies/{s}/timeline")).json()72 assert len(tl_all["items"]) == 3 and sum(d["count"] for d in tl_all["days"]) == 373 m = (await client.get(f"{V}/companies/{s}/metrics?days=30")).json()74 assert {c["metric"] for c in m["current"]} >= {"activity_score", "open_jobs"} and len(m["series"]["activity_score"]) == 1075 assert set(m["series"]["activity_score"][0]) == {"day", "value", "confidence"}76 only = (await client.get(f"{V}/companies/{s}/metrics?metric=activity_score")).json()77 assert list(only["series"]) == ["activity_score"]787980async def test_jobs_people_products_pricing_locations_news(client, fixture_data): # type: ignore[no-untyped-def]81 s = fixture_data["alpha_slug"]82 r = await client.get(f"{V}/companies/{s}/jobs")83 body = r.json()84 assert r.status_code == 200 and body["total"] == 2 and body["meta"]["summary"]["open"] == 2 and body["meta"]["summary"]["ai_open"] == 185 assert body["meta"]["summary"]["remote_ratio"] == 0.5 and body["meta"]["summary"]["by_country"] == [{"country": "ZZ", "n": 2}]86 job = body["items"][0]87 assert {"id", "title", "department", "location_text", "city", "country", "remote", "employment_type", "seniority", "url", "posted_at", "first_seen_at", "last_seen_at",88 "removed_at", "status", "is_ai"} <= set(job)89 assert (await client.get(f"{V}/companies/{s}/jobs?status=removed")).json()["items"][0]["status"] == "no_longer_listed"90 assert (await client.get(f"{V}/companies/{s}/jobs?status=all")).json()["total"] == 391 assert (await client.get(f"{V}/companies/{s}/jobs?ai=1")).json()["items"][0]["title"] == "Senior ML Engineer"92 assert (await client.get(f"{V}/companies/{s}/jobs?q=account")).json()["total"] == 193 p = (await client.get(f"{V}/companies/{s}/people")).json()94 assert p["listed"][0]["name"] == "Jane Ztest" and p["no_longer_listed"][0]["name"] == "John Former"95 pr = (await client.get(f"{V}/companies/{s}/products")).json()96 assert pr["listed"][0]["name"] == "Ztest Widget" and pr["removed"] == []97 plans = (await client.get(f"{V}/companies/{s}/pricing")).json()98 assert plans["current"][0]["price"] == 12.0 and plans["current"][0]["features"] == ["1 seat"] and plans["history"][0]["price"] == 10.099 loc = (await client.get(f"{V}/companies/{s}/locations")).json()100 assert loc["countries"] == ["ZZ"] and loc["items"][0]["kind"] == "headquarters" and loc["items"][0]["lat"] == 45.5101 news = (await client.get(f"{V}/companies/{s}/news")).json()102 assert news["items"][0]["title"].startswith("Ztest Alpha announces")103104105async def test_sensors_history_similar(client, fixture_data): # type: ignore[no-untyped-def]106 s = fixture_data["alpha_slug"]107 sensors = (await client.get(f"{V}/companies/{s}/sensors")).json()["items"]108 assert {x["surface"] for x in sensors} == {"pricing", "careers"}109 assert {"id", "company_id", "surface", "connector_id", "url", "canonical_url", "domain", "status", "tier", "quality_score", "discovery_confidence", "discovery_method",110 "current_interval_s", "next_run_at", "last_run_at", "last_success_at", "last_change_at", "last_status", "last_failure_class", "consecutive_failures",111 "observation_count", "snapshot_count", "change_count", "meaningful_change_count", "event_count", "created_at"} <= set(sensors[0])112 hist = (await client.get(f"{V}/companies/{s}/history")).json()["sensors"]113 pricing = next(x for x in hist if x["surface"] == "pricing")114 assert [v["version_no"] for v in pricing["versions"]] == [3, 2, 1]115 assert (await client.get(f"{V}/companies/{s}/history?versions=1")).json()["sensors"][0]["versions"].__len__() <= 1116 similar = (await client.get(f"{V}/companies/{s}/similar")).json()["items"]117 assert [c["slug"] for c in similar] == [fixture_data["beta_slug"]]118119120async def test_compare(client, fixture_data): # type: ignore[no-untyped-def]121 a, b = fixture_data["alpha_slug"], fixture_data["beta_slug"]122 r = await client.get(f"{V}/companies/compare", params={"companies": f"{a},{b}"})123 body = r.json()124 assert r.status_code == 200125 assert [c["slug"] for c in body["companies"]] == [a, b]126 assert body["metrics"]["activity_score"] == {a: 72.3, b: 30.0}127 assert len(body["series"][a]) == 10 and body["series"][b] == []128 assert body["events_30d"][a] == {"PRICING": 1, "HIRING": 1, "PRODUCT": 1} and body["events_30d"][b] == {"LEADERSHIP": 1}129 assert body["jobs"][a] == {"open": 2, "ai_open": 1, "new_30d": 3} and body["jobs"][b] == {"open": 0, "ai_open": 0, "new_30d": 0}130 assert body["locations"] == {a: 1, b: 0}131 assert (await client.get(f"{V}/companies/compare", params={"companies": a})).status_code == 422132 assert (await client.get(f"{V}/companies/compare", params={"companies": f"{a},nope"})).status_code == 404133134135async def test_events_feed_types_summary_detail(client, fixture_data): # type: ignore[no-untyped-def]136 r = await client.get(f"{V}/events", params={"country": "ZZ"})137 body = r.json()138 assert r.status_code == 200 and body["total"] == 4139 assert (await client.get(f"{V}/events", params={"country": "ZZ", "status": "retracted"})).json()["total"] == 1140 assert (await client.get(f"{V}/events", params={"industry": fixture_data["industry"], "event_type": "LEADERSHIP"})).json()["items"][0]["company"]["slug"] == fixture_data["beta_slug"]141 assert (await client.get(f"{V}/events", params={"company": fixture_data["alpha_slug"], "min_confidence": 0.9})).json()["total"] == 1142 assert (await client.get(f"{V}/events", params={"q": "executive listed"})).json()["items"][0]["id"] == fixture_data["ev_leader"]143 assert (await client.get(f"{V}/events", params={"country": "ZZ", "origin": "llm"})).json()["total"] == 0144 assert (await client.get(f"{V}/events", params={"company": "nope"})).status_code == 404145 types = (await client.get(f"{V}/events/types")).json()["types"]146 pricing = next(t for t in types if t["event_type"] == "PRICING")147 assert pricing["count_30d"] >= 1 and any(s["event_subtype"] == "PRICE_INCREASE" and s["count_30d"] >= 1 for s in pricing["subtypes"])148 summ = (await client.get(f"{V}/events/summary?days=7&group=country")).json()["items"]149 zz = next(i for i in summ if i["key"] == "ZZ")150 assert zz["count"] == 4 and "delta_pct" in zz151 assert (await client.get(f"{V}/events/summary?group=nope")).status_code == 422152 r = await client.get(f"{V}/events/{fixture_data['ev_pricing']}")153 ev = r.json()154 assert r.status_code == 200 and ev["sources"][0]["source_url"].endswith("/pricing") and ev["change"]["id"] == fixture_data["change"]155 assert ev["company"]["slug"] == fixture_data["alpha_slug"] and CARD_KEYS <= set(ev["company"])156 assert (await client.get(f"{V}/events/evt_nope")).status_code == 404157