mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Download forms: allow a frequency of "Once" (#804)
* app: a download frequency of "Once" no longer blocks submission useForm treated any falsy value as a missing required field. "Once" is frequency 0, so the Channel/Playlist, RSS, and Zim download forms never became ready and the Download button stayed disabled. Only null, undefined, '', false, and NaN count as missing now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 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> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c8d5765ea3
commit
d75be8e1a4
5 changed files with 65 additions and 1 deletions
|
|
@ -127,6 +127,15 @@ describe('<ChannelDownloadForm/>', () => {
|
|||
shouldBeInvalid('#url_input');
|
||||
});
|
||||
|
||||
it('can be submitted with a frequency of Once', () => {
|
||||
cy.get('#url_input').type('https://example.com/playlist').wait(500);
|
||||
cy.get('#frequency_select').click();
|
||||
cy.contains('[role="option"]:visible', 'Once').should('be.visible').click({force: true});
|
||||
cy.get('#frequency_select').should('have.value', 'Once');
|
||||
|
||||
cy.get('#download_form_download_button').should('not.be.disabled');
|
||||
});
|
||||
|
||||
it('can choose different options', () => {
|
||||
/*
|
||||
* `#download_frequency_selector` and `.item` named the old dropdown and its menu rows.
|
||||
|
|
|
|||
|
|
@ -67,7 +67,11 @@ export function useForm({
|
|||
setReady(false);
|
||||
return
|
||||
}
|
||||
const missingValues = Object.keys(memoizedRequires).filter(i => !_.get(formData, i));
|
||||
// 0 is a real value (a download frequency of "Once"), only empty values are missing.
|
||||
const missingValues = Object.keys(memoizedRequires).filter(i => {
|
||||
const value = _.get(formData, i);
|
||||
return value === null || value === undefined || value === '' || value === false || Number.isNaN(value);
|
||||
});
|
||||
if (missingValues.length > 0) {
|
||||
console.debug(`Form invalid because it is missing required value: ${missingValues[0]}`);
|
||||
setReady(false);
|
||||
|
|
|
|||
|
|
@ -727,6 +727,29 @@ describe('useForm', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('zero satisfies a required field', async () => {
|
||||
// A download frequency of 0 means "Once".
|
||||
const {result} = renderHook(() => useForm({
|
||||
defaultFormData: {frequency: null},
|
||||
submitter: jest.fn(),
|
||||
}));
|
||||
|
||||
act(() => {
|
||||
result.current.getCustomProps({name: 'frequency', required: true});
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.ready).toBe(false);
|
||||
});
|
||||
|
||||
act(() => {
|
||||
result.current.setValue('frequency', 0);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.formData.frequency).toBe(0);
|
||||
expect(result.current.ready).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('addRequires marks field as required', async () => {
|
||||
const {result} = renderHook(() => useForm({
|
||||
defaultFormData: {field: ''},
|
||||
|
|
|
|||
|
|
@ -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