mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-21 23:46:18 -05:00
Creating new /api/archive/upload which accepts a file from the SingleFile browser extension and converts it to an Archive.
This commit is contained in:
parent
01338e4d89
commit
531ec3d65e
62 changed files with 1000 additions and 562 deletions
|
|
@ -16,7 +16,7 @@ def assert_map_file_status(test_client, expected, status_code=HTTPStatus.OK):
|
|||
|
||||
@mock.patch('modules.map.lib.is_pbf_file', lambda i: True)
|
||||
@mock.patch('modules.map.lib.is_dump_file', lambda i: True)
|
||||
def test_status_and_import(test_client, test_session, make_files_structure, mock_create_subprocess_shell):
|
||||
def test_status_and_import(test_client, test_session, make_files_structure, mock_run_command):
|
||||
"""PBF files can be imported, and the status of the import can be monitored."""
|
||||
pbf1, pbf2, dump1 = make_files_structure([
|
||||
'map/pbf/some-country.osm.pbf',
|
||||
|
|
@ -32,11 +32,9 @@ def test_status_and_import(test_client, test_session, make_files_structure, mock
|
|||
]
|
||||
assert_map_file_status(test_client, expected)
|
||||
|
||||
with mock.patch('modules.map.lib.asyncio') as mock_asyncio:
|
||||
mock_asyncio.create_subprocess_shell = mock_create_subprocess_shell(return_code=0)
|
||||
body = {'files': [str(pbf1), ], }
|
||||
request, response = test_client.post('/api/map/import', content=json.dumps(body))
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
body = {'files': [str(pbf1), ], }
|
||||
request, response = test_client.post('/api/map/import', content=json.dumps(body))
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
|
||||
expected = [
|
||||
{'imported': False, 'path': 'map/dump/dumpy.dump'},
|
||||
|
|
@ -45,11 +43,9 @@ def test_status_and_import(test_client, test_session, make_files_structure, mock
|
|||
]
|
||||
assert_map_file_status(test_client, expected)
|
||||
|
||||
with mock.patch('modules.map.lib.asyncio') as mock_asyncio:
|
||||
mock_asyncio.create_subprocess_shell = mock_create_subprocess_shell(return_code=0)
|
||||
body = {'files': [str(pbf1), str(pbf2)]}
|
||||
request, response = test_client.post('/api/map/import', content=json.dumps(body))
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
body = {'files': [str(pbf1), str(pbf2)]}
|
||||
request, response = test_client.post('/api/map/import', content=json.dumps(body))
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
|
||||
expected = [
|
||||
{'imported': False, 'path': 'map/dump/dumpy.dump'},
|
||||
|
|
@ -58,11 +54,9 @@ def test_status_and_import(test_client, test_session, make_files_structure, mock
|
|||
]
|
||||
assert_map_file_status(test_client, expected)
|
||||
|
||||
with mock.patch('modules.map.lib.asyncio') as mock_asyncio:
|
||||
mock_asyncio.create_subprocess_shell = mock_create_subprocess_shell(return_code=0)
|
||||
body = {'files': [str(dump1), ]}
|
||||
request, response = test_client.post('/api/map/import', content=json.dumps(body))
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
body = {'files': [str(dump1), ]}
|
||||
request, response = test_client.post('/api/map/import', content=json.dumps(body))
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
|
||||
expected = [
|
||||
{'imported': True, 'path': 'map/dump/dumpy.dump'},
|
||||
|
|
@ -74,7 +68,7 @@ def test_status_and_import(test_client, test_session, make_files_structure, mock
|
|||
|
||||
@mock.patch('modules.map.lib.is_pbf_file', lambda i: True)
|
||||
@mock.patch('modules.map.lib.is_dump_file', lambda i: True)
|
||||
def test_multiple_import(test_client, test_session, test_directory, make_files_structure, mock_create_subprocess_shell):
|
||||
def test_multiple_import(test_client, test_session, test_directory, make_files_structure, mock_run_command):
|
||||
"""Multiple PBFs can be imported. Importing a second time overwrites the previous imports."""
|
||||
pbf1, pbf2, pbf3, dump = make_files_structure([
|
||||
'map/pbf/country1.osm.pbf',
|
||||
|
|
@ -83,11 +77,9 @@ def test_multiple_import(test_client, test_session, test_directory, make_files_s
|
|||
'map/dumpy.dump',
|
||||
])
|
||||
|
||||
with mock.patch('modules.map.lib.asyncio') as mock_asyncio:
|
||||
mock_asyncio.create_subprocess_shell = mock_create_subprocess_shell(return_code=0)
|
||||
body = {'files': [str(pbf2), str(pbf1)]}
|
||||
request, response = test_client.post('/api/map/import', content=json.dumps(body))
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
body = {'files': [str(pbf2), str(pbf1)]}
|
||||
request, response = test_client.post('/api/map/import', content=json.dumps(body))
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
|
||||
# Two PBFs can be merged and imported.
|
||||
expected = [
|
||||
|
|
@ -98,11 +90,9 @@ def test_multiple_import(test_client, test_session, test_directory, make_files_s
|
|||
]
|
||||
assert_map_file_status(test_client, expected)
|
||||
|
||||
with mock.patch('modules.map.lib.asyncio') as mock_asyncio:
|
||||
mock_asyncio.create_subprocess_shell = mock_create_subprocess_shell(return_code=0)
|
||||
body = {'files': [str(pbf3), ]}
|
||||
request, response = test_client.post('/api/map/import', content=json.dumps(body))
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
body = {'files': [str(pbf3), ]}
|
||||
request, response = test_client.post('/api/map/import', content=json.dumps(body))
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
|
||||
# New imports overwrite old imports.
|
||||
expected = [
|
||||
|
|
@ -113,12 +103,10 @@ def test_multiple_import(test_client, test_session, test_directory, make_files_s
|
|||
]
|
||||
assert_map_file_status(test_client, expected)
|
||||
|
||||
with mock.patch('modules.map.lib.asyncio') as mock_asyncio:
|
||||
mock_asyncio.create_subprocess_shell = mock_create_subprocess_shell(return_code=0)
|
||||
# Can't mix PBF and dump.
|
||||
body = {'files': [str(dump), ]}
|
||||
request, response = test_client.post('/api/map/import', content=json.dumps(body))
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
# Can't mix PBF and dump.
|
||||
body = {'files': [str(dump), ]}
|
||||
request, response = test_client.post('/api/map/import', content=json.dumps(body))
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
|
||||
# Dump does not overwrite.
|
||||
expected = [
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ def test_get_map_paths(test_directory, make_files_structure):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_import_command(test_directory, mock_create_subprocess_shell):
|
||||
async def test_run_import_command(test_directory, mock_run_command, run_command_bad_result):
|
||||
"""
|
||||
Import map files. Files to import are checked for validity before importing. Any errors returned by
|
||||
asyncio.create_subprocess_shell are caught and reported.
|
||||
|
|
@ -38,22 +38,14 @@ async def test_run_import_command(test_directory, mock_create_subprocess_shell):
|
|||
dump_file = test_directory / 'dumpy.dump'
|
||||
dump_file.touch()
|
||||
|
||||
with mock.patch('modules.map.lib.asyncio') as mock_asyncio, \
|
||||
mock.patch('modules.map.lib.is_pbf_file') as mock_is_pbf_file:
|
||||
with mock.patch('modules.map.lib.is_pbf_file') as mock_is_pbf_file:
|
||||
# Run the import, it succeeds.
|
||||
mock_asyncio.create_subprocess_shell = mock_create_subprocess_shell(
|
||||
communicate_return=(b'out', b'error')
|
||||
)
|
||||
mock_is_pbf_file.return_value = True
|
||||
await lib.run_import_command(pbf_file)
|
||||
|
||||
with mock.patch('modules.map.lib.asyncio') as mock_asyncio, \
|
||||
mock.patch('modules.map.lib.is_pbf_file') as mock_is_pbf_file:
|
||||
with mock.patch('modules.map.lib.is_pbf_file') as mock_is_pbf_file:
|
||||
# Run the import, it fails.
|
||||
mock_asyncio.create_subprocess_shell = mock_create_subprocess_shell(
|
||||
communicate_return=(b'out', b'error'),
|
||||
return_code=1,
|
||||
)
|
||||
mock_run_command(run_command_bad_result)
|
||||
mock_is_pbf_file.return_value = True
|
||||
with pytest.raises(ValueError):
|
||||
await lib.run_import_command(pbf_file)
|
||||
|
|
@ -102,7 +94,7 @@ def test_seconds_to_import_rpi5(size, expected):
|
|||
assert lib.seconds_to_import(size, True) == expected
|
||||
|
||||
|
||||
def test_get_custom_map_directory(test_directory, test_wrolpi_config):
|
||||
def test_get_custom_map_directory(async_client, test_directory, test_wrolpi_config):
|
||||
"""Custom directory can be used for map directory."""
|
||||
# Default location.
|
||||
assert lib.get_map_directory() == (test_directory / 'map')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue