Files
datatools-dev/tests/gui/test_lite_tier.py
Michael ff2eaeb6c4 feat(home): multi-file upload + per-file analysis, drop tool grid
Home is now upload + analysis only. The page accepts multiple files in
one go, analyzes each independently, and renders findings grouped by
filename in bordered containers. The 3-section tool-card grid is gone —
discovery happens via the sidebar now.

Mechanics:
- file_uploader uses accept_multiple_files=True. Each file's findings
  cache in session_state["home_findings_by_file"] keyed by filename so
  removing a file via Streamlit's "x" button drops its findings too,
  and re-clicking Run only re-analyzes pending files.
- The first uploaded file is mirrored into the singular
  home_uploaded_{name,bytes,size} keys so tool pages continue to pick
  up an "active" upload through pickup_or_upload — no tool-page changes.
- New i18n keys: upload.intro_multi, upload.uploader_label_multi,
  upload.clear_results, upload.empty_state. upload.heading text is
  updated to "Upload one or more files to start" (EN + ES).

Dropped tests pinning the tool grid:
- TestHomeToolGridLocalization (test_chrome.py)
- test_home_tool_card_uses_es_name (test_smoke.py)
- TestLiteHomeGridBadges (test_lite_tier.py — locked-card lock-badge
  assertions; locking is still enforced per-tool-page via
  require_feature_or_render_upgrade)

2009 tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 20:12:48 +00:00

106 lines
3.6 KiB
Python

"""GUI tests for the Lite tier.
A Lite license unlocks Find Duplicates, Clean Text, Standardize
Formats. Opening any other tool page (Fix Missing Values, Map
Columns, Automated Workflows, etc.) must render an upgrade prompt
and short-circuit the page body.
The home grid shows a 🔒 Locked badge on the cards for tools the
user's tier doesn't unlock.
"""
from __future__ import annotations
import pytest
from .conftest import collected_text, stash_upload
@pytest.fixture
def lite_license(monkeypatch, tmp_path):
"""Activate a Lite license; return nothing — the env vars route
every page on this test through this license."""
monkeypatch.delenv("DATATOOLS_DEV_MODE", raising=False)
monkeypatch.setenv(
"DATATOOLS_LICENSE_PATH", str(tmp_path / "license.json"),
)
from src.license.manager import reset_singleton_for_tests
reset_singleton_for_tests()
from src.license import LicenseManager, Tier
LicenseManager()._mint(
name="Lite User", email="lite@example.com", tier=Tier.LITE,
)
yield
reset_singleton_for_tests()
# ---------------------------------------------------------------------------
# Unlocked tools render normally
# ---------------------------------------------------------------------------
class TestLiteUnlockedPages:
@pytest.mark.parametrize("slug,signal", [
("1_Deduplicator", "Find Duplicates"),
("2_Text_Cleaner", "Clean Text"),
("3_Format_Standardizer", "Standardize Formats"),
])
def test_unlocked_pages_render_body(
self, lite_license, app_factory, slug, signal, small_csv_bytes,
):
app = app_factory(slug)
stash_upload(app, name="messy.csv", data=small_csv_bytes)
app.run()
text = collected_text(app)
assert signal in text
# No upgrade prompt.
assert "isn't on your" not in text and "no está incluida" not in text
# ---------------------------------------------------------------------------
# Locked tools render upgrade prompt
# ---------------------------------------------------------------------------
class TestLiteLockedPages:
@pytest.mark.parametrize("slug", [
"4_Missing_Values",
"5_Column_Mapper",
"9_Pipeline_Runner",
"6_Outlier_Detector",
"7_Multi_File_Merger",
"8_Validator_Reporter",
])
def test_locked_page_shows_upgrade_prompt(
self, lite_license, app_factory, slug, small_csv_bytes,
):
app = app_factory(slug)
stash_upload(app, name="messy.csv", data=small_csv_bytes)
app.run()
text = collected_text(app)
# Upgrade prompt title carries the localized lock + tier label.
assert "isn't on your" in text or "no está incluida" in text, (
f"locked page {slug!r} missing upgrade prompt; got:\n"
f"{text[:500]}"
)
def test_upgrade_button_present(
self, lite_license, app_factory, small_csv_bytes,
):
app = app_factory("4_Missing_Values")
stash_upload(app, name="messy.csv", data=small_csv_bytes)
app.run()
labels = [b.label for b in app.button]
assert any("Manage license" in lbl for lbl in labels), (
f"upgrade prompt missing Manage-license button; got: {labels}"
)
# ---------------------------------------------------------------------------
# Sidebar status shows Lite
# ---------------------------------------------------------------------------
class TestLiteSidebarStatus:
def test_sidebar_caption_mentions_lite(self, lite_license, home_app):
home_app.run()
captions = " ".join(c.value for c in home_app.sidebar.caption)
assert "Lite" in captions