SPB Git forge
28commits 1branches 0releases
7.7 MBsize
maindefault branch
10 days agolast push
Python 66.3% TypeScript 22.7% JavaScript 8.6% HTML 1.4% CSS 0.7%
6.6 KB · 113 lines python
Raw Blame History
1from __future__ import annotations23import pytest45from companyatlas.connectors._util import ats_sensor_spec, country_code, job_fingerprint, parse_date, parse_location6from companyatlas.connectors.generic_html import looks_like_name, parse_price, role_category7from companyatlas.sdk import connector as C8from companyatlas.taxonomy import Surface9from companyatlas.urls import classify_url, detect_ats101112@pytest.mark.parametrize("url,anchor,surface", [13    ("https://stripe.com/pricing", "Pricing", Surface.PRICING),14    ("https://stripe.com/jobs", "Jobs", Surface.CAREERS),15    ("https://boards.greenhouse.io/stripe", None, Surface.JOBS_BOARD),16    ("https://stripe.com/newsroom", "Newsroom", Surface.NEWSROOM),17    ("https://investors.example.com/", None, Surface.INVESTOR_RELATIONS),18    ("https://example.com/about/leadership", "Leadership", Surface.LEADERSHIP),19    ("https://example.com/legal/privacy", None, Surface.LEGAL_PRIVACY),20    ("https://example.com/blog/atom.xml", None, Surface.FEED),21    ("https://example.com/sitemap.xml", None, Surface.SITEMAP),22])23def test_classify_url(url: str, anchor: str | None, surface: Surface) -> None:24    s, conf = classify_url(url, anchor=anchor, canonical_domain="example.com")25    assert s == surface and conf >= 0.55262728def test_connector_selection() -> None:29    assert C.for_surface("jobs_board", "https://boards-api.greenhouse.io/v1/boards/stripe/jobs?content=false").connector_id == "greenhouse-v1"30    assert C.for_surface("jobs_board", "https://api.lever.co/v0/postings/palantir?mode=json").connector_id == "lever-v1"31    assert C.for_surface("jobs_board", "https://nvidia.wd5.myworkdayjobs.com/wday/cxs/nvidia/NVIDIAExternalCareerSite/jobs").connector_id == "workday-v1"32    assert C.for_surface("feed", "https://x.com/blog/feed.xml").connector_id == "feed-v1"33    assert C.for_surface("sitemap", "https://x.com/sitemap_index.xml").connector_id == "sitemap-v1"34    assert C.for_surface("status", "https://status.x.com/api/v2/summary.json").connector_id == "statuspage-v1"35    assert C.for_surface("pricing", "https://x.com/pricing").connector_id == "generic-html-v1"36    assert C.for_surface("legal_terms", "https://x.com/terms").connector_id == "generic-html-v1"37    assert C.get("greenhouse-v0").connector_id == "greenhouse-v1"   # older ids fall back to the family's newest38    # vendor connectors are pattern-bound: a non-ATS jobs_board URL never gets an ATS parser39    assert C.for_surface("jobs_board", "https://x.com/jobs").connector_id == "jsonld-jobs-v1"40    assert C.for_surface("status", "https://status.x.com/").connector_id == "generic-html-v1"414243def test_ats_detection_and_specs() -> None:44    assert detect_ats("https://boards.greenhouse.io/stripe") == ("greenhouse", "stripe")45    spec = ats_sensor_spec("workday", "nvidia", "https://nvidia.wd5.myworkdayjobs.com/en-US/NVIDIAExternalCareerSite")46    assert spec and spec[0].endswith("/wday/cxs/nvidia/NVIDIAExternalCareerSite/jobs") and spec[1] == "workday-v1"47    assert ats_sensor_spec("teamtailor", "acme", "https://career.acme.com/jobs")[0] == "https://career.acme.com/jobs.json"48    assert ats_sensor_spec("lever", "x", "https://jobs.eu.lever.co/x")[0].startswith("https://api.eu.lever.co/")495051@pytest.mark.parametrize("text,city,region,country,remote", [52    ("San Francisco, CA", "San Francisco", "CA", None, None),          # CA is ambiguous → no country guess53    ("Austin, TX", "Austin", "TX", "US", None),54    ("Toronto, ON, Canada", "Toronto", "ON", "CA", None),55    ("US, MA, Westford", "Westford", "MA", "US", None),56    ("Remote - US", None, None, "US", True),57    ("Germany", None, None, "DE", None),58    ("Paris, France (Hybrid)", "Paris", None, "FR", False),59    ("Dublin", None, None, None, None),60    ("London EC2M 2PF, United Kingdom", "London", None, "GB", None),61])62def test_parse_location(text: str, city: str | None, region: str | None, country: str | None, remote: bool | None) -> None:63    loc = parse_location(text)64    assert (loc["city"], loc["region"], loc["country"], loc["remote"]) == (city, region, country, remote)656667def test_country_code_and_dates() -> None:68    assert country_code("United Kingdom") == "GB" and country_code("usa") == "US" and country_code("DEU") == "DE" and country_code("Atlantis") is None69    assert parse_date("2026-09-10T09:00:00Z").isoformat().startswith("2026-09-10T09:00")70    assert parse_date(1711403416463).year == 202471    assert parse_date("Posted Yesterday") is None or parse_date("Posted Yesterday").year >= 202072    assert parse_date("garbage") is None737475def test_job_fingerprint_is_stable() -> None:76    a = job_fingerprint("Senior  Engineer", "Toronto, ON", "123", None)77    b = job_fingerprint("senior engineer", "toronto, on", "123", "https://x/other")78    assert a == b and a != job_fingerprint("Senior Engineer", "Toronto, ON", "124", None)798081@pytest.mark.parametrize("title,category,is_exec", [82    ("Chief Executive Officer", "ceo", True), ("Co-Founder & CEO", "founder", True), ("Chief Financial Officer", "cfo", True),83    ("SVP, Global Sales", "vp", False), ("Head of People", "head", False), ("Chairman of the Board", "chair", True),84    ("Independent Director", "board", False), ("Chief People Officer", "other", True), ("Software Engineer", "other", False),85])86def test_role_category(title: str, category: str, is_exec: bool) -> None:87    assert role_category(title) == (category, is_exec)888990def test_looks_like_name() -> None:91    assert looks_like_name("María García-López") and looks_like_name("Tom O'Neill") and looks_like_name("Dr. Jane Doe")92    assert not looks_like_name("Meet the team") and not looks_like_name("Chief Executive Officer") and not looks_like_name("Read more")939495@pytest.mark.parametrize("text,price,currency,period,unit,contact", [96    ("$29 per month", 29.0, "USD", "month", None, False),97    ("€1.299,00 / Jahr", 1299.0, "EUR", "year", None, False),98    ("£12 per user / month, billed annually", 12.0, "GBP", "month", "user", False),99    ("From $1,000/year", 1000.0, "USD", "year", None, False),100    ("Contact sales", None, None, "contact", None, True),101    ("Free", 0.0, None, None, None, False),102    ("CHF 49 monthly", 49.0, "CHF", "month", None, False),103    ("$0.10 per 1,000 requests", 0.10, "USD", "usage", "1,000", False),104])105def test_parse_price(text: str, price: float | None, currency: str | None, period: str | None, unit: str | None, contact: bool) -> None:106    info = parse_price(text)107    assert info is not None108    assert (info["price"], info["currency"], info["billing_period"], info["unit"], info["contact_sales"]) == (price, currency, period, unit, contact)109110111def test_parse_price_none_for_prose() -> None:112    assert parse_price("Up to 5 users and email support") is None113