def test_sets_backend_for_regions(empty_config):
    configure_dogpile_cache({
        'dogpile_cache.regions': 'foo, bar',
        'dogpile_cache.backend': 'dogpile.cache.memory',
        'dogpile_cache.expiration_time': '1',
    })
    assert isinstance(get_region('foo').backend, MemoryBackend)
    assert isinstance(get_region('bar').backend, MemoryBackend)
def test_unconfigured_region_raises(empty_config):
    get_region('bar')
    with pytest.raises(dogpile.cache.exception.RegionNotConfigured):
        configure_dogpile_cache({
            'dogpile_cache.regions': 'foo',
            'dogpile_cache.backend': 'dogpile.cache.memory',
            'dogpile_cache.expiration_time': '1',
        })
def test_converts_expiration_time_to_int(empty_config):
    configure_dogpile_cache({
        'dogpile_cache.regions': 'foo',
        'dogpile_cache.backend': 'dogpile.cache.memory',
        'dogpile_cache.expiration_time': '1',
    })
    assert get_region('foo').expiration_time == 1
def test_sets_pylibmc_behaviours(empty_config, monkeypatch):
    monkeypatch.setattr(
        dogpile.cache.backends.memcached.PylibmcBackend, '_imports',
        lambda self: None)
    configure_dogpile_cache({
        'dogpile_cache.regions': 'foo',
        'dogpile_cache.backend': 'dogpile.cache.pylibmc',
        'dogpile_cache.pylibmc_url': 'http://localhost:8899',
        'dogpile_cache.expiration_time': '1',
        'dogpile_cache.pylibmc_behavior.send_timeout': '5',
    })
    assert get_region('foo').backend.behaviors == {'send_timeout': 5}
def test_methods_are_detected_when_decorated(empty_config):
    region = get_region('test')
    region.configure('dogpile.cache.memory')

    class Foo(object):

        @region.cache_on_arguments()
        def method(self):
            return 42

    Foo().method()
    assert region.get('pyramid_dogpile_cache2.tests.test_cache.Foo.method|') == 42
def test_sets_memcache_expire_time_to_later_than_expiration_time(
        empty_config, monkeypatch):
    monkeypatch.setattr(
        dogpile.cache.backends.memcached.PylibmcBackend, '_imports',
        lambda self: None)
    configure_dogpile_cache({
        'dogpile_cache.regions': 'foo',
        'dogpile_cache.backend': 'dogpile.cache.pylibmc',
        'dogpile_cache.pylibmc_url': 'http://localhost:8899',
        'dogpile_cache.expiration_time': '1',
        'dogpile_cache.memcache_expire_time_interval': '5'
    })
    assert get_region('foo').backend.memcached_expire_time == 6
Exemple #7
0
class ClearFanstaticOnError(object):
    """In debug mode, removes any application CSS on error, so as not to clash
    with the CSS of werkzeug debugger.
    """
    def __init__(self, app):
        self.app = app

    def __call__(self, environ, start_response):
        try:
            return self.app(environ, start_response)
        except Exception:
            fanstatic.clear_needed()
            raise


CONFIG_CACHE = pyramid_dogpile_cache2.get_region('config')


def zope_shell():
    if len(sys.argv) < 2:
        sys.stderr.write('Usage: %s paste.ini\n' % sys.argv[0])
        sys.exit(1)
    paste_ini = sys.argv[1]
    logging.config.fileConfig(
        paste_ini, {
            '__file__': paste_ini,
            'here': os.path.abspath(os.path.dirname(paste_ini))
        })
    config = ConfigParser()
    config.read(paste_ini)
    # XXX How to get to zope.conf is the only-application specific part.
Exemple #8
0
QPS_SCHEMA_NS = u"http://namespaces.zeit.de/QPS/attributes"
ID_NAMESPACE = u'http://xml.zeit.de/'
TEASER_NAMESPACE = u'http://xml.zeit.de/CMS/Teaser'
PRINT_NAMESPACE = u"http://namespaces.zeit.de/CMS/print"
IR_NAMESPACE = u"http://namespaces.zeit.de/CMS/interred"

# lovely.remotetask stores times as 32 bit leading to an overflow after 2030.
MAX_PUBLISH_DATE = datetime.datetime(2030, 1, 1, tzinfo=pytz.UTC)

# Backward compatibility imports
from zeit.connector.interfaces import (  # noqa
    DeleteProperty, LockingError, IConnector, IResource,
    IWebDAVReadProperties, IWebDAVWriteProperties, IWebDAVProperties)


CONFIG_CACHE = pyramid_dogpile_cache2.get_region('config')
FEATURE_CACHE = pyramid_dogpile_cache2.get_region('feature')


class ICMSContentType(zope.interface.interfaces.IInterface):
    """Interface for content types."""


class InvalidName(zope.schema.ValidationError):
    __doc__ = _('Name contains invalid characters')


class ValidationError(zope.schema.ValidationError):

    def doc(self):
        return self.args[0]