changeset 4833:50732c861ac2

Groups2009: ConfigDicts backend was introduced. Some class names refinements.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Sat, 04 Jul 2009 12:13:46 +0100
parents f83b7b0b59c4
children f8cc357576c3
files MoinMoin/datastruct/__init__.py MoinMoin/datastruct/backends/__init__.py MoinMoin/datastruct/backends/_tests/__init__.py MoinMoin/datastruct/backends/_tests/test_composite_groups.py MoinMoin/datastruct/backends/_tests/test_config_dicts.py MoinMoin/datastruct/backends/_tests/test_config_groups.py MoinMoin/datastruct/backends/_tests/test_wiki_dicts.py MoinMoin/datastruct/backends/_tests/test_wiki_groups.py MoinMoin/datastruct/backends/composite_groups.py MoinMoin/datastruct/backends/config_dicts.py MoinMoin/datastruct/backends/config_groups.py MoinMoin/datastruct/backends/wiki_dicts.py MoinMoin/datastruct/backends/wiki_groups.py
diffstat 13 files changed, 110 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/datastruct/__init__.py	Fri Jul 03 16:36:47 2009 +0100
+++ b/MoinMoin/datastruct/__init__.py	Sat Jul 04 12:13:46 2009 +0100
@@ -7,6 +7,7 @@
 """
 
 from MoinMoin.datastruct.backends.wiki_dicts import WikiDicts
+from MoinMoin.datastruct.backends.config_dicts import ConfigDicts
 from MoinMoin.datastruct.backends.wiki_groups import WikiGroups
 from MoinMoin.datastruct.backends.config_groups import ConfigGroups
 from MoinMoin.datastruct.backends.composite_groups import CompositeGroups
--- a/MoinMoin/datastruct/backends/__init__.py	Fri Jul 03 16:36:47 2009 +0100
+++ b/MoinMoin/datastruct/backends/__init__.py	Sat Jul 04 12:13:46 2009 +0100
@@ -113,7 +113,7 @@
                                                              self.member_groups)
 
 
-class BaseGroupBackend(object):
+class BaseGroupsBackend(object):
 
     def __init__(self, request):
         self.request = request
@@ -207,7 +207,7 @@
         return "<%r name=%r items=%r>" % (self.__class__, self.name, self._dict.items())
 
 
-class BaseDictBackend(object):
+class BaseDictsBackend(object):
 
     def __init__(self, request):
         self.request = request
--- a/MoinMoin/datastruct/backends/_tests/__init__.py	Fri Jul 03 16:36:47 2009 +0100
+++ b/MoinMoin/datastruct/backends/_tests/__init__.py	Sat Jul 04 12:13:46 2009 +0100
@@ -16,7 +16,7 @@
 from MoinMoin.datastruct import GroupDoesNotExistError
 
 
-class BackendTest(object):
+class GroupsBackendTest(object):
 
     test_groups = {u'EditorGroup': [u'AdminGroup', u'John', u'JoeDoe', u'Editor1', u'John'],
                    u'AdminGroup': [u'Admin1', u'Admin2', u'John'],
@@ -137,3 +137,26 @@
 
         assert not acl.may(request, u"Someone", "write")
 
+
+class DictsBackendTest(object):
+
+    dicts = {u'SomeTestDict': {u'First': u'first item',
+                            u'text with spaces': u'second item',
+                            u'Empty string': u'',
+                            u'Last': u'last item'}}
+
+    def test_getitem(self):
+        expected_dict = self.dicts[u'SomeTestDict']
+        dicts = self.request.dicts
+        test_dict = dicts[u'SomeTestDict']
+
+        assert len(test_dict) == len(expected_dict)
+        for key, value in expected_dict.items():
+            assert test_dict[key] == value
+
+    def test_contains(self):
+        dicts = self.request.dicts
+
+        assert u'SomeTestDict' in dicts
+        assert u'SomeNotExistingDict' not in dicts
+
--- a/MoinMoin/datastruct/backends/_tests/test_composite_groups.py	Fri Jul 03 16:36:47 2009 +0100
+++ b/MoinMoin/datastruct/backends/_tests/test_composite_groups.py	Sat Jul 04 12:13:46 2009 +0100
@@ -10,22 +10,22 @@
 
 from py.test import raises
 
-from MoinMoin.datastruct.backends._tests import BackendTest
+from MoinMoin.datastruct.backends._tests import GroupsBackendTest
 from MoinMoin.datastruct import ConfigGroups, CompositeGroups, GroupDoesNotExistError
 from MoinMoin._tests import wikiconfig
 from MoinMoin import security
 
 
-class TestConfigBackend(BackendTest):
+class TestCompositeGroupsBackend(GroupsBackendTest):
 
     class Config(wikiconfig.Config):
 
         def group_manager_init(self, request):
-            groups = BackendTest.test_groups
+            groups = GroupsBackendTest.test_groups
             return CompositeGroups(request, ConfigGroups(request, groups))
 
 
-class TestConfigGroup(object):
+class TestCompositeGroup(object):
 
     class Config(wikiconfig.Config):
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/datastruct/backends/_tests/test_config_dicts.py	Sat Jul 04 12:13:46 2009 +0100
@@ -0,0 +1,24 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - MoinMoin.backends.config_dicts tests
+
+    @copyright: 2009 by MoinMoin:DmitrijsMilajevs
+    @license: GNU GPL, see COPYING for details.
+"""
+
+from  MoinMoin.datastruct.backends._tests import DictsBackendTest
+from MoinMoin.datastruct import ConfigDicts
+from MoinMoin._tests import wikiconfig
+
+
+class TestConfigDictsBackend(DictsBackendTest):
+
+    class Config(wikiconfig.Config):
+
+        def dict_manager_init(self, request):
+            dicts = DictsBackendTest.dicts
+            return ConfigDicts(request, dicts)
+
+
+coverage_modules = ['MoinMoin.datastruct.backends.config_dicts']
+
--- a/MoinMoin/datastruct/backends/_tests/test_config_groups.py	Fri Jul 03 16:36:47 2009 +0100
+++ b/MoinMoin/datastruct/backends/_tests/test_config_groups.py	Sat Jul 04 12:13:46 2009 +0100
@@ -10,17 +10,17 @@
 
 """
 
-from  MoinMoin.datastruct.backends._tests import BackendTest
+from  MoinMoin.datastruct.backends._tests import GroupsBackendTest
 from MoinMoin.datastruct import ConfigGroups
 from MoinMoin._tests import wikiconfig
 
 
-class TestConfigBackend(BackendTest):
+class TestConfigGroupsBackend(GroupsBackendTest):
 
     class Config(wikiconfig.Config):
 
         def group_manager_init(self, request):
-            groups = BackendTest.test_groups
+            groups = GroupsBackendTest.test_groups
             return ConfigGroups(request, groups)
 
 
--- a/MoinMoin/datastruct/backends/_tests/test_wiki_dicts.py	Fri Jul 03 16:36:47 2009 +0100
+++ b/MoinMoin/datastruct/backends/_tests/test_wiki_dicts.py	Sat Jul 04 12:13:46 2009 +0100
@@ -4,15 +4,17 @@
 
     @copyright: 2003-2004 by Juergen Hermann <jh@web.de>,
                 2007 by MoinMoin:ThomasWaldmann
+                2009 by MoinMoin:DmitrijsMilajevs
     @license: GNU GPL, see COPYING for details.
 """
 
 
+from  MoinMoin.datastruct.backends._tests import DictsBackendTest
 from MoinMoin.datastruct.backends import wiki_dicts
 from MoinMoin._tests import become_trusted, create_page, nuke_page
 
 
-class TestDictDict:
+class TestWikiDicstBackend(DictsBackendTest):
 
     def setup_class(self):
         request = self.request
@@ -37,22 +39,6 @@
         become_trusted(self.request)
         nuke_page(self.request, u'SomeTestDict')
 
-    def test_getitem(self):
-        dicts = self.request.dicts
-
-        some_test_dict = dicts['SomeTestDict']
-        assert len(some_test_dict) == 4
-        assert some_test_dict['First'] == 'first item'
-        assert some_test_dict['text with spaces'] == 'second item'
-        assert some_test_dict['Empty string'] == '' # XXX fails if trailing blank is missing
-        assert some_test_dict['Last'] == 'last item'
-
-    def test_contains(self):
-        dicts = self.request.dicts
-
-        assert  u'SomeTestDict' in dicts
-        assert u'SomeNotExistingDict' not in dicts
-
 
 coverage_modules = ['MoinMoin.datastruct.backends.wiki_dicts']
 
--- a/MoinMoin/datastruct/backends/_tests/test_wiki_groups.py	Fri Jul 03 16:36:47 2009 +0100
+++ b/MoinMoin/datastruct/backends/_tests/test_wiki_groups.py	Sat Jul 04 12:13:46 2009 +0100
@@ -12,7 +12,7 @@
 from py.test import raises
 import re, shutil
 
-from  MoinMoin.datastruct.backends._tests import BackendTest
+from  MoinMoin.datastruct.backends._tests import GroupsBackendTest
 from MoinMoin.datastruct import WikiGroups
 from MoinMoin import Page, security
 from MoinMoin.PageEditor import PageEditor
@@ -81,7 +81,7 @@
         return group
 
 
-class TestWikiGroupBackend(BackendTest):
+class TestWikiGroupBackend(GroupsBackendTest):
 
     class Config(wikiconfig.Config):
 
--- a/MoinMoin/datastruct/backends/composite_groups.py	Fri Jul 03 16:36:47 2009 +0100
+++ b/MoinMoin/datastruct/backends/composite_groups.py	Sat Jul 04 12:13:46 2009 +0100
@@ -6,10 +6,10 @@
 @license: GPL, see COPYING for details
 """
 
-from MoinMoin.datastruct.backends import BaseGroupBackend, GroupDoesNotExistError
+from MoinMoin.datastruct.backends import BaseGroupsBackend, GroupDoesNotExistError
 
 
-class CompositeGroups(BaseGroupBackend):
+class CompositeGroups(BaseGroupsBackend):
     """
     Manage several group backends.
     """
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/datastruct/backends/config_dicts.py	Sat Jul 04 12:13:46 2009 +0100
@@ -0,0 +1,39 @@
+# -*- coding: iso-8859-1 -*-
+"""
+MoinMoin - config dict backend
+
+The config group backend enables you to define dicts in a configuration file.
+
+@copyright: 2009 MoinMoin:DmitrijsMilajevs
+@license: GPL, see COPYING for details
+"""
+
+from MoinMoin.datastruct.backends import BaseDict, BaseDictsBackend, DictDoesNotExistError
+
+
+class ConfigDict(BaseDict):
+    pass
+
+
+class ConfigDicts(BaseDictsBackend):
+
+    def __init__(self, request, dicts):
+        super(ConfigDicts, self).__init__(request)
+
+        self._dicts = dicts
+
+    def __contains__(self, dict_name):
+        return self.page_dict_regex.match(dict_name) and dict_name in self._dicts
+
+    def __iter__(self):
+        return self._dicts.iterkeys()
+
+    def __getitem__(self, dict_name):
+        return ConfigDict(request=self.request, name=dict_name, backend=self)
+
+    def _retrieve_members(self, dict_name):
+        try:
+            return self._dicts[dict_name]
+        except KeyError:
+            raise DictDoesNotExistError(dict_name)
+
--- a/MoinMoin/datastruct/backends/config_groups.py	Fri Jul 03 16:36:47 2009 +0100
+++ b/MoinMoin/datastruct/backends/config_groups.py	Sat Jul 04 12:13:46 2009 +0100
@@ -8,14 +8,14 @@
 @license: GPL, see COPYING for details
 """
 
-from MoinMoin.datastruct.backends import BaseGroup, BaseGroupBackend, GroupDoesNotExistError
+from MoinMoin.datastruct.backends import BaseGroup, BaseGroupsBackend, GroupDoesNotExistError
 
 
 class Group(BaseGroup):
     pass
 
 
-class ConfigGroups(BaseGroupBackend):
+class ConfigGroups(BaseGroupsBackend):
 
     def __init__(self, request, groups):
         """
--- a/MoinMoin/datastruct/backends/wiki_dicts.py	Fri Jul 03 16:36:47 2009 +0100
+++ b/MoinMoin/datastruct/backends/wiki_dicts.py	Sat Jul 04 12:13:46 2009 +0100
@@ -13,7 +13,7 @@
 
 from MoinMoin import caching, wikiutil
 from MoinMoin.Page import Page
-from MoinMoin.datastruct.backends import BaseDict, BaseDictBackend, DictDoesNotExistError
+from MoinMoin.datastruct.backends import BaseDict, BaseDictsBackend, DictDoesNotExistError
 
 
 class WikiDict(BaseDict):
@@ -57,7 +57,7 @@
             raise DictDoesNotExistError(dict_name)
 
 
-class WikiDicts(BaseDictBackend):
+class WikiDicts(BaseDictsBackend):
     """ a dictionary of Dict objects
 
        Config:
--- a/MoinMoin/datastruct/backends/wiki_groups.py	Fri Jul 03 16:36:47 2009 +0100
+++ b/MoinMoin/datastruct/backends/wiki_groups.py	Sat Jul 04 12:13:46 2009 +0100
@@ -17,7 +17,7 @@
 
 from MoinMoin import caching, wikiutil
 from MoinMoin.Page import Page
-from MoinMoin.datastruct.backends import BaseGroup, BaseGroupBackend, GroupDoesNotExistError
+from MoinMoin.datastruct.backends import BaseGroup, BaseGroupsBackend, GroupDoesNotExistError
 
 
 class WikiGroup(BaseGroup):
@@ -49,7 +49,7 @@
             raise GroupDoesNotExistError(group_name)
 
 
-class WikiGroups(BaseGroupBackend):
+class WikiGroups(BaseGroupsBackend):
 
     def __contains__(self, group_name):
         return self.is_group(group_name) and Page(self.request, group_name).exists()