Commits

Thomas Waldmann committed 2d49d04

remove old routing middleware + tests (everything is broken now)

Comments (0)

Files changed (2)

MoinMoin/storage/middleware/_tests/test_routing.py

-# Copyright: 2011 MoinMoin:ThomasWaldmann
-# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
-
-"""
-MoinMoin - router middleware tests
-"""
-
-
-from __future__ import absolute_import, division
-
-from StringIO import StringIO
-
-import pytest
-
-from MoinMoin.config import NAME, REVID
-
-from ..routing import Backend as RouterBackend
-
-from MoinMoin.storage.backends.stores import MutableBackend as StoreBackend, Backend as ROBackend
-from MoinMoin.storage.stores.memory import BytesStore as MemoryBytesStore
-from MoinMoin.storage.stores.memory import FileStore as MemoryFileStore
-
-
-def make_ro_backend():
-    store = StoreBackend(MemoryBytesStore(), MemoryFileStore())
-    store.create()
-    store.open()
-    store.store({NAME: 'test'}, StringIO(''))
-    store.store({NAME: 'test2'}, StringIO(''))
-    return ROBackend(store.meta_store, store.data_store)
-
-
-
-def pytest_funcarg__router(request):
-    root_be = StoreBackend(MemoryBytesStore(), MemoryFileStore())
-    sub_be = StoreBackend(MemoryBytesStore(), MemoryFileStore())
-    ro_be = make_ro_backend()
-    router = RouterBackend([('sub', sub_be), ('ro', ro_be), ('', root_be)])
-    router.create()
-    router.open()
-
-    @request.addfinalizer
-    def finalize():
-        router.close()
-        router.destroy()
-
-    return router
-
-def test_store_get_del(router):
-    root_name = u'foo'
-    root_revid = router.store(dict(name=root_name), StringIO(''))
-    sub_name = u'sub/bar'
-    sub_revid = router.store(dict(name=sub_name), StringIO(''))
-
-    # when going via the router backend, we get back fully qualified names:
-    root_meta, _ = router.retrieve(root_name, root_revid)
-    sub_meta, _ = router.retrieve(sub_name, sub_revid)
-    assert root_name == root_meta[NAME]
-    assert sub_name == sub_meta[NAME]
-
-    # when looking into the storage backend, we see relative names (without mountpoint):
-    root_meta, _ = router.mapping[-1][1].retrieve(root_revid)
-    sub_meta, _ = router.mapping[0][1].retrieve(sub_revid)
-    assert root_name == root_meta[NAME]
-    assert sub_name == 'sub' + '/' + sub_meta[NAME]
-    # delete revs:
-    router.remove(root_name, root_revid)
-    router.remove(sub_name, sub_revid)
-
-
-def test_store_readonly_fails(router):
-    with pytest.raises(TypeError):
-        router.store(dict(name=u'ro/testing'), StringIO(''))
-
-def test_del_readonly_fails(router):
-    ro_id = next(iter(router)) # we have only readonly items
-    print ro_id
-    with pytest.raises(TypeError):
-        router.remove(ro_id)
-
-
-def test_destroy_create_dont_touch_ro(router):
-    existing = set(router)
-    root_revid = router.store(dict(name=u'foo'), StringIO(''))
-    sub_revid = router.store(dict(name=u'sub/bar'), StringIO(''))
-
-    router.close()
-    router.destroy()
-    router.create()
-    router.open()
-
-    assert set(router) == existing
-
-
-def test_iter(router):
-    existing_before = set([revid for mountpoint, revid in router])
-    root_revid = router.store(dict(name=u'foo'), StringIO(''))
-    sub_revid = router.store(dict(name=u'sub/bar'), StringIO(''))
-    existing_now = set([revid for mountpoint, revid in router])
-    assert existing_now == set([root_revid, sub_revid]) | existing_before
-

MoinMoin/storage/middleware/routing.py

-# Copyright: 2008-2011 MoinMoin:ThomasWaldmann
-# Copyright: 2011 MoinMoin:RonnyPfannschmidt
-# Copyright: 2009 MoinMoin:ChristopherDenter
-# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
-
-"""
-MoinMoin - routing middleware
-
-Routes requests to different backends depending on the item name.
-
-Just think of UNIX filesystems, fstab and mount.
-
-This middleware lets you mount backends that store items belonging to some
-specific part of the namespace. Routing middleware has same API as a backend.
-"""
-
-
-from __future__ import absolute_import, division
-
-from MoinMoin.config import NAME
-
-from MoinMoin.storage.backends import BackendBase, MutableBackendBase
-
-
-class Backend(MutableBackendBase):
-    """
-    router, behaves readonly for readonly mounts
-    """
-    def __init__(self, mapping):
-        """
-        Initialize router backend.
-
-        The mapping given must satisfy the following criteria:
-            * Order matters.
-            * Mountpoints are just item names, including the special '' (empty)
-              root item name.
-            * Trailing '/' of a mountpoint will be stripped.
-            * There *must* be a backend with mountpoint '' at the very
-              end of the mapping. That backend is then used as root, which means
-              that all items that don't lie in the namespace of any other
-              backend are stored there.
-
-        :type mapping: list of tuples of mountpoint -> backend mappings
-        :param mapping: [(mountpoint, backend), ...]
-        """
-        self.mapping = [(mountpoint.rstrip('/'), backend) for mountpoint, backend in mapping]
-
-    def open(self):
-        for mountpoint, backend in self.mapping:
-            backend.open()
-
-    def close(self):
-        for mountpoint, backend in self.mapping:
-            backend.close()
-
-    def _get_backend(self, itemname):
-        """
-        For a given fully-qualified itemname (i.e. something like Company/Bosses/Mr_Joe)
-        find the backend it belongs to (given by this instance's mapping), the local
-        itemname inside that backend and the mountpoint of the backend.
-
-        :param itemname: fully-qualified itemname
-        :returns: tuple of (backend, local itemname, mountpoint)
-        """
-        for mountpoint, backend in self.mapping:
-            if itemname == mountpoint or itemname.startswith(mountpoint and mountpoint + '/' or ''):
-                lstrip = mountpoint and len(mountpoint)+1 or 0
-                return backend, itemname[lstrip:], mountpoint
-        raise AssertionError("No backend found for {0!r}. Available backends: {1!r}".format(itemname, self.mapping))
-
-    def __iter__(self):
-        # Note: yields <backend_mountpoint>/<backend_revid> as router revid, so that this
-        #       can be given to get_revision and be routed to the right backend.
-        for mountpoint, backend in self.mapping:
-            for revid in backend:
-                yield (mountpoint, revid)
-
-    def retrieve(self, name, revid):
-        backend, _, mountpoint = self._get_backend(name)
-        meta, data = backend.retrieve(revid)
-        if mountpoint:
-            name = meta[NAME]
-            if name:
-                meta[NAME] = u'{0}/{1}'.format(mountpoint, meta[NAME])
-            else:
-                meta[NAME] = mountpoint # no trailing slash!
-        return meta, data
-
-    # writing part
-    def create(self):
-        for mountpoint, backend in self.mapping:
-            if isinstance(backend, MutableBackendBase):
-                backend.create()
-            #XXX else: log info?
-
-    def destroy(self):
-        for mountpoint, backend in self.mapping:
-            if isinstance(backend, MutableBackendBase):
-                backend.destroy()
-            #XXX else: log info?
-
-    def store(self, meta, data):
-        mountpoint_itemname = meta[NAME]
-        backend, itemname, mountpoint = self._get_backend(mountpoint_itemname)
-        if not isinstance(backend, MutableBackendBase):
-            raise TypeError('backend {0!r} mounted at {1!r} is readonly'.format(backend, mountpoint))
-        meta[NAME] = itemname
-        revid = backend.store(meta, data)
-        meta[NAME] = mountpoint_itemname # restore the original name
-        return revid
-
-    def remove(self, name, revid):
-        backend, _, mountpoint = self._get_backend(name)
-        if not isinstance(backend, MutableBackendBase):
-            raise TypeError('backend {0!r} mounted at {1!r} is readonly'.format(backend, mountpoint))
-        backend.remove(revid)
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.