diff --git a/wrolpi/downloader.py b/wrolpi/downloader.py index 84727acd..9eae4baa 100644 --- a/wrolpi/downloader.py +++ b/wrolpi/downloader.py @@ -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 diff --git a/wrolpi/test/test_root_api.py b/wrolpi/test/test_root_api.py index a8163666..4b8eff7a 100644 --- a/wrolpi/test/test_root_api.py +++ b/wrolpi/test/test_root_api.py @@ -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."""