mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 10:51:36 -04:00
Link a Download to its domain by its destination column
`domain_download_links` read the destination only from a Download's settings, but the destination is now a column (the config import moves an old settings destination into it), so no Download was linked to a domain by its directory. Read the column, and the settings for an old Download, as channels already do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
79526afebe
commit
76105baf9b
2 changed files with 29 additions and 3 deletions
|
|
@ -1018,10 +1018,12 @@ def domain_download_links(session: Session) -> Dict[int, int]:
|
|||
|
||||
links = dict()
|
||||
downloads = session.query(Download.id, Download.url, Download.downloader, Download.sub_downloader,
|
||||
Download.settings) \
|
||||
Download.destination, Download.settings) \
|
||||
.filter(Download.frequency.isnot(None), Download.collection_id.is_(None))
|
||||
for id_, url, downloader, sub_downloader, settings in downloads:
|
||||
if destination := (settings or dict()).get('destination'):
|
||||
for id_, url, downloader, sub_downloader, destination, settings in downloads:
|
||||
# An old Download kept its destination in its settings.
|
||||
destination = str(destination) if destination else (settings or dict()).get('destination')
|
||||
if destination:
|
||||
for collection_id, directory, prefix in directories:
|
||||
if destination == directory or destination.startswith(prefix):
|
||||
links[id_] = collection_id
|
||||
|
|
|
|||
|
|
@ -1277,6 +1277,30 @@ def test_link_domain_and_downloads(test_session, test_download_manager):
|
|||
assert download4.collection_id is None # no frequency = no link
|
||||
|
||||
|
||||
def test_link_domain_and_downloads_by_destination(test_session, test_directory, test_download_manager):
|
||||
"""A Download whose destination column is in a domain's directory is linked to that domain (the destination was
|
||||
moved out of the settings)."""
|
||||
from wrolpi.downloader import Download
|
||||
from modules.archive.lib import link_domain_and_downloads
|
||||
|
||||
collection = Collection(name='example.com', kind='domain', directory=test_directory / 'archive/example.com')
|
||||
test_session.add(collection)
|
||||
exact = Download(url='https://other.com/rss', downloader='rss', sub_downloader='archive', frequency=86400,
|
||||
destination=test_directory / 'archive/example.com')
|
||||
below = Download(url='https://other.com/rss2', downloader='rss', sub_downloader='archive', frequency=86400,
|
||||
destination=test_directory / 'archive/example.com/2025/01')
|
||||
similar = Download(url='https://other.com/rss3', downloader='rss', sub_downloader='archive', frequency=86400,
|
||||
destination=test_directory / 'archive/example.com.au')
|
||||
test_session.add_all([exact, below, similar])
|
||||
test_session.commit()
|
||||
|
||||
link_domain_and_downloads(test_session)
|
||||
|
||||
assert exact.collection_id == collection.id
|
||||
assert below.collection_id == collection.id
|
||||
assert similar.collection_id is None
|
||||
|
||||
|
||||
@skip_ci
|
||||
@pytest.mark.asyncio
|
||||
async def test_archive_download_uses_domain_collection_directory(async_client, test_session, test_directory, fake_now,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue