1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Tests for CherryPy web server setup and its components.
"""
from unittest.mock import call, patch
import pytest
from plinth.web_server import StaticFiles
@pytest.fixture(autouse=True)
def fixture_cleanup_static_files():
"""Ensure that global list of static files is clean."""
StaticFiles._all_instances = {}
def test_static_files_init():
"""Test that static files component is being initialized correctly."""
component = StaticFiles('test-component')
assert component.component_id == 'test-component'
assert component.directory_map is None
directory_map = {'/a': '/b'}
component = StaticFiles('test-component', directory_map)
assert component.directory_map == directory_map
def test_static_files_list():
"""Test that static files components can be listed properly."""
component1 = StaticFiles('test-component1')
component2 = StaticFiles('test-component2')
assert set(StaticFiles.list()) == {component1, component2}
@patch('cherrypy.tree.mount')
def test_static_files_mount(mount, load_cfg):
"""Test that mounting on CherryPy works as expected."""
directory_map = {'/a': '/b', '/c': '/d'}
component = StaticFiles('test-component', directory_map)
component.mount()
calls = [
call(
None, '/plinth/a', {
'/': {
'tools.staticdir.root': '/b',
'tools.staticdir.on': True,
'tools.staticdir.dir': '.'
}
}),
call(
None, '/plinth/c', {
'/': {
'tools.staticdir.root': '/d',
'tools.staticdir.on': True,
'tools.staticdir.dir': '.'
}
})
]
mount.assert_has_calls(calls)
|