Commits

Anonymous committed 8c86c36

Add high-level view tests for all views.

Comments (0)

Files changed (5)

MoinMoin/apps/admin/_tests/test_admin.py

+# Copyright: 2011 Sam Toyer
+# License: GNU GPL v2 (or any later version), see LICENSE.txt for details
+
+"""
+    MoinMoin - admin view tests
+"""
+
+from flask import url_for
+
+def pytest_generate_tests(metafunc):
+    if 'view' in metafunc.funcargs:
+        parameters = metafunc.cls.params[metafunc.func.__name__]
+        argnames = parameters[0].keys()
+        metafunc.parametrize(argnames, [[parameters[argument] for argument in argnames] for parameter in parameters])
+
+class TestAdmin(object):
+    superuser_views = ['admin.' + action for action in ['require_permission', 'sysitems_upgrade',
+            'wikiconfig', 'wikiconfighelp',
+            ]
+        ]
+    params = {
+        'test_superuser_page': [dict(view=view) for view in superuser_views]
+        }
+
+    def _test_view_get(self, viewname, status='200 OK', data=['<html>', '</html>'], viewopts={}):
+        with self.app.test_client() as c:
+            rv = c.get(url_for(viewname, **viewopts))
+            assert rv.status == status
+            assert rv.headers['Content-Type'] == 'text/html; charset=utf-8'
+            for item in data: assert item in rv.data
+
+    def test_index(self):
+        self._test_view_get('admin.index')
+
+    def test_userprofile(self):
+        self._test_view_get('admin.userprofile', status='403 FORBIDDEN', viewopts=dict(user_name='DoesntExist'))
+
+    def test_superuser_page(self, view):
+        # This will die for the reasons outlined in apps/frontend/_tests/test_frontend.py
+        self._test_view_get(view, status='403 FORBIDDEN')
+
+    def test_interwikihelp(self):
+        self._test_view_get('admin.interwikihelp')
+
+    def test_highlighterhelp(self):
+        self._test_view_get('admin.highlighterhelp')
+
+    def test_itemsize(self):
+        self._test_view_get('admin.itemsize')
+

MoinMoin/apps/feed/_tests/test_feed.py

 MoinMoin - basic tests for feeds
 """
 
+from flask import url_for
+
 from MoinMoin._tests import wikiconfig
 
 from MoinMoin.items import Item
 
     def test_global_atom(self):
         with self.app.test_client() as c:
-            rv = c.get('/+feed/atom')
+            rv = c.get(url_for('feed.atom'))
             assert rv.status == '200 OK'
             assert rv.headers['Content-Type'] == 'application/atom+xml'
             assert rv.data.startswith('<?xml')
         basename = u'Foo'
         item = update_item(basename, {COMMENT: u"foo data for feed item"}, '')
         with self.app.test_client() as c:
-            rv = c.get('/+feed/atom')
+            rv = c.get(url_for('feed.atom'))
             assert rv.status == '200 OK'
             assert rv.headers['Content-Type'] == 'application/atom+xml'
             assert rv.data.startswith('<?xml')
         # tests the cache invalidation
         update_item(basename, {COMMENT: u"checking if the cache invalidation works"}, '')
         with self.app.test_client() as c:
-            rv = c.get('/+feed/atom')
+            rv = c.get(url_for('feed.atom'))
             assert rv.status == '200 OK'
             assert rv.headers['Content-Type'] == 'application/atom+xml'
             assert rv.data.startswith('<?xml')

MoinMoin/apps/frontend/_tests/test_frontend.py

     MoinMoin - basic tests for frontend
 """
 
+from flask import url_for
 from flask import g as flaskg
 from werkzeug import ImmutableMultiDict
 
 from MoinMoin._tests import wikiconfig
 import pytest
 
+def pytest_generate_tests(metafunc):
+    if 'action' in metafunc.funcargnames:
+        parameters = metafunc.cls.params[metafunc.func.__name__]
+        arguments = parameters[0].keys()
+        metafunc.parametrize(arguments, [[parameter[argname] for argname in arguments] for parameter in parameters])
+
 class TestFrontend(object):
+    item_actions = ['frontend.' + action for action in
+            ['show_item', 'show_dom', 'indexable', 'highlight_item', 'show_item_meta',
+                'content_item', 'get_item', 'download_item', 'convert_item', 'modify_item',
+                'rename_item', 'delete_item', 'index', 'backrefs', 'history', 'diff',
+                'similar_names', 'sitemap', 'tagged_items'
+            ]
+        ]
+    params = {
+            'test_item_actions': [dict(action=actionname) for actionname in item_actions],
+        }
+
+    def _test_view(self, viewname, status='200 OK', data=['<html>', '</html>'], content_types=['text/html; charset=utf-8'], viewopts={}, method='GET'):
+        with self.app.test_client() as c:
+            if method == 'POST':
+                rv = c.post(url_for(viewname, **viewopts))
+            else:
+                rv = c.get(url_for(viewname, **viewopts))
+            assert rv.status == status
+            for item in data:
+                assert item in rv.data
+            assert rv.headers['Content-Type'] in content_types
+            return rv
+
+    def test_item_actions(self, action):
+        # TODO: fix conftest.py so this passes
+        # Problem in MoinMoin/conftest.py, line 112 -
+        # pytest_pycollect_makeitem magic means that pytest_generate_tests is
+        # not called on this method
+        # also affects other local pytest hooks (decorators like @pytest.mark.skip)
+        self._test_view(action, status='404 NOT FOUND', viewopts=dict(item_name='DoesntExist'))
+
     def test_root(self):
-        with self.app.test_client() as c:
-            rv = c.get('/') # / redirects to front page
-            assert rv.status == '302 FOUND'
+        self._test_view('frontend.index')
 
     def test_robots(self):
-        with self.app.test_client() as c:
-            rv = c.get('/robots.txt')
-            assert rv.status == '200 OK'
-            assert rv.headers['Content-Type'] == 'text/plain; charset=utf-8'
-            assert 'Disallow:' in rv.data
+        self._test_view('frontend.robots', data=['Disallow:'], content_types=['text/plain; charset=utf-8'])
+
+    def test_search(self):
+        self._test_view('frontend.search')
+
+    def test_revert_item(self):
+        self._test_view('frontend.revert_item', status='404 NOT FOUND', viewopts=dict(item_name='DoesntExist', rev='000000'))
+
+    def test_ajaxdelete(self):
+        self._test_view('frontend.ajaxdelete', content_types=[], viewopts=dict(item_name='DoesntExist'), data=['{', '}'], method='POST')
+
+    def test_ajaxdestroy(self):
+        self._test_view('frontend.ajaxdestroy', content_types=[], viewopts=dict(item_name='DoesntExist'), data=['{', '}'], method='POST')
+
+    def test_ajaxmodify(self):
+        self._test_view('frontend.ajaxmodify', status='404 NOT FOUND', viewopts=dict(item_name='DoesntExist'), method='POST')
+
+    def test_jfu_server(self):
+        self._test_view('frontend.jfu_server', data=['{', '}'], viewopts=dict(item_name='DoesntExist'), method='POST')
+
+    def test_mychanges(self):
+        self._test_view('frontend.mychanges', viewopts=dict(userid='000000'))
+
+    def test_global_history(self):
+        self._test_view('frontend.global_history')
+
+    def test_wanted_items(self):
+        self._test_view('frontend.wanted_items')
+
+    def test_orphaned_items(self):
+        self._test_view('frontend.orphaned_items')
+
+    def test_quicklink_item(self):
+        self._test_view('frontend.quicklink_item', status='302 FOUND', viewopts=dict(item_name='DoesntExist'), data=['<!DOCTYPE HTML'])
+
+    def test_subscribe_item(self):
+        self._test_view('frontend.subscribe_item', status='302 FOUND', viewopts=dict(item_name='DoesntExist'), data=['<!DOCTYPE HTML'])
+
+    def test_register(self):
+        self._test_view('frontend.register')
+
+    def test_verifyemail(self):
+        self._test_view('frontend.verifyemail', status='302 FOUND', data=['<!DOCTYPE HTML'])
+
+    def test_lostpass(self):
+        self._test_view('frontend.lostpass')
+
+    def test_recoverpass(self):
+        self._test_view('frontend.recoverpass')
+
+    def test_login(self):
+        self._test_view('frontend.login')
+
+    def test_logout(self):
+        self._test_view('frontend.logout', status='302 FOUND', data=['<!DOCTYPE HTML'])
+
+    def test_usersettings(self):
+        self._test_view('frontend.usersettings')
+
+    def test_bookmark(self):
+        self._test_view('frontend.bookmark', status='302 FOUND', data=['<!DOCTYPE HTML'])
+
+    def test_diffraw(self):
+        self._test_view('frontend.diffraw', data=[], viewopts=dict(item_name='DoesntExist'))
 
     def test_favicon(self):
-        with self.app.test_client() as c:
-            rv = c.get('/favicon.ico')
-            assert rv.status == '200 OK'
-            assert rv.headers['Content-Type'] in ['image/x-icon', 'image/vnd.microsoft.icon']
-            assert rv.data.startswith('\x00\x00') # "reserved word, should always be 0"
+        rv = self._test_view('frontend.favicon', content_types=['image/x-icon', 'image/vnd.microsoft.icon'], data=[])
+        assert rv.data.startswith('\x00\x00') # "reserved word, should always be 0"
 
-    def test_404(self):
-        with self.app.test_client() as c:
-            rv = c.get('/DoesntExist')
-            assert rv.status == '404 NOT FOUND'
-            assert rv.headers['Content-Type'] == 'text/html; charset=utf-8'
-            assert '<html>' in rv.data
-            assert '</html>' in rv.data
-
-    def test_global_index(self):
-        with self.app.test_client() as c:
-            rv = c.get('/+index/')
-            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_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
+    def test_global_tags(self):
+        self._test_view('frontend.global_tags')
 
 class TestUsersettings(object):
     def setup_method(self, method):

MoinMoin/apps/misc/_tests/test_misc.py

 MoinMoin - basic tests for misc views
 """
 
+from flask import url_for
+
 from MoinMoin._tests import wikiconfig
 
 
 
     def test_global_sitemap(self):
         with self.app.test_client() as c:
-            rv = c.get('/+misc/sitemap')
+            rv = c.get(url_for('misc.sitemap'))
             assert rv.status == '200 OK'
             assert rv.headers['Content-Type'] == 'text/xml; charset=utf-8'
             assert rv.data.startswith('<?xml')
 
     def test_urls_names(self):
         with self.app.test_client() as c:
-            rv = c.get('/+misc/urls_names')
+            rv = c.get(url_for('misc.urls_names'))
             assert rv.status == '200 OK'
             assert rv.headers['Content-Type'] == 'text/plain; charset=utf-8'

MoinMoin/apps/serve/_tests/test_serve.py

+# Copyright: 2011 Sam Toyer
+# License: GNU GPL V2 (or any later version), see LICENSE.txt for details
+
+"""
+    MoinMoin - tests for "serve" app
+"""
+
+from flask import url_for
+
+class TestServe(object):
+    def test_index(self):
+        with self.app.test_client() as c:
+            rv = c.get(url_for('serve.index'))
+            assert rv.status == '200 OK'
+            assert rv.headers['Content-Type'] == 'text/plain'
+
+    def test_files(self):
+        with self.app.test_client() as c:
+            rv = c.get(url_for('serve.files', name="DoesntExist"))
+            assert rv.status == '404 NOT FOUND'
+            assert rv.headers['Content-Type'] == 'text/html'
+            assert '<!DOCTYPE HTML' in rv.data
+