Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion test/test_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import tempfile
import unittest
from bottle import ConfigDict
Expand Down Expand Up @@ -167,7 +168,7 @@ class TestINIConfigLoader(unittest.TestCase):
@classmethod
def setUpClass(self):
self.config_file = tempfile.NamedTemporaryFile(suffix='.example.ini',
delete=True)
delete=False)
self.config_file.write(b'[DEFAULT]\n'
b'default: 45\n'
b'[bottle]\n'
Expand All @@ -184,6 +185,7 @@ def setUpClass(self):
@classmethod
def tearDownClass(self):
self.config_file.close()
os.unlink(self.config_file.name)

def test_load_config(self):
c = ConfigDict()
Expand Down
53 changes: 37 additions & 16 deletions test/test_resources.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
from bottle import ResourceManager
import os.path
import sys
import unittest
from bottle import ResourceManager

if sys.platform == 'win32':
TEST_PATHS = ('C:\\foo\\bar\\', 'C:\\foo\\bar\\baz', 'C:\\foo\\baz\\..\\bar\\blub')
EXPECTED = ['C:\\foo\\bar\\']
else:
TEST_PATHS = ('/foo/bar/', '/foo/bar/baz', '/foo/baz/../bar/blub')
EXPECTED = ['/foo/bar/']


class TestResourceManager(unittest.TestCase):

def test_path_normalize(self):
tests = ('/foo/bar/', '/foo/bar/baz', '/foo/baz/../bar/blub')
for test in tests:
for test in TEST_PATHS:
rm = ResourceManager()
rm.add_path(test)
self.assertEqual(rm.path, ['/foo/bar/'])
self.assertEqual(rm.path, EXPECTED)

def test_path_create(self):
import tempfile, shutil
import shutil
import tempfile
tempdir = tempfile.mkdtemp()
try:
rm = ResourceManager()
Expand All @@ -24,8 +33,13 @@ def test_path_create(self):
shutil.rmtree(tempdir)

def test_path_absolutize(self):
tests = ('./foo/bar/', './foo/bar/baz', './foo/baz/../bar/blub')
abspath = os.path.abspath('./foo/bar/') + os.sep
if sys.platform == 'win32':
tests = ('.\\foo\\bar\\', '.\\foo\\bar\\baz', '.\\foo\\baz\\..\\bar\\blub')
abspath = os.path.abspath('.\\foo\\bar\\') + os.sep
else:
tests = ('./foo/bar/', './foo/bar/baz', './foo/baz/../bar/blub')
abspath = os.path.abspath('./foo/bar/') + os.sep

for test in tests:
rm = ResourceManager()
rm.add_path(test)
Expand All @@ -37,29 +51,36 @@ def test_path_absolutize(self):
self.assertEqual(rm.path, [abspath])

def test_path_unique(self):
tests = ('/foo/bar/', '/foo/bar/baz', '/foo/baz/../bar/blub')
rm = ResourceManager()
[rm.add_path(test) for test in tests]
self.assertEqual(rm.path, ['/foo/bar/'])
[rm.add_path(test) for test in TEST_PATHS]
self.assertEqual(rm.path, EXPECTED)

def test_root_path(self):
tests = ('/foo/bar/', '/foo/bar/baz', '/foo/baz/../bar/blub')
for test in tests:
if sys.platform == 'win32':
expected = ['C:\\foo\\bar\\baz\\']
else:
expected = ['/foo/bar/baz/']

for test in TEST_PATHS:
rm = ResourceManager()
rm.add_path('./baz/', test)
self.assertEqual(rm.path, ['/foo/bar/baz/'])
self.assertEqual(rm.path, expected)

for test in tests:
for test in TEST_PATHS:
rm = ResourceManager()
rm.add_path('baz/', test)
self.assertEqual(rm.path, ['/foo/bar/baz/'])
self.assertEqual(rm.path, expected)

def test_path_order(self):
rm = ResourceManager()
rm.add_path('/middle/')
rm.add_path('/first/', index=0)
rm.add_path('/last/')
self.assertEqual(rm.path, ['/first/', '/middle/', '/last/'])

if sys.platform == 'win32':
self.assertEqual(rm.path, ['C:\\first\\', 'C:\\middle\\', 'C:\\last\\'])
else:
self.assertEqual(rm.path, ['/first/', '/middle/', '/last/'])

def test_get(self):
rm = ResourceManager()
Expand Down
4 changes: 4 additions & 0 deletions test/test_sendfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import unittest
from bottle import static_file, request, response, parse_date, parse_range_header, Bottle, tob
import bottle
Expand Down Expand Up @@ -63,6 +64,8 @@ def test_invalid(self):
self.assertEqual(403, f.status_code)

def test_file_not_readable(self):
if sys.platform == 'win32':
return
if os.geteuid() == 0:
return # Root can read anything

Expand All @@ -89,6 +92,7 @@ def test_mime_gzip(self):
""" SendFile: Mime Guessing"""
try:
fp, fn = tempfile.mkstemp(suffix=".txt.gz")
os.close(fp) # File needs to be closed before it can be accessed on Windows
f = static_file(fn, root='/')
self.assertTrue(f.headers['Content-Type'][0] in ('application/gzip'))
self.assertFalse('Content-Encoding' in f.headers)
Expand Down