Tests: added tests for "index" (string) option.

This commit is contained in:
Alejandro Colomar
2022-02-21 23:02:51 +01:00
parent 9af5f36951
commit 8027e7ce0f

View File

@@ -87,6 +87,22 @@ class TestStatic(TestApplicationProto):
assert self.get(url='/')['body'] == '0123456789', 'before 1.26.0 2' assert self.get(url='/')['body'] == '0123456789', 'before 1.26.0 2'
def test_static_index(self): def test_static_index(self):
def set_index(index):
assert 'success' in self.conf(
{"share": option.temp_dir + "/assets$uri", "index": index},
'routes/0/action',
), 'configure index'
set_index('README')
assert self.get()['body'] == 'readme', 'index'
self.conf_delete('routes/0/action/index')
assert self.get()['body'] == '0123456789', 'delete index'
set_index('')
assert self.get()['status'] == 404, 'index empty'
def test_static_index_default(self):
assert self.get(url='/index.html')['body'] == '0123456789', 'index' assert self.get(url='/index.html')['body'] == '0123456789', 'index'
assert self.get(url='/')['body'] == '0123456789', 'index 2' assert self.get(url='/')['body'] == '0123456789', 'index 2'
assert self.get(url='//')['body'] == '0123456789', 'index 3' assert self.get(url='//')['body'] == '0123456789', 'index 3'
@@ -102,6 +118,18 @@ class TestStatic(TestApplicationProto):
resp['headers']['Content-Type'] == 'text/html' resp['headers']['Content-Type'] == 'text/html'
), 'index not found 2 Content-Type' ), 'index not found 2 Content-Type'
def test_static_index_invalid(self, skip_alert):
skip_alert(r'failed to apply new conf')
def check_index(index):
assert 'error' in self.conf(
{"share": option.temp_dir + "/assets$uri", "index": index},
'routes/0/action',
)
check_index({})
check_index(['index.html', '$blah'])
def test_static_large_file(self, temp_dir): def test_static_large_file(self, temp_dir):
file_size = 32 * 1024 * 1024 file_size = 32 * 1024 * 1024
with open(temp_dir + '/assets/large', 'wb') as f: with open(temp_dir + '/assets/large', 'wb') as f: