From b29429e470c093573f3735b0dbf09d42c29cfe4d Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Fri, 2 Jul 2010 01:47:47 +0000 Subject: - The ``repoze.bfg.url.route_url`` API has changed. If a keyword ``_app_url`` is present in the arguments passed to ``route_url``, this value will be used as the protocol/hostname/port/leading path prefix of the generated URL. For example, using an ``_app_url`` of ``http://example.com:8080/foo`` would cause the URL ``http://example.com:8080/foo/fleeb/flub`` to be returned from this function if the expansion of the route pattern associated with the ``route_name`` expanded to ``/fleeb/flub``. - It is now possible to use a URL as the ``name`` argument fed to ``repoze.bfg.configuration.Configurator.add_static_view``. When the name argument is a URL, the ``repoze.bfg.url.static_url`` API will generate join this URL (as a prefix) to a path including the static file name. This makes it more possible to put static media on a separate webserver for production, while keeping static media package-internal and served by the development webserver during development. --- repoze/bfg/tests/test_configuration.py | 60 +++++++++++++++++----------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'repoze/bfg/tests/test_configuration.py') diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py index 16b590cdd..4762ed416 100644 --- a/repoze/bfg/tests/test_configuration.py +++ b/repoze/bfg/tests/test_configuration.py @@ -1699,59 +1699,52 @@ class ConfiguratorTests(unittest.TestCase): self.assertEqual(overrides.inserted, [('path', 'opackage', 'oprefix')]) self.assertEqual(overrides.package, package) - def test_add_static_view_here_relative(self): + def test_add_static_here_no_utility_registered(self): from repoze.bfg.static import PackageURLParser from zope.interface import implementedBy - from repoze.bfg.static import StaticRootFactory + from repoze.bfg.static import StaticURLInfo from repoze.bfg.interfaces import IView from repoze.bfg.interfaces import IViewClassifier config = self._makeOne() config.add_static_view('static', 'fixtures/static') request_type = self._getRouteRequestIface(config, 'static') route = self._assertRoute(config, 'static', 'static*subpath') - self.assertEqual(route.factory.__class__, StaticRootFactory) - iface = implementedBy(StaticRootFactory) + self.assertEqual(route.factory.__class__, type(lambda x: x)) + iface = implementedBy(StaticURLInfo) wrapped = config.registry.adapters.lookup( (IViewClassifier, request_type, iface), IView, name='') request = self._makeRequest(config) self.assertEqual(wrapped(None, request).__class__, PackageURLParser) def test_add_static_view_package_relative(self): - from repoze.bfg.static import PackageURLParser - from zope.interface import implementedBy - from repoze.bfg.static import StaticRootFactory - from repoze.bfg.interfaces import IView - from repoze.bfg.interfaces import IViewClassifier + from repoze.bfg.interfaces import IStaticURLInfo + info = DummyStaticURLInfo() config = self._makeOne() + config.registry.registerUtility(info, IStaticURLInfo) config.add_static_view('static', 'repoze.bfg.tests:fixtures/static') - request_type = self._getRouteRequestIface(config, 'static') - route = self._assertRoute(config, 'static', 'static*subpath') - self.assertEqual(route.factory.__class__, StaticRootFactory) - iface = implementedBy(StaticRootFactory) - wrapped = config.registry.adapters.lookup( - (IViewClassifier, request_type, iface), IView, name='') - request = self._makeRequest(config) - self.assertEqual(wrapped(None, request).__class__, PackageURLParser) + self.assertEqual(info.added, + [('static', 'repoze.bfg.tests:fixtures/static', {})]) + + def test_add_static_view_package_here_relative(self): + from repoze.bfg.interfaces import IStaticURLInfo + info = DummyStaticURLInfo() + config = self._makeOne() + config.registry.registerUtility(info, IStaticURLInfo) + config.add_static_view('static', 'fixtures/static') + self.assertEqual(info.added, + [('static', 'repoze.bfg.tests:fixtures/static', {})]) def test_add_static_view_absolute(self): - from paste.urlparser import StaticURLParser import os - from zope.interface import implementedBy - from repoze.bfg.static import StaticRootFactory - from repoze.bfg.interfaces import IView - from repoze.bfg.interfaces import IViewClassifier + from repoze.bfg.interfaces import IStaticURLInfo + info = DummyStaticURLInfo() config = self._makeOne() + config.registry.registerUtility(info, IStaticURLInfo) here = os.path.dirname(__file__) static_path = os.path.join(here, 'fixtures', 'static') config.add_static_view('static', static_path) - request_type = self._getRouteRequestIface(config, 'static') - route = self._assertRoute(config, 'static', 'static*subpath') - self.assertEqual(route.factory.__class__, StaticRootFactory) - iface = implementedBy(StaticRootFactory) - wrapped = config.registry.adapters.lookup( - (IViewClassifier, request_type, iface), IView, name='') - request = self._makeRequest(config) - self.assertEqual(wrapped(None, request).__class__, StaticURLParser) + self.assertEqual(info.added, + [('static', static_path, {})]) def test_set_notfound_view(self): from zope.interface import implementedBy @@ -3661,3 +3654,10 @@ class DummyFactory(object): class DummyEvent: implements(IDummy) +class DummyStaticURLInfo: + def __init__(self): + self.added = [] + + def add(self, name, spec, **kw): + self.added.append((name, spec, kw)) + -- cgit v1.2.3