collective.redismemoize.testing#
Test layers and helpers for add-ons.
Test layers, and helpers to test an add-on against a fake Redis.
REDIS_MEMOIZE_FIXTURE is for add-on authors: put it in a layer's
bases and every @ram.cache function goes through this package, backed by
an in-process fakeredis server instead of a real Redis. Each test starts
with an empty prefix, an empty RAM cache, a closed breaker and no learned
routes. fakeredis is not a dependency of this package; add it to your
test extra.
activate() and deactivate() are the same thing for a test runner
without layers, such as a plain pytest fixture.
- collective.redismemoize.testing.TEST_ENVIRON = {'REDIS_MEMOIZE_PREFIX': 'test.memoize', 'REDIS_MEMOIZE_URL': 'redis://fakeredis:6379/0'}#
What
activate()sets unless told otherwise. The URL is never contacted: the client factory is replaced byfakeredis.
- collective.redismemoize.testing.activate(server=None, **variables)[source]#
Point the package at a
fakeredisserver.- Parameters:
server (Any) -- A
fakeredis.FakeServer; a new one when omitted.variables (str) --
REDIS_MEMOIZE_*variables to set on top ofTEST_ENVIRON.
- Returns:
The server.
- Return type:
- collective.redismemoize.testing.deactivate()[source]#
Restore the environment
activate()changed, and reset the state.- Return type:
None
- collective.redismemoize.testing.clean()[source]#
Empty the prefix and the RAM cache, close the breaker, forget routes.
- Return type:
None
- class collective.redismemoize.testing.RedisMemoizeLayer[source]#
Bases:
LayerRoute
plone.memoizethrough this package and a fake Redis.Loads the package's
overrides.zcmlinto a stacked component registry, so the chooser is in place even in a layer that never loaded this package's ZCML.- defaultBases = (plone.testing.zca.ZCML_DIRECTIVES,)#
- testSetUp()[source]#
Start every test from an empty cache, with this package's chooser.
The registry stacked in
setUp()is not always the one a test sees. A Plone site's component registry is based on the global registry of the moment the site was created, so for a layer such asPLONE_FIXTURE, set up before or after this one, the stock chooserplone.memoizeregistered there wins. For the duration of each test, every registry in the global chain that registers another chooser gets this package's one instead.- Return type:
None
- testTearDown()[source]#
Put back the choosers
testSetUp()replaced.- Return type:
None