diff --git a/wrolpi/root_api.py b/wrolpi/root_api.py index 59cd8036..1e3d5b91 100644 --- a/wrolpi/root_api.py +++ b/wrolpi/root_api.py @@ -383,6 +383,9 @@ async def post_download(request: Request, body: schema.DownloadRequest): # Raises an InvalidDownload if the Downloader cannot be found. download_manager.find_downloader_by_name(body.downloader) + if body.frequency and len(body.urls) != 1: + raise ValidationError('Only one URL can be specified for a recurring Download') + kwargs = dict(downloader_name=body.downloader, sub_downloader_name=body.sub_downloader, reset_attempts=True, destination=body.destination, tag_names=body.tag_names, diff --git a/wrolpi/test/test_downloader.py b/wrolpi/test/test_downloader.py index 2f888223..9abd3c12 100644 --- a/wrolpi/test/test_downloader.py +++ b/wrolpi/test/test_downloader.py @@ -975,6 +975,20 @@ async def test_process_runner_output(async_client, test_directory, test_download assert result.stderr == b'bad standard error\n' +@pytest.mark.asyncio +async def test_recurring_download_one_url(async_client, test_session, test_download_manager, test_downloader): + """A recurring Download has one URL; more are an error, not silently dropped.""" + body = dict( + urls=['https://example.com/1', 'https://example.com/2'], + downloader=test_downloader.name, + frequency=DownloadFrequency.weekly, + ) + request, response = await async_client.post('/api/download', content=json.dumps(body)) + assert response.status_code == HTTPStatus.BAD_REQUEST, response.body + assert 'one URL' in response.json['error'] + assert test_session.query(Download).count() == 0 + + @pytest.mark.asyncio async def test_crud_download(async_client, test_session, test_download_manager, test_downloader): """Test the ways that Downloads can be created."""