-
Notifications
You must be signed in to change notification settings - Fork 506
/
static_files_test.py
40 lines (29 loc) · 1.96 KB
/
static_files_test.py
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
import pytest
import tornado
from voila.static_file_handler import TemplateStaticFileHandler
async def test_static_file_absolute_path(app, base_url, http_server_client):
response_lab = await http_server_client.fetch(f'{base_url}voila/templates/lab/static/voila.js')
assert response_lab.code == 200
abspath = TemplateStaticFileHandler.get_absolute_path(None, 'lab/static/voila.js')
with open(abspath, encoding='utf-8', errors='replace') as f:
content = f.read()
assert response_lab.body.decode('utf-8') == content
async def test_static_file_not_found(app, base_url, http_server_client):
with pytest.raises(tornado.httpclient.HTTPClientError, match='HTTP 404.*'):
await http_server_client.fetch(f'{base_url}voila/templates/lab/static/doesnotexist.js')
async def test_static_file_availability_default(app, base_url, http_server_client):
response_lab = await http_server_client.fetch(f'{base_url}voila/templates/lab/static/voila.js')
response_default = await http_server_client.fetch(f'{base_url}voila/static/voila.js')
assert response_lab.code == 200
assert response_default.code == 200
assert response_lab.body.decode('utf-8') == response_default.body.decode('utf-8')
async def test_static_file_override(app, base_url, http_server_client):
response_lab = await http_server_client.fetch(f'{base_url}voila/templates/lab/static/voila.js')
response_test_template = await http_server_client.fetch(f'{base_url}voila/templates/test_template/static/voila.js')
assert response_lab.code == 200
assert response_test_template.code == 200
assert response_lab.body.decode('utf-8') != response_test_template.body.decode('utf-8')
async def test_static_file_other_template(app, base_url, http_server_client):
response = await http_server_client.fetch(f'{base_url}voila/templates/test_template/static/only-in-test-template.js')
assert response.code == 200
assert response.body.decode('utf-8') == '', "empty file expected"