mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-03 15:59:18 +02:00
Fix #879: Admins can now add custom CSS from their pod settings
This commit is contained in:
parent
78ab153734
commit
7897c8ac7f
5 changed files with 84 additions and 1 deletions
|
@ -141,3 +141,47 @@ def test_get_route_head_tags(mocker, settings):
|
|||
assert tags == match.func.return_value
|
||||
match.func.assert_called_once_with(request, *[], **{"pk": 42})
|
||||
resolve.assert_called_once_with(request.path, urlconf=settings.SPA_URLCONF)
|
||||
|
||||
|
||||
def test_serve_spa_includes_custom_css(mocker, no_api_auth):
|
||||
request = mocker.Mock(path="/")
|
||||
mocker.patch.object(
|
||||
middleware,
|
||||
"get_spa_html",
|
||||
return_value="<html><head></head><body></body></html>",
|
||||
)
|
||||
mocker.patch.object(middleware, "get_default_head_tags", return_value=[])
|
||||
mocker.patch.object(middleware, "get_request_head_tags", return_value=[])
|
||||
get_custom_css = mocker.patch.object(
|
||||
middleware, "get_custom_css", return_value="body { background: black; }"
|
||||
)
|
||||
response = middleware.serve_spa(request)
|
||||
|
||||
assert response.status_code == 200
|
||||
expected = [
|
||||
"<html><head>\n\n</head><body>",
|
||||
"<style>body { background: black; }</style>",
|
||||
"</body></html>",
|
||||
]
|
||||
get_custom_css.assert_called_once_with()
|
||||
assert response.content == "\n".join(expected).encode()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"custom_css, expected",
|
||||
[
|
||||
("body { background: black; }", "body { background: black; }"),
|
||||
(
|
||||
"body { injection: </style> & Hello",
|
||||
"body { injection: </style> & Hello",
|
||||
),
|
||||
(
|
||||
'body { background: url("image/url"); }',
|
||||
'body { background: url("image/url"); }',
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_get_custom_css(preferences, custom_css, expected):
|
||||
preferences["ui__custom_css"] = custom_css
|
||||
|
||||
assert middleware.get_custom_css() == expected
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue