Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 782 #783

Merged
merged 4 commits into from
Feb 16, 2016
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
5 changes: 4 additions & 1 deletion aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ def __init__(self, name, prefix, directory, *,
self._prefix = prefix
self._prefix_len = len(self._prefix)
try:
directory = Path(directory).resolve()
directory = Path(directory)
if str(directory).startswith('~'):
directory = Path(os.path.expanduser(str(directory)))
directory = directory.resolve()
if not directory.is_dir():
raise ValueError('Not a directory')
except (FileNotFoundError, ValueError) as error:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_urldispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,3 +874,17 @@ def test_resources_abc(self):
self.assertIsInstance(self.router.resources(), Sized)
self.assertIsInstance(self.router.resources(), Iterable)
self.assertIsInstance(self.router.resources(), Container)

def test_static_route_user_home(self):
here = pathlib.Path(aiohttp.__file__).parent
home = pathlib.Path(os.path.expanduser('~'))
if not str(here).startswith(str(home)): # pragma: no cover
self.skipTest("aiohttp folder is not placed in user's HOME")
static_dir = '~/' + str(here.relative_to(home))
route = self.router.add_static('/st', static_dir)
self.assertEqual(here, route.get_info()['directory'])

def test_static_route_points_to_file(self):
here = pathlib.Path(aiohttp.__file__).parent / '__init__.py'
with self.assertRaises(ValueError):
self.router.add_static('/st', here)