Files
siftlode/backend/tests/test_download_share_notice.py
T
peter 3a688fa0f5 refactor(capture): the unit's tables move into downloads/models
The nine Capture tables (files, jobs, folders, shares, links, quota, cookies, profiles, library
resume points) leave app/models.py for the unit's own module; app.tables registers every unit's
tables for the migrations, the test database and the ownership check. No schema change.
2026-10-18 23:45:53 +02:00

43 lines
1.4 KiB
Python

"""The "shared with you" notice carries the download's title in its data, so the client can name
the notice in the reader's language. Its stored title is an English sentence ("Cats was shared with
you") — the only place the title lived, so a Hungarian reader got the English. Needs the DB."""
from sqlalchemy import select
from app.models import Notification
from app.downloads.models import DownloadJob, MediaAsset
def test_a_share_notice_carries_the_title_and_the_sharer(db, make_user, as_user):
owner = make_user("owner@example.com")
friend = make_user("friend@example.com")
asset = MediaAsset(
source_kind="url", source_ref="share-e30", format_sig="sig", status="ready", ref_count=1
)
db.add(asset)
db.flush()
job = DownloadJob(
user_id=owner.id,
asset_id=asset.id,
source_kind="url",
source_ref="share-e30",
status="done",
queue_pos=1,
profile_snapshot={},
display_name="Cats",
)
db.add(job)
db.commit()
r = as_user(owner).post(f"/api/downloads/{job.id}/share", json={"email": "friend@example.com"})
assert r.status_code == 200, r.text
notice = db.execute(select(Notification).where(Notification.user_id == friend.id)).scalar_one()
assert notice.type == "download_shared"
assert notice.data == {
"kind": "download_shared",
"from": "owner@example.com",
"job_id": job.id,
"title": "Cats",
}