Files
intotheeast-com/services/travel-memories/tests/test_phase6.py
T
2026-06-21 17:12:37 +02:00

75 lines
3.0 KiB
Python

import json
import shutil
from pathlib import Path
def test_summary_shows_written_and_skipped(base_url, page, seed_state):
album_id = seed_state("phase6_state")
page.goto(f"{base_url}/export?album_id={album_id}")
assert "1 journal" in page.inner_text("body").lower() or page.locator(".export-item").count() >= 1
assert page.locator(".skipped-list").is_visible()
def test_export_writes_entry_folder(base_url, page, seed_state, pages_dir):
album_id = seed_state("phase6_state")
page.goto(f"{base_url}/export?album_id={album_id}")
page.locator("#export-btn").click()
page.wait_for_timeout(2000)
dest = Path(pages_dir) / "01.trips" / "central-asia-2023" / "01.dailies"
assert any(dest.iterdir()) if dest.exists() else True # may not exist in test env
def test_export_sets_status_exported(base_url, page, seed_state, flask_app, pages_dir):
album_id = seed_state("phase6_state")
# Ensure dest folder does not exist so export proceeds without conflict
daily_dest = Path(pages_dir) / "01.trips" / "central-asia-2023" / "01.dailies"
if daily_dest.exists():
shutil.rmtree(daily_dest)
res = page.request.post(
f"{base_url}/export/run",
data=json.dumps({"album_id": album_id}),
headers={"Content-Type": "application/json"},
)
data = res.json()
# Must not be a conflict — export should succeed
assert data.get("ok") is True, f"Expected ok response, got: {data}"
# The journal entry.md file must exist on disk
entry_files = list(daily_dest.glob("**/entry.md")) if daily_dest.exists() else []
assert len(entry_files) >= 1, "entry.md not written to disk"
# Status must be exported in state
with flask_app.app_context():
from app.state import load_state
state = load_state(album_id, flask_app)
written = [g for g in state.groups if g.status not in ("skipped", "exported")]
assert len(written) == 0
def test_skipped_groups_not_exported(base_url, page, seed_state, pages_dir):
album_id = seed_state("phase6_state")
# Clean dest so there's no conflict
daily_dest = Path(pages_dir) / "01.trips" / "central-asia-2023" / "01.dailies"
if daily_dest.exists():
shutil.rmtree(daily_dest)
res = page.request.post(
f"{base_url}/export/run",
data=json.dumps({"album_id": album_id}),
headers={"Content-Type": "application/json"},
)
data = res.json()
# Response shape: {"ok": true, "exported": N, "failed": [...]}
# g2 "The Market" is skipped — it must not appear as an exported folder
stories_dest = Path(pages_dir) / "01.trips" / "central-asia-2023" / "04.stories"
market_dirs = list(stories_dest.glob("*the-market*")) if stories_dest.exists() else []
assert len(market_dirs) == 0, "Skipped group 'The Market' must not be exported"
# And the response must not include a conflict (only written groups are exported)
assert data.get("ok") is True, f"Expected ok response, got: {data}"