aiohttp.__file__

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 7

Example 1

Project: aiohttp
License: View license
Source File: test_urldispatch.py
@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

Example 2

Project: aiohttp
License: View license
Source File: test_urldispatch.py
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

Example 3

Project: aiohttp
License: View license
Source File: test_urldispatch.py
@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

Example 4

Project: aiohttp
License: View license
Source File: test_urldispatch.py
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)

Example 5

Project: aiohttp
License: View license
Source File: test_urldispatch.py
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']

Example 6

Project: aiohttp
License: View license
Source File: test_urldispatch.py
@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

Example 7

Project: aiohttp
License: View license
Source File: test_urldispatch.py
@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

Example 8

Project: aiohttp
License: View license
Source File: test_urldispatch.py
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())

Example 9

Project: aiohttp
License: View license
Source File: test_urldispatch.py
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']))

Example 10

Project: aiohttp
License: View license
Source File: test_urldispatch.py
def test_static_adds_slash(router):
    route = router.add_static('/prefix',
                              os.path.dirname(aiohttp.__file__))
    assert '/prefix/' == route._prefix

Example 11

Project: aiohttp
License: View license
Source File: test_urldispatch.py
def test_static_dont_add_trailing_slash(router):
    route = router.add_static('/prefix/',
                              os.path.dirname(aiohttp.__file__))
    assert '/prefix/' == route._prefix

Example 12

Project: aiohttp
License: View license
Source File: test_urldispatch.py
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/'}

Example 13

Project: aiohttp
License: View license
Source File: test_urldispatch.py
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)

Example 14

Project: aiohttp
License: View license
Source File: test_urldispatch.py
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')

Example 15

Project: aiohttp
License: View license
Source File: test_urldispatch.py
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'))