launchmaxxing/tests/test_utm.py
caelum0x 6908fb66af feat: catalog to 82 directories, dashboard/serve, dogfood, interactive init, outreach send, portfolio, content/pain-point expansion, watch, multi-competitor backlinks, compare, directory export
Round 1 of 3 against STRATEGY-2026-10-23.md's backlog. Highlights:

- catalog.py: 24 -> 82 live-verified directories across AI-tool/GEO,
  browser-extension, API-marketplace, newsletter-sponsor, Slack/Discord
  community, and vertical-SaaS categories; export_csv/json/opml.
- dashboard.py + `dashboard`/`serve` commands: self-contained HTML dashboard
  (inline SVG progress rings, submission timeline) and a localhost-only live
  server; `report --html`/`--json` reuse the same payload.
- dogfood.py + `dogfood`: runs content generation against launchmaxxing's own
  profile for its six not-yet-submitted directories, writing evidence to
  launch-evidence/ and recording tracker state.
- init --interactive: step-by-step onboarding wizard, saves a per-product
  default profile so content/outreach no longer need every flag re-supplied.
- outreach.py: `outreach send <contact_id>` sends via the user's own SMTP
  creds and records sent_at/send_status; outreach list now prints contact
  ids so send/status are actually usable from the CLI.
- portfolio.py + `portfolio`: cross-product rollup (directories, checklist,
  outreach, last-active) across every tracked product.
- content.py: five new generators (indie_hackers, ask_hn, cold_pitch_email,
  community_intro, newsletter_sponsor_pitch), 5 -> 10 platforms.
- painpoints.py: merges Reddit with free-keyless Hacker News (Algolia) search
  and an honest Indie Hackers blocked-source report.
- watch.py + `watch`: background poll + native macOS notification on newly
  dead directories or newly stale outreach contacts.
- backlinks.py: multi-competitor `--competitors file.txt --export csv` mode.
- checklist.py: cold_outreach and reddit_pain_points now auto-derive from
  real outreach/pain-point state, not just launch_everywhere.
- compare.py + `compare`: regenerable competitor comparison table instead of
  hand-written prose.

214/214 tests pass, ruff clean on touched files. Verified every command above
by actually running it against scratch state/db files this round.
2026-10-23 14:45:17 +03:00

121 lines
4.6 KiB
Python

from __future__ import annotations
import csv
from pathlib import Path
import pytest
from launchmaxxing import utm
def test_defaults_for_known_platform() -> None:
defaults = utm.defaults_for_platform("product_hunt")
assert defaults == {"source": "producthunt", "medium": "launch_directory"}
def test_defaults_for_unknown_platform_falls_back() -> None:
defaults = utm.defaults_for_platform("totally-unknown")
assert defaults["source"] == "totally-unknown"
assert defaults["medium"] == "referral"
def test_defaults_resolve_for_every_catalog_platform_id() -> None:
"""Every catalog platform gets a usable (non-empty source/medium) UTM default -- either from
the curated :data:`utm.PLATFORM_UTM_DEFAULTS` table (only practical to hand-curate for a
subset of the catalog) or :func:`utm.defaults_for_platform`'s id-derived fallback for
everything else, so growing the catalog never leaves a platform with no usable default."""
from launchmaxxing import catalog
for platform in catalog.PLATFORMS:
defaults = utm.defaults_for_platform(platform["id"])
assert defaults["source"]
assert defaults["medium"]
def test_build_url_adds_utm_params() -> None:
url = utm.build_url("https://acme.example", source="producthunt", medium="launch_directory",
campaign="acme-launch")
assert "utm_source=producthunt" in url
assert "utm_medium=launch_directory" in url
assert "utm_campaign=acme-launch" in url
def test_build_url_adds_scheme_when_missing() -> None:
url = utm.build_url("acme.example", source="s", medium="m", campaign="c")
assert url.startswith("https://acme.example")
def test_build_url_preserves_existing_non_utm_params() -> None:
url = utm.build_url("https://acme.example/page?ref=abc", source="s", medium="m", campaign="c")
assert "ref=abc" in url
def test_build_url_overwrites_existing_utm_params_idempotently() -> None:
first = utm.build_url("https://acme.example", source="old", medium="old", campaign="old")
second = utm.build_url(first, source="new", medium="new", campaign="new")
assert "utm_source=new" in second
assert "utm_source=old" not in second
assert second.count("utm_source") == 1
def test_build_url_includes_optional_content_param() -> None:
url = utm.build_url("https://acme.example", source="s", medium="m", campaign="c", content="thread-1")
assert "utm_content=thread-1" in url
def test_build_url_rejects_empty_base_url() -> None:
with pytest.raises(ValueError):
utm.build_url("", source="s", medium="m", campaign="c")
def _link_row(**overrides: str) -> dict[str, str]:
row = {"id": "l1", "product_name": "Acme", "platform_id": "product_hunt", "base_url": "https://acme.example",
"source": "producthunt", "medium": "launch_directory", "campaign": "acme-launch", "content": "",
"full_url": "https://acme.example?utm_source=producthunt&utm_medium=launch_directory"
"&utm_campaign=acme-launch",
"created_at": "2026-10-01T00:00:00+00:00"}
row.update(overrides)
return row
def test_write_links_csv_writes_header_and_rows(tmp_path: Path) -> None:
out_path = tmp_path / "links.csv"
rows = [_link_row(), _link_row(id="l2", platform_id="betalist", source="betalist")]
result = utm.write_links_csv(rows, out_path)
assert result == out_path
assert out_path.is_file()
with out_path.open(newline="", encoding="utf-8") as f:
reader = csv.reader(f)
header = next(reader)
data_rows = list(reader)
assert header == list(utm.CSV_FIELDS)
assert len(data_rows) == 2
expected_full_url = ("https://acme.example?utm_source=producthunt&utm_medium=launch_directory"
"&utm_campaign=acme-launch")
assert data_rows[0] == ["l1", "Acme", "product_hunt", "https://acme.example", "producthunt",
"launch_directory", "acme-launch", "", expected_full_url,
"2026-10-01T00:00:00+00:00"]
assert data_rows[1][0:3] == ["l2", "Acme", "betalist"]
def test_write_links_csv_handles_empty_rows(tmp_path: Path) -> None:
out_path = tmp_path / "empty.csv"
utm.write_links_csv([], out_path)
with out_path.open(newline="", encoding="utf-8") as f:
reader = csv.reader(f)
rows = list(reader)
assert rows == [list(utm.CSV_FIELDS)]
def test_write_links_csv_accepts_str_path(tmp_path: Path) -> None:
out_path = tmp_path / "links.csv"
result = utm.write_links_csv([_link_row()], str(out_path))
assert result == out_path
assert out_path.is_file()