spb/company-atlas
Public
Python 66.3%
TypeScript 22.7%
JavaScript 8.6%
HTML 1.4%
CSS 0.7%
1"""API surface of the profile enrichment (docs/API.md "Profile & facts"): `CompanyCard.profile`, detail `facts`, relationship provenance,2people `source`. Uses the shared API fixture family and writes a profile into the alpha company's `source_meta`."""3from __future__ import annotations45import pytest6import test_api_support as support78from companyatlas.db import execute, jsonb, transaction910client = support.client11fixture_data = support.fixture_data1213pytestmark = pytest.mark.asyncio(loop_scope="session")14V = "/api/v1"15PROFILE = {16 "description": "Ztest Alpha is a synthetic company used by the API tests. " * 4, "description_source": "wikipedia",17 "description_url": "https://en.wikipedia.org/wiki/Ztest_Alpha", "description_license": "CC BY-SA 4.0", "description_attribution": "Text from Wikipedia (en), CC BY-SA 4.0",18 "logo_url": "https://commons.wikimedia.org/wiki/Special:FilePath/Ztest.svg", "icon_url": None, "founded_year": 1999, "legal_form": "corporation", "legal_name": "Ztest Alpha Inc.",19 "employees": 47756, "employees_year": 2013, "revenue": {"value": 305630000000, "currency": "USD", "year": 2023}, "net_income": None, "total_assets": None,20 "hq": {"city": "Testville", "region": "Test Region", "country": "ZZ", "address": None, "lat": None, "lon": None},21 "ticker": "ZTA", "exchange": "Nasdaq", "isin": None, "lei": "7ZW8QJWVPR4P1J1KQY45", "sec_cik": None, "public_company": True,22 "wikipedia_url": "https://en.wikipedia.org/wiki/Ztest_Alpha", "wikidata_url": "https://www.wikidata.org/wiki/Q95", "official_website": "https://ztest.example/", "phone": None,23 "products": ["Ztest Search"], "industries": [], "industry_labels": ["software industry"], "socials": {"linkedin": "https://www.linkedin.com/company/ztest"},24 "enriched_at": "2026-09-13T00:00:00+00:00", "version": "profile-v1",25 "sources": [{"field": "description", "source": "wikipedia", "url": "https://en.wikipedia.org/wiki/Ztest_Alpha", "retrieved_at": "2026-09-13T00:00:00+00:00"},26 {"field": "employees", "source": "wikidata", "url": "https://www.wikidata.org/wiki/Q95", "retrieved_at": "2026-09-13T00:00:00+00:00"},27 {"field": "founded_year", "source": "wikidata", "url": "https://www.wikidata.org/wiki/Q95", "retrieved_at": "2026-09-13T00:00:00+00:00"},28 {"field": "hq_city", "source": "wikidata", "url": "https://www.wikidata.org/wiki/Q95", "retrieved_at": "2026-09-13T00:00:00+00:00"},29 {"field": "ticker", "source": "wikidata", "url": "https://www.wikidata.org/wiki/Q95", "retrieved_at": "2026-09-13T00:00:00+00:00"},30 {"field": "revenue", "source": "wikidata", "url": "https://www.wikidata.org/wiki/Q95", "retrieved_at": "2026-09-13T00:00:00+00:00"}],31}323334async def test_profile_facts_relationships_people(client, fixture_data): # type: ignore[no-untyped-def]35 alpha, beta = fixture_data["alpha"], fixture_data["beta"]36 async with transaction() as conn:37 await execute(conn, "update companies set source_meta = source_meta || cast(:p as jsonb) where id = :id", p=jsonb({"profile": PROFILE}), id=alpha)38 await execute(conn, """insert into company_relationships (id, from_company_id, to_company_id, kind, valid_from, confidence, source_url, provenance)39 values (:id, :a, :b, 'SUBSIDIARY_OF', '2015-10-02', 0.85, 'https://www.wikidata.org/wiki/Q95', cast(:prov as jsonb))""",40 id=f"rel_ztestapi{fixture_data['suffix']}p", a=alpha, b=beta, prov=jsonb({"source": "wikidata", "property": "P749", "qid": "Q20800404"}))41 await execute(conn, """insert into people (id, company_id, name, name_norm, title, role_category, is_executive, status, source_url)42 values (:id, :c, 'Ztest Chief', :nn, 'Chief Executive Officer', 'ceo', true, 'listed', 'https://www.wikidata.org/wiki/Q95')""",43 id=f"person_ztestapi{fixture_data['suffix']}w", c=alpha, nn=f"ztestchief{fixture_data['suffix']}")44 support.cache.clear()45 # card in a list46 items = (await client.get(f"{V}/companies", params={"country": "ZZ", "sort": "name"})).json()["items"]47 cards = {c["slug"]: c for c in items}48 assert cards[fixture_data["alpha_slug"]]["profile"]["employees"] == 47756 and cards[fixture_data["alpha_slug"]]["profile"]["description_license"] == "CC BY-SA 4.0"49 assert "profile" not in cards[fixture_data["beta_slug"]] # never enriched → absent, not null-filled50 # detail: profile, facts, relationships with provenance51 body = (await client.get(f"{V}/companies/{fixture_data['alpha_slug']}")).json()52 assert body["profile"]["version"] == "profile-v1"53 facts = {f["key"]: f for f in body["facts"]}54 assert set(facts) == {"founded", "headquarters", "employees", "revenue", "legal_form", "listing", "lei", "website", "wikipedia"}55 assert facts["employees"] == {"key": "employees", "label": "Employees", "value": "47,756 (2013)", "raw": 47756, "source": "wikidata",56 "url": "https://www.wikidata.org/wiki/Q95", "retrieved_at": "2026-09-13T00:00:00+00:00"}57 assert facts["revenue"]["value"] == "USD 305.6 B (2023)" and facts["headquarters"]["value"] == "Testville, Test Region, ZZ"58 assert facts["listing"]["value"] == "ZTA · Nasdaq" and facts["listing"]["source"] == "wikidata" and facts["legal_form"]["source"] is None59 rel = {r["kind"]: r for r in body["relationships"]}60 assert rel["SUBSIDIARY_OF"]["company"]["slug"] == fixture_data["beta_slug"] and rel["SUBSIDIARY_OF"]["provenance"] == {"source": "wikidata", "property": "P749", "qid": "Q20800404"}61 assert rel["SUBSIDIARY_OF"]["valid_from"] == "2015-10-02" and rel["SUBSIDIARY_OF"]["confidence"] == 0.85 and "first_seen_at" in rel["SUBSIDIARY_OF"]62 assert rel["PARTNER_OF"]["provenance"] == {}63 # people carry their source64 people = (await client.get(f"{V}/companies/{fixture_data['alpha_slug']}/people")).json()65 by_name = {p["name"]: p for p in people["listed"]}66 assert by_name["Ztest Chief"]["source"] == "wikidata" and by_name["Ztest Chief"]["title"] == "Chief Executive Officer"67 assert all(p["source"] in ("wikidata", "page") for p in people["listed"] + people["no_longer_listed"]) and "wikidata" in people["sources"]68 beta_detail = (await client.get(f"{V}/companies/{fixture_data['beta_slug']}")).json()69 assert beta_detail["profile"] is None and beta_detail["facts"] == []70