changeset 793:328d83e165a4 pytest2

whooshify _compute_item_sets (used for wanteds/orphans view) remove the tests for it (they can't work any more the way they were designed) added some simple highlevel test that makes sure the wanteds/orphans view code is executed and does not crash.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 28 Aug 2011 20:53:25 +0200
parents 911ccaa08db6
children 2dfaef39854f 2eaf94a45adf
files MoinMoin/apps/frontend/_tests/test_frontend.py MoinMoin/apps/frontend/views.py
diffstat 2 files changed, 27 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/_tests/test_frontend.py	Sun Aug 28 19:46:39 2011 +0200
+++ b/MoinMoin/apps/frontend/_tests/test_frontend.py	Sun Aug 28 20:53:25 2011 +0200
@@ -51,6 +51,22 @@
             assert '<html>' in rv.data
             assert '</html>' in rv.data
 
+    def test_wanteds(self):
+        with self.app.test_client() as c:
+            rv = c.get('/+wanteds')
+            assert rv.status == '200 OK'
+            assert rv.headers['Content-Type'] == 'text/html; charset=utf-8'
+            assert '<html>' in rv.data
+            assert '</html>' in rv.data
+
+    def test_orphans(self):
+        with self.app.test_client() as c:
+            rv = c.get('/+orphans')
+            assert rv.status == '200 OK'
+            assert rv.headers['Content-Type'] == 'text/html; charset=utf-8'
+            assert '<html>' in rv.data
+            assert '</html>' in rv.data
+
 class TestUsersettings(object):
     def setup_method(self, method):
         # Save original user
@@ -157,62 +173,3 @@
         if not self.user.exists():
             self.user = None
             pytest.skip("Can't create test user")
-
-
-class TestViews(object):
-    """
-    Tester class for +backrefs, +orphans and +wanted views
-    """
-    class DummyItem(object):
-        """
-        Fake storage object, simulating the page item object from the storage
-        """
-        def __init__(self, name, revision):
-            self.latest_revision = revision
-            self.name = name
-
-        def get_revision(self, *args, **kw):
-            return self.latest_revision
-
-    class DummyRevision(object):
-        """
-        Fake revision object, used for retrieving ITEMTRANSCLUSIONS and ITEMLINKS meta
-        """
-        def __init__(self, links, transclusions):
-            self.links = links
-            self.transclusions = transclusions
-
-        def get(self, meta_name, *args, **kw):
-            if meta_name == 'itemlinks':
-                return self.links
-            if meta_name == 'itemtransclusions':
-                return self.transclusions
-
-    def setup_class(self):
-        # list of tuples
-        # (page_name, links, transclusions)
-        items = [('page1', ['page2', 'page3'], ['page2']),
-                 ('page2',  ['page1', 'page3'], []),
-                 ('page3', ['page5'], ['page1']),
-                 ('page4', [], ['page5'])
-                ]
-        # we create the list of items
-        self.items = []
-        for item in items:
-            revision = self.DummyRevision(item[1], item[2])
-            page = self.DummyItem(item[0], revision)
-            self.items.append(page)
-
-    def test_item_sets(self):
-        existing, linked, transcluded, norevs = views._compute_item_sets(self.items)
-        assert sorted(existing) == sorted(['page1', 'page2', 'page3', 'page4'])
-        assert sorted(linked) == sorted(['page1', 'page2', 'page3', 'page5'])
-        assert sorted(transcluded) == sorted(['page1', 'page2', 'page5'])
-        assert sorted(norevs) == []
-
-    def test_backrefs(self):
-        expected_backrefs = sorted(['page1', 'page2'])
-        result_backrefs = sorted(views._backrefs(self.items, 'page3'))
-
-        assert result_backrefs == expected_backrefs
-
--- a/MoinMoin/apps/frontend/views.py	Sun Aug 28 19:46:39 2011 +0200
+++ b/MoinMoin/apps/frontend/views.py	Sun Aug 28 20:53:25 2011 +0200
@@ -848,25 +848,19 @@
                            previous_offset=previous_offset,
                           )
 
-def _compute_item_sets(items):
+def _compute_item_sets():
     """
     compute sets of existing, linked, transcluded and no-revision item names
     """
     linked = set()
     transcluded = set()
     existing = set()
-    norev = set()
-    for item in items:
-        name = item.name
-        existing.add(name)
-        try:
-            current_rev = item.get_revision(-1)
-        except NoSuchRevisionError:
-            norev.add(name)
-        else:
-            linked.update(current_rev.get(ITEMLINKS, []))
-            transcluded.update(current_rev.get(ITEMTRANSCLUSIONS, []))
-    return existing, linked, transcluded, norev
+    docs = flaskg.storage.documents(all_revs=False, wikiname=app.cfg.interwikiname)
+    for doc in docs:
+        existing.add(doc[NAME])
+        linked.update(doc.get(ITEMLINKS, []))
+        transcluded.update(doc.get(ITEMTRANSCLUSIONS, []))
+    return existing, linked, transcluded
 
 
 @frontend.route('/+wanteds')
@@ -876,10 +870,9 @@
     transcluded by other items. If you want to know by which items they are
     referred to, use the backrefs functionality of the item in question.
     """
-    existing, linked, transcluded, norevs = _compute_item_sets(flaskg.storage.iteritems())
-    valid = existing - norevs
+    existing, linked, transcluded = _compute_item_sets()
     referred = linked | transcluded
-    wanteds = referred - valid
+    wanteds = referred - existing
     item_name = request.values.get('item_name', '') # actions menu puts it into qs
     return render_template('item_link_list.html',
                            headline=_(u'Wanted Items'),
@@ -893,10 +886,9 @@
     Return a list view of existing items not being linked or transcluded
     by any other item (which makes them sometimes not discoverable).
     """
-    existing, linked, transcluded, norevs = _compute_item_sets(flaskg.storage.iteritems())
-    valid = existing - norevs
+    existing, linked, transcluded = _compute_item_sets()
     referred = linked | transcluded
-    orphans = valid - referred
+    orphans = existing - referred
     item_name = request.values.get('item_name', '') # actions menu puts it into qs
     return render_template('item_link_list.html',
                            item_name=item_name,