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

Return URL by .make_url() testing utility #1279

Merged
merged 2 commits into from
Sep 30, 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
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CHANGES

- Accept `yarl.URL` by server redirections #1278

-
- Return `yarl.URL` by `.make_url()` testing utility #1279

-

Expand Down
13 changes: 11 additions & 2 deletions aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from unittest import mock

from multidict import CIMultiDict
from yarl import URL

import aiohttp

Expand Down Expand Up @@ -54,14 +55,22 @@ def start_server(self, **kwargs):
if self.server:
return
self.port = unused_port()
self._root = '{}://{}:{}'.format(self.scheme, self.host, self.port)
self._root = URL('{}://{}:{}'.format(self.scheme,
self.host,
self.port))
self.handler = self.app.make_handler(**kwargs)
self.server = yield from self._loop.create_server(self.handler,
self.host,
self.port)

def make_url(self, path):
return self._root + path
assert path.startswith('/')
path = path[1:]
if path.startswith('?'):
# add a query to root path
return self._root.with_query(path[1:])
else:
return self._root / path

@asyncio.coroutine
def close(self):
Expand Down