Skip to content

Commit

Permalink
Return URL by .make_url() testing utility (#1279)
Browse files Browse the repository at this point in the history
* Return URL by .make_url() testing utility

* Update CHANGES
  • Loading branch information
asvetlov authored Sep 30, 2016
1 parent b85b4c2 commit 0e75f50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit 0e75f50

Please sign in to comment.