changeset 4217:b231877df090

Added werkzeug.test.Client for blackbox application testing (headers, status, output)
author Florian Krupicka <florian.krupicka@googlemail.com>
date Mon, 14 Jul 2008 13:16:57 +0200
parents 84cdf829d881
children 10fe93273b09
files MoinMoin/_tests/test_wsgiapp.py MoinMoin/conftest.py
diffstat 2 files changed, 44 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/_tests/test_wsgiapp.py	Mon Jul 14 13:16:57 2008 +0200
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+"""
+    MoinMoin - MoinMoin.wsgiapp Tests
+
+    @copyright: 2008 MoinMoin:FlorianKrupicka
+    @license: GNU GPL, see COPYING for details.
+"""
+from StringIO import StringIO
+
+from MoinMoin import wsgiapp
+
+DOC_TYPE = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
+
+class TestApplication:
+
+    # These should exist
+    PAGES = ('FrontPage', 'RecentChanges', 'HelpContents', 'FindPage')
+    # ... and these should not
+    NO_PAGES = ('FooBar', 'TheNone/ExistantPage/', '%33Strange%74Codes')
+
+    def testWSGIAppExisting(self):
+        for page in self.PAGES:
+            def _test_():
+                appiter, status, headers = self.client.get('/%s' % page)
+                assert status[:3] == '200'
+                assert ('Content-Type', 'text/html; charset=utf-8') in headers
+                output = ''.join(appiter)
+                for needle in (DOC_TYPE, page):
+                    assert needle in output
+            yield _test_
+
+    def testWSGIAppAbsent(self):
+        for page in self.NO_PAGES:
+            def _test_():
+                appiter, status, headers = self.client.get('/%s' % page)
+                assert status[:3] == '404'
+                output = ''.join(appiter)
+                for needle in ('new empty page', 'page template'):
+                    assert needle in output
+            yield _test_
--- a/MoinMoin/conftest.py	Mon Jul 14 11:05:19 2008 +0200
+++ b/MoinMoin/conftest.py	Mon Jul 14 13:16:57 2008 +0200
@@ -25,6 +25,7 @@
 
 import py
 
+from werkzeug.test import Client
 
 rootdir = py.magic.autopath().dirpath()
 moindir = rootdir.join("..")
@@ -37,7 +38,7 @@
 
 from MoinMoin.support.python_compatibility import set
 from MoinMoin.web.request import TestRequest
-from MoinMoin.wsgiapp import init as request_init
+from MoinMoin.wsgiapp import application, init
 
 coverage_modules = set()
 
@@ -63,7 +64,6 @@
         coverage.erase()
         coverage.start()
 
-
     py.test.config.addoptions('MoinMoin options', py.test.config.Option('-C',
         '--coverage', action='callback', callback=callback,
         help='Output information about code coverage (slow!)'))
@@ -77,7 +77,7 @@
         maketestwiki.run(True)
         static_state[0] = True
     request = TestRequest()
-    request = request_init(request)
+    request = init(request)
     return request
 
 class TestConfig:
@@ -177,6 +177,7 @@
         cls = self.obj
         cls.request = self.parent.request
         cls.TestConfig = TestConfig(cls.request)
+        cls.client = Client(application)
         super(MoinClassCollector, self).setup()