Here are the examples of the python api aiohttp.__file__ taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
15 Examples
3
Example 1
@pytest.fixture
def fill_routes(router):
def go():
route1 = router.add_route('GET', '/plain', make_handler())
route2 = router.add_route('GET', '/variable/{name}',
make_handler())
resource = router.add_static('/static',
os.path.dirname(aiohttp.__file__))
return [route1, route2] + list(resource)
return go
3
Example 2
def test_add_static(router):
resource = router.add_static('/st',
os.path.dirname(aiohttp.__file__),
name='static')
assert router['static'] is resource
url = resource.url(filename='/dir/a.txt')
assert '/st/dir/a.txt' == url
assert len(resource) == 2
3
Example 3
@asyncio.coroutine
def test_static_not_match(router):
router.add_static('/pre', os.path.dirname(aiohttp.__file__),
name='name')
resource = router['name']
ret = yield from resource.resolve(
make_mocked_request('GET', '/another/path'))
assert (None, set()) == ret
3
Example 4
def test_named_resources(router):
route1 = router.add_route('GET', '/plain', make_handler(),
name='route1')
route2 = router.add_route('GET', '/variable/{name}',
make_handler(), name='route2')
route3 = router.add_static('/static',
os.path.dirname(aiohttp.__file__),
name='route3')
names = {route1.name, route2.name, route3.name}
assert 3 == len(router.named_resources())
for name in names:
assert name in router.named_resources()
assert isinstance(router.named_resources()[name],
AbstractResource)
3
Example 5
def test_static_route_user_home(router):
here = pathlib.Path(aiohttp.__file__).parent
home = pathlib.Path(os.path.expanduser('~'))
if not str(here).startswith(str(home)): # pragma: no cover
pytest.skip("aiohttp folder is not placed in user's HOME")
static_dir = '~/' + str(here.relative_to(home))
route = router.add_static('/st', static_dir)
assert here == route.get_info()['directory']
3
Example 6
@asyncio.coroutine
def test_404_for_static_resource(router):
resource = router.add_static('/st',
os.path.dirname(aiohttp.__file__))
ret = yield from resource.resolve(
make_mocked_request('GET', '/unknown/path'))
assert (None, set()) == ret
3
Example 7
@asyncio.coroutine
def test_405_for_resource_adapter(router):
resource = router.add_static('/st',
os.path.dirname(aiohttp.__file__))
ret = yield from resource.resolve(
make_mocked_request('POST', '/st/abc.py'))
assert (None, {'HEAD', 'GET'}) == ret
3
Example 8
def test_set_options_route(router):
resource = router.add_static('/static',
os.path.dirname(aiohttp.__file__))
options = None
for route in resource:
if route.method == 'OPTIONS':
options = route
assert options is None
resource.set_options_route(make_handler())
for route in resource:
if route.method == 'OPTIONS':
options = route
assert options is not None
with pytest.raises(RuntimeError):
resource.set_options_route(make_handler())
0
Example 9
def test_static_repr(router):
router.add_static('/get', os.path.dirname(aiohttp.__file__),
name='name')
assert re.match(r"<StaticResource 'name' /get/", repr(router['name']))
0
Example 10
def test_static_adds_slash(router):
route = router.add_static('/prefix',
os.path.dirname(aiohttp.__file__))
assert '/prefix/' == route._prefix
0
Example 11
def test_static_dont_add_trailing_slash(router):
route = router.add_static('/prefix/',
os.path.dirname(aiohttp.__file__))
assert '/prefix/' == route._prefix
0
Example 12
def test_static_resource_get_info(router):
directory = pathlib.Path(aiohttp.__file__).parent
resource = router.add_static('/st', directory)
assert resource.get_info() == {'directory': directory,
'prefix': '/st/'}
0
Example 13
def test_static_route_points_to_file(router):
here = pathlib.Path(aiohttp.__file__).parent / '__init__.py'
with pytest.raises(ValueError):
router.add_static('/st', here)
0
Example 14
def test_url_for_in_static_resource(router):
resource = router.add_static('/static',
os.path.dirname(aiohttp.__file__))
assert URL('/static/file.txt') == resource.url_for(filename='file.txt')
0
Example 15
def test_url_for_in_static_resource_pathlib(router):
resource = router.add_static('/static',
os.path.dirname(aiohttp.__file__))
assert URL('/static/file.txt') == resource.url_for(
filename=pathlib.Path('file.txt'))