changeset 2276:b7a77b1c2510

Fixes for failing tests.
author Ashutosh Singla <ashu1461@gmail.com>
date Sun, 15 Sep 2013 08:38:41 +0530
parents ae0755153258
children 77e6a0d7ce2a
files MoinMoin/_tests/test_forms.py MoinMoin/forms.py MoinMoin/items/__init__.py MoinMoin/items/_tests/test_Item.py MoinMoin/items/blog.py MoinMoin/storage/middleware/indexing.py
diffstat 6 files changed, 25 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_forms.py	Sat Sep 14 04:43:04 2013 +0530
+++ b/MoinMoin/_tests/test_forms.py	Sun Sep 15 08:38:41 2013 +0530
@@ -12,7 +12,7 @@
 from flask import current_app as app
 from flask import g as flaskg
 
-from MoinMoin.forms import DateTimeUNIX, JSON
+from MoinMoin.forms import DateTimeUNIX, JSON, Names
 from MoinMoin.util.interwiki import CompositeName
 from MoinMoin.items import Item
 from MoinMoin._tests import become_trusted
@@ -71,6 +71,9 @@
              ([u'existingname'], 'ns1/ns2', '', 'existingname', False),
              ]
     for name, namespace, field, value, result in tests:
-        x = JSON(json.dumps({NAME: name, NAMESPACE: namespace}))
-        state = {FQNAME: CompositeName(namespace, field, value), ITEMID: None}
-        assert x.validate(state) == result
+        meta = {NAME:name, NAMESPACE: namespace}
+        x = JSON(json.dumps(meta))
+        y = Names(name)
+        state = dict(fqname=CompositeName(namespace, field, value), itemid=None, meta=meta)
+        value = x.validate(state) and y.validate(state)
+        assert value == result
--- a/MoinMoin/forms.py	Sat Sep 14 04:43:04 2013 +0530
+++ b/MoinMoin/forms.py	Sun Sep 15 08:38:41 2013 +0530
@@ -120,8 +120,11 @@
     def validate(self, element, state):
         # Make sure that the other meta is valid before validating the name.
         # TODO Change/Make sure that the below statement holds good.
-        if not element.parent.parent['extra_meta_text'].valid:
-            return False
+        try:
+            if not element.parent.parent['extra_meta_text'].valid:
+                return False
+        except AttributeError:
+            pass
         try:
             validate_name(state['meta'], state[ITEMID])
         except NameNotValidError as e:
--- a/MoinMoin/items/__init__.py	Sat Sep 14 04:43:04 2013 +0530
+++ b/MoinMoin/items/__init__.py	Sun Sep 15 08:38:41 2013 +0530
@@ -686,7 +686,7 @@
         isglobalindex = not fqname.value or fqname.value == NAMESPACE_ALL
         query = Term(WIKINAME, app.cfg.interwikiname) & self.build_index_query(startswith, selected_groups, isglobalindex)
         if not fqname.value.startswith(NAMESPACE_ALL+'/') and fqname.value != NAMESPACE_ALL:
-            query = Term(NAMESPACE, fqname.namespace)
+            query = Term(NAMESPACE, fqname.namespace) & query
         revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None)
         return self.make_flat_index(revs, isglobalindex)
 
--- a/MoinMoin/items/_tests/test_Item.py	Sat Sep 14 04:43:04 2013 +0530
+++ b/MoinMoin/items/_tests/test_Item.py	Sun Sep 15 08:38:41 2013 +0530
@@ -12,7 +12,9 @@
 
 from MoinMoin._tests import become_trusted, update_item
 from MoinMoin.items import Item, NonExistent, IndexEntry, MixedIndexEntry
-from MoinMoin.constants.keys import ITEMTYPE, CONTENTTYPE, NAME, NAME_OLD, COMMENT, ACTION, ADDRESS, TRASH, ITEMID
+from MoinMoin.util.interwiki import CompositeName
+from MoinMoin.constants.keys import ITEMTYPE, CONTENTTYPE, NAME, NAME_OLD, COMMENT, ACTION, ADDRESS, TRASH, ITEMID, NAME_EXACT
+from MoinMoin.constants.namespaces import NAMESPACE_DEFAULT
 from MoinMoin.constants.contenttypes import CONTENTTYPE_NONEXISTENT
 from MoinMoin.constants.itemtypes import ITEMTYPE_NONEXISTENT
 
@@ -21,7 +23,7 @@
     """
     Build a list of IndexEntry by hand, useful as a test helper.
     """
-    return [(IndexEntry(relname, '/'.join((basename, relname)), Item.create('/'.join((basename, relname))).meta))
+    return [(IndexEntry(relname, CompositeName(NAMESPACE_DEFAULT, NAME_EXACT, '/'.join((basename, relname))), Item.create('/'.join((basename, relname))).meta))
             for relname in relnames]
 
 
@@ -31,7 +33,7 @@
 
     :spec is a list of (relname, hassubitem) tuples.
     """
-    return [(MixedIndexEntry(relname, '/'.join((basename, relname)), Item.create('/'.join((basename, relname))).meta, hassubitem))
+    return [(MixedIndexEntry(relname, CompositeName(NAMESPACE_DEFAULT, NAME_EXACT, '/'.join((basename, relname))), Item.create('/'.join((basename, relname))).meta, hassubitem))
             for relname, hassubitem in spec]
 
 
@@ -132,7 +134,7 @@
         item = Item.create(name)
         result = Item.meta_filter(item, meta)
         # keys like NAME, ITEMID, REVID, DATAID are filtered
-        expected = {'test_key': 'test_val', CONTENTTYPE: contenttype, NAME: [u'test_name']}
+        expected = {'test_key': 'test_val', CONTENTTYPE: contenttype}
         assert result == expected
 
     def test_meta_dict_to_text(self):
@@ -141,7 +143,7 @@
         meta = {'test_key': 'test_val', CONTENTTYPE: contenttype, NAME: [u'test_name']}
         item = Item.create(name)
         result = Item.meta_dict_to_text(item, meta)
-        expected = '{\n  "contenttype": "text/plain;charset=utf-8", \n  "name": [\n    "test_name"\n  ], \n  "test_key": "test_val"\n}'
+        expected = '{\n  "contenttype": "text/plain;charset=utf-8", \n  "test_key": "test_val"\n}'
         assert result == expected
 
     def test_meta_text_to_dict(self):
@@ -150,7 +152,7 @@
         text = '{\n  "contenttype": "text/plain;charset=utf-8", \n  "test_key": "test_val", \n "name": ["test_name"] \n}'
         item = Item.create(name)
         result = Item.meta_text_to_dict(item, text)
-        expected = {'test_key': 'test_val', CONTENTTYPE: contenttype, NAME: [u"test_name"]}
+        expected = {'test_key': 'test_val', CONTENTTYPE: contenttype}
         assert result == expected
 
     def test_item_can_have_several_names(self):
--- a/MoinMoin/items/blog.py	Sat Sep 14 04:43:04 2013 +0530
+++ b/MoinMoin/items/blog.py	Sun Sep 15 08:38:41 2013 +0530
@@ -22,6 +22,7 @@
 from MoinMoin.storage.middleware.protecting import AccessDenied
 from MoinMoin.constants.keys import NAME_EXACT, WIKINAME, ITEMTYPE, MTIME, PTIME, TAGS
 from MoinMoin.items import Item, Default, register, BaseMetaForm
+from MoinMoin.util.interwiki import split_fqname
 
 
 ITEMTYPE_BLOG = u'blog'
@@ -86,6 +87,7 @@
         blog_entry_items = [Item.create(rev.name, rev_id=rev.revid) for rev in revs]
         return render_template('blog/main.html',
                                item_name=self.name,
+                               fqname=split_fqname(self.name),
                                blog_item=self,
                                blog_entry_items=blog_entry_items,
                                tag=tag,
@@ -122,6 +124,7 @@
             abort(403)
         return render_template('blog/entry.html',
                                item_name=self.name,
+                               fqname=blog_item.fqname,
                                blog_item=blog_item,
                                blog_entry_item=self,
                               )
--- a/MoinMoin/storage/middleware/indexing.py	Sat Sep 14 04:43:04 2013 +0530
+++ b/MoinMoin/storage/middleware/indexing.py	Sun Sep 15 08:38:41 2013 +0530
@@ -833,7 +833,7 @@
 
     @property
     def namespace(self):
-        return self.meta[NAMESPACE]
+        return self.meta.get(NAMESPACE, u'')
 
     def _fqname(self, name=None):
         """