mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-22 16:06:19 -05:00
downloads: editing to "Once" stores a once-download, not frequency 0
Once-downloads have a NULL frequency. A 0 frequency counted as recurring (frequency != None) but could never be scheduled (not frequency), so an edited download stayed on the recurring list and could break renewal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
298988503e
commit
aca2fed8e6
2 changed files with 28 additions and 0 deletions
|
|
@ -1062,6 +1062,8 @@ class DownloadManager:
|
|||
sub_downloader: str | None = None, frequency: int = None,
|
||||
settings: Dict = None, collection_id: int = None) -> Download:
|
||||
download = Download.find_by_id(session, id_)
|
||||
# A once-download has no frequency; a frequency of 0 ("Once") is never stored as an interval.
|
||||
frequency = frequency or None
|
||||
if collection_id and not frequency:
|
||||
raise InvalidDownload(f'A once-download cannot be associated with a Collection')
|
||||
download.url = url
|
||||
|
|
|
|||
|
|
@ -584,6 +584,32 @@ async def test_update_download_with_settings_collection_id(test_session, async_c
|
|||
f'Expected NO_CONTENT but got {response.status_code}: {response.json}'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_download_frequency_once(test_session, async_client, test_download_manager_config,
|
||||
test_download_manager):
|
||||
"""Editing a recurring Download to a frequency of 0 ("Once") stores a once-download, not a zero interval."""
|
||||
|
||||
async def dispatch_downloads(*a, **kw):
|
||||
pass
|
||||
|
||||
with mock.patch('wrolpi.downloader.DownloadManager.dispatch_downloads', dispatch_downloads):
|
||||
body = dict(urls=['https://example.com/feed.xml'], downloader='rss', sub_downloader='archive',
|
||||
frequency=86400)
|
||||
request, response = await async_client.post('/api/download', json=body)
|
||||
assert response.status_code == HTTPStatus.CREATED
|
||||
download = test_session.query(Download).one()
|
||||
assert download.frequency == 86400
|
||||
|
||||
body = dict(urls=['https://example.com/feed.xml'], downloader='rss', sub_downloader='archive', frequency=0)
|
||||
request, response = await async_client.put(f'/api/download/{download.id}', json=body)
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT, response.json
|
||||
|
||||
test_session.expire_all()
|
||||
download = test_session.query(Download).one()
|
||||
assert download.frequency is None
|
||||
assert test_download_manager.get_recurring_downloads(test_session) == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_downloaders(async_client):
|
||||
"""A list of Downloaders the user can use can be gotten."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue