mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 03:46:29 -05:00
Configs can be saved in background using switches.
This commit is contained in:
parent
44d4921c84
commit
d54735c4bb
53 changed files with 967 additions and 574 deletions
|
|
@ -9,7 +9,7 @@ from wrolpi.downloader import Download
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_zim_search(test_async_client, test_session, test_zim, tag_factory, assert_zim_search):
|
||||
async def test_zim_search(async_client, test_session, test_zim, tag_factory, assert_zim_search):
|
||||
"""Entries can be tagged and retrieved using their containing Zim."""
|
||||
tag1, tag2 = await tag_factory(), await tag_factory()
|
||||
test_zim.tag_entry(tag1.name, 'one')
|
||||
|
|
@ -80,7 +80,7 @@ async def test_zim_search(test_async_client, test_session, test_zim, tag_factory
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_entries_by_tag(test_async_client, test_session, test_zim, tag_factory):
|
||||
async def test_entries_by_tag(async_client, test_session, test_zim, tag_factory):
|
||||
"""Entries can be tagged and retrieved using their containing Zim."""
|
||||
tag1, tag2 = await tag_factory(), await tag_factory()
|
||||
test_zim.tag_entry(tag1.name, 'one')
|
||||
|
|
@ -99,37 +99,37 @@ async def test_entries_by_tag(test_async_client, test_session, test_zim, tag_fac
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_zim_crud(test_async_client, test_session, test_directory, test_zim):
|
||||
request, response = await test_async_client.get('/api/zim')
|
||||
async def test_zim_crud(async_client, test_session, test_directory, test_zim):
|
||||
request, response = await async_client.get('/api/zim')
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert len(response.json['zims']) == 1
|
||||
assert response.json['zims'][0]['path'] == test_zim.path.name
|
||||
|
||||
request, response = await test_async_client.delete('/api/zim/1')
|
||||
request, response = await async_client.delete('/api/zim/1')
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
assert not test_zim.path.exists()
|
||||
assert test_session.query(Zim).count() == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_zim_tag_and_untag(test_async_client, test_session, test_zim, tag_factory):
|
||||
async def test_zim_tag_and_untag(async_client, test_session, test_zim, tag_factory):
|
||||
"""Zim entries can be Tagged and Untagged."""
|
||||
tag1, tag2 = await tag_factory(), await tag_factory()
|
||||
test_session.commit()
|
||||
|
||||
# Entries can be tagged in the API.
|
||||
content = dict(tag_name=tag1.name, zim_id=test_zim.id, zim_entry='home')
|
||||
request, response = await test_async_client.post('/api/zim/tag', content=json.dumps(content))
|
||||
request, response = await async_client.post('/api/zim/tag', content=json.dumps(content))
|
||||
assert response.status_code == HTTPStatus.CREATED
|
||||
|
||||
# Entries can be untagged in the API.
|
||||
content = dict(tag_name=tag1.name, zim_id=test_zim.id, zim_entry='home')
|
||||
request, response = await test_async_client.post('/api/zim/untag', content=json.dumps(content))
|
||||
request, response = await async_client.post('/api/zim/untag', content=json.dumps(content))
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
|
||||
# Cannot untag twice.
|
||||
content = dict(tag_name=tag1.name, zim_id=test_zim.id, zim_entry='home')
|
||||
request, response = await test_async_client.post('/api/zim/untag', content=json.dumps(content))
|
||||
request, response = await async_client.post('/api/zim/untag', content=json.dumps(content))
|
||||
assert response.status_code == HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
|
|
@ -199,7 +199,7 @@ def test_get_zim_entry(test_session, test_client, test_zim):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_find_outdated_zim_files(test_session, test_directory, test_zim_bytes, test_async_client):
|
||||
async def test_find_outdated_zim_files(test_session, test_directory, test_zim_bytes, async_client):
|
||||
"""Outdated Zim files are found and reported. They can automatically be deleted."""
|
||||
# Can search empty directory.
|
||||
outdated, current = lib.find_outdated_zim_files()
|
||||
|
|
@ -217,11 +217,11 @@ async def test_find_outdated_zim_files(test_session, test_directory, test_zim_by
|
|||
asdf.write_bytes(test_zim_bytes)
|
||||
empty = test_directory / 'zims/wikipedia_en_all_maxi_2023-03.zim' # empty files should be ignored.
|
||||
empty.touch()
|
||||
request, response = await test_async_client.get('/api/zim/outdated')
|
||||
request, response = await async_client.get('/api/zim/outdated')
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert response.json['outdated'] == [str(wikipedia_one.relative_to(test_directory)), ]
|
||||
|
||||
request, response = await test_async_client.delete('/api/zim/outdated')
|
||||
request, response = await async_client.delete('/api/zim/outdated')
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
# Only the outdated was deleted.
|
||||
assert wikibooks_one.is_file()
|
||||
|
|
@ -232,12 +232,12 @@ async def test_find_outdated_zim_files(test_session, test_directory, test_zim_by
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_search_estimates(test_session, test_async_client, zim_factory):
|
||||
async def test_search_estimates(test_session, async_client, zim_factory):
|
||||
zim_factory('test zim')
|
||||
test_session.commit()
|
||||
|
||||
body = dict(search_str='one')
|
||||
request, response = await test_async_client.post('/api/zim/search_estimates', json=body)
|
||||
request, response = await async_client.post('/api/zim/search_estimates', json=body)
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert len(response.json['zims_estimates']) == 1
|
||||
assert response.json['zims_estimates'][0]['estimate'] == 2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue