def test_static_route_path_existence_check(self): directory = os.path.dirname(__file__) web.StaticRoute(None, "/", directory) nodirectory = os.path.join(directory, "nonexistent-uPNiOEAg5d") with self.assertRaises(ValueError): web.StaticRoute(None, "/", nodirectory)
def get_static_route(url, directory): prefix = url.rsplit('/', 1)[0] or '/' if IS_BUNDLED: route = StaticRoute(None, prefix) else: route = web.StaticRoute(None, prefix, directory) return route
def test_env_nosendfile(self): directory = os.path.dirname(__file__) with mock.patch.dict(os.environ, {'AIOHTTP_NOSENDFILE': '1'}): route = web.StaticRoute(None, "/", directory) self.assertEqual(route._sendfile, route._sendfile_fallback)
from aiohttp import web from music.music_list import music_list, music_list_ajax import settings app = web.Application() app.router.add_static('/static/', settings.STATIC_DIR, name='static') route = web.StaticRoute(None, '/static/', settings.STATIC_DIR) route._method = 'HEAD' app.router.register_route(route) app.router.add_route('GET', '/', music_list) app.router.add_route('GET', '/music/ajax/', music_list_ajax) web.run_app(app)