def test_static_url_noscheme_uses_scheme_from_request(self): from pyramid.interfaces import IStaticURLInfo from pyramid.config.views import StaticURLInfo info = StaticURLInfo() here = os.path.abspath(os.path.dirname(__file__)) info.add(self.config, '//subdomain.example.com/static', here) request = self._makeOne({'wsgi.url_scheme': 'https'}) registry = request.registry registry.registerUtility(info, IStaticURLInfo) abspath = os.path.join(here, 'test_url.py') result = request.static_url(abspath) self.assertEqual(result, 'https://subdomain.example.com/static/test_url.py')
def test_static_url_abspath_integration_with_staticurlinfo(self): from pyramid.interfaces import IStaticURLInfo from pyramid.config.views import StaticURLInfo info = StaticURLInfo() here = os.path.abspath(os.path.dirname(__file__)) info.add(self.config, 'absstatic', here) request = self._makeOne() registry = request.registry registry.registerUtility(info, IStaticURLInfo) abspath = os.path.join(here, 'test_url.py') result = request.static_url(abspath) self.assertEqual(result, 'http://example.com:5432/absstatic/test_url.py')
def get_static_dir(request): registrations = set(StaticURLInfo()._get_registrations(request.registry)) registrations = registrations - set([(None, 'pyramid_debugtoolbar:static/', '___debug_toolbar/static/'), (None, 'pyramid_promosite:static/', '__static/')]) static_dir = list(registrations) if static_dir: static_dir = static_dir[0][2][2:] else: static_dir = 'static/' return static_dir