Spaces:
Sleeping
Sleeping
| from __future__ import annotations | |
| import os | |
| import tempfile | |
| import sys | |
| from pathlib import Path | |
| from sqlmodel import Session | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | |
| from backend import Backend | |
| from models import Asset, FetlifeKinkMeta, FetlifePictureRef, Kink, Source | |
| def assert_true(condition: bool, message: str) -> None: | |
| if not condition: | |
| raise AssertionError(message) | |
| def check_fetlife_popularity_uses_kinksters() -> None: | |
| with tempfile.TemporaryDirectory() as tmp_dir: | |
| backend = Backend(Path(tmp_dir) / "store.db") | |
| with Session(backend.engine) as session: | |
| session.add( | |
| Kink( | |
| id="fixture_popularity", | |
| name="Fixture Play", | |
| cluster="fetlife_fetish", | |
| short_definition="Fixture", | |
| notes="", | |
| risk_level="low", | |
| is_extreme=False, | |
| ) | |
| ) | |
| session.commit() | |
| backend.upsert_fetlife_kink_meta( | |
| "fixture_popularity", | |
| "999", | |
| "https://example.test/fetishes/999", | |
| { | |
| "Kinksters": "271K", | |
| "Pictures": "1M", | |
| "Statuses": "1M", | |
| "Videos": "193K", | |
| }, | |
| has_real_images=True, | |
| similar_count=3, | |
| ) | |
| with Session(backend.engine) as session: | |
| meta = session.get(FetlifeKinkMeta, "fixture_popularity") | |
| assert_true(meta is not None, "fixture meta was not written") | |
| assert_true(meta.popularity == 271000.0, f"popularity should use Kinksters only, got {meta.popularity}") | |
| def check_image_relevance_filters_spammy_reuse() -> None: | |
| with tempfile.TemporaryDirectory() as tmp_dir: | |
| backend = Backend(Path(tmp_dir) / "store.db") | |
| with Session(backend.engine) as session: | |
| session.add(Source(id="fetlife_fetish_pages", name="Fixture", source_type="test", base_url="", license_model="test")) | |
| session.add(Kink(id="fixture_bondage", name="Bondage", cluster="fetlife_fetish", short_definition="", notes="")) | |
| for index in range(14): | |
| kink_id = f"fixture_other_{index}" | |
| session.add(Kink(id=kink_id, name=f"Other {index}", cluster="fetlife_fetish", short_definition="", notes="")) | |
| session.commit() | |
| with Session(backend.engine) as session: | |
| for index in range(14): | |
| kink_id = f"fixture_other_{index}" | |
| session.add( | |
| Asset( | |
| id=f"asset_other_{index}", | |
| kink_id=kink_id, | |
| source_id="fetlife_fetish_pages", | |
| asset_url=f"/media/fetlife_fetishes/{index}/999.jpg", | |
| ) | |
| ) | |
| session.add( | |
| FetlifePictureRef( | |
| id=f"ref_other_{index}", | |
| kink_id=kink_id, | |
| fetish_id=str(index), | |
| attachment_id="999", | |
| picture_title="Picture by spam - unrelated tag cloud", | |
| ) | |
| ) | |
| session.add( | |
| Asset( | |
| id="asset_good", | |
| kink_id="fixture_bondage", | |
| source_id="fetlife_fetish_pages", | |
| asset_url="/media/fetlife_fetishes/10/100.jpg", | |
| ) | |
| ) | |
| session.add( | |
| FetlifePictureRef( | |
| id="ref_good", | |
| kink_id="fixture_bondage", | |
| fetish_id="10", | |
| attachment_id="100", | |
| picture_title="Picture by creator - bondage rope", | |
| caption_text="bondage rope", | |
| ) | |
| ) | |
| session.add( | |
| Asset( | |
| id="asset_spam", | |
| kink_id="fixture_bondage", | |
| source_id="fetlife_fetish_pages", | |
| asset_url="/media/fetlife_fetishes/10/999.jpg", | |
| ) | |
| ) | |
| session.add( | |
| FetlifePictureRef( | |
| id="ref_spam", | |
| kink_id="fixture_bondage", | |
| fetish_id="10", | |
| attachment_id="999", | |
| picture_title="Picture by spam - unrelated tag cloud", | |
| ) | |
| ) | |
| session.commit() | |
| detail = backend.get_kink("fixture_bondage") | |
| assert_true(detail is not None, "fixture detail missing") | |
| assert_true(detail["representative_image_count"] == 1, f"expected one representative image, got {detail['representative_image_count']}") | |
| assert_true(detail["assets"][0]["image_relevance_score"] > 0.7, "good image relevance score too low") | |
| def main() -> int: | |
| check_fetlife_popularity_uses_kinksters() | |
| check_image_relevance_filters_spammy_reuse() | |
| print("REGRESSION CHECKS OK") | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |